OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Helper script that mounts chromium os image from a device or directory | 7 # Helper script that mounts chromium os image from a device or directory |
8 # and creates mount points for /var and /usr/local (if in dev_mode). | 8 # and creates mount points for /var and /usr/local (if in dev_mode). |
9 | 9 |
10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 # Die on error | 35 # Die on error |
36 set -e | 36 set -e |
37 | 37 |
38 # Common unmounts for either a device or directory | 38 # Common unmounts for either a device or directory |
39 function unmount_image() { | 39 function unmount_image() { |
40 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ | 40 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ |
41 "and ${FLAGS_rootfs_mountpt}" | 41 "and ${FLAGS_rootfs_mountpt}" |
42 # Don't die on error to force cleanup | 42 # Don't die on error to force cleanup |
43 set +e | 43 set +e |
44 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then | 44 # Reset symlinks in /usr/local. |
45 # Reset symlinks in /usr/local. | 45 setup_symlinks_on_root "/usr/local" "/var" \ |
46 setup_symlinks_on_root "/usr/local" "/var" \ | 46 "${FLAGS_stateful_mountpt}" |
47 "${FLAGS_stateful_mountpt}" | 47 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" |
48 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" | |
49 fi | |
50 sudo umount "${FLAGS_rootfs_mountpt}/var" | 48 sudo umount "${FLAGS_rootfs_mountpt}/var" |
51 sudo umount -d "${FLAGS_stateful_mountpt}" | 49 sudo umount -d "${FLAGS_stateful_mountpt}" |
52 sudo umount -d "${FLAGS_rootfs_mountpt}" | 50 sudo umount -d "${FLAGS_rootfs_mountpt}" |
53 set -e | 51 set -e |
54 } | 52 } |
55 | 53 |
56 function get_usb_partitions() { | 54 function get_usb_partitions() { |
57 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" | 55 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" |
58 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" | 56 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" |
59 } | 57 } |
(...skipping 17 matching lines...) Expand all Loading... |
77 mkdir -p "${FLAGS_rootfs_mountpt}" | 75 mkdir -p "${FLAGS_rootfs_mountpt}" |
78 mkdir -p "${FLAGS_stateful_mountpt}" | 76 mkdir -p "${FLAGS_stateful_mountpt}" |
79 | 77 |
80 # Get the partitions for the image / device. | 78 # Get the partitions for the image / device. |
81 if [ -b ${FLAGS_from} ] ; then | 79 if [ -b ${FLAGS_from} ] ; then |
82 get_usb_partitions | 80 get_usb_partitions |
83 else | 81 else |
84 get_gpt_partitions | 82 get_gpt_partitions |
85 fi | 83 fi |
86 | 84 |
87 # Mount var unconditionally and then setup /usr/local for user of dev mode. | 85 # Mount directories and setup symlinks. |
88 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ | 86 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ |
89 "${FLAGS_rootfs_mountpt}/var" | 87 "${FLAGS_rootfs_mountpt}/var" |
90 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then | 88 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ |
91 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ | 89 "${FLAGS_rootfs_mountpt}/usr/local" |
92 "${FLAGS_rootfs_mountpt}/usr/local" | 90 # Setup symlinks in /usr/local so you can emerge packages into /usr/local. |
93 # Setup symlinks in /usr/local so you can emerge packages into /usr/local. | 91 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ |
94 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ | 92 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" |
95 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" | |
96 fi | |
97 echo "Image specified by ${FLAGS_from} mounted at"\ | 93 echo "Image specified by ${FLAGS_from} mounted at"\ |
98 "${FLAGS_rootfs_mountpt} successfully." | 94 "${FLAGS_rootfs_mountpt} successfully." |
99 } | 95 } |
100 | 96 |
101 # Find the last image built on the board. | 97 # Find the last image built on the board. |
102 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then | 98 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then |
103 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 99 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
104 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" | 100 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" |
105 fi | 101 fi |
106 | 102 |
107 # Turn path into an absolute path. | 103 # Turn path into an absolute path. |
108 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 104 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
109 | 105 |
110 # Perform desired operation. | 106 # Perform desired operation. |
111 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then | 107 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then |
112 unmount_image | 108 unmount_image |
113 else | 109 else |
114 mount_image | 110 mount_image |
115 fi | 111 fi |
OLD | NEW |