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 # Script to create a Chrome OS dev recovery image using a dev install shim | 7 # Script to create a Chrome OS dev recovery image using a dev install shim |
8 | 8 |
9 # Source constants and utility functions | 9 # Source constants and utility functions |
10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 else | 68 else |
69 info "Using a recent dev install shim at ${FLAGS_dev_install_shim}" | 69 info "Using a recent dev install shim at ${FLAGS_dev_install_shim}" |
70 fi | 70 fi |
71 | 71 |
72 # Constants | 72 # Constants |
73 INSTALL_SHIM_DIR="$(dirname "$FLAGS_dev_install_shim")" | 73 INSTALL_SHIM_DIR="$(dirname "$FLAGS_dev_install_shim")" |
74 DEV_RECOVERY_IMAGE="dev_recovery_image.bin" | 74 DEV_RECOVERY_IMAGE="dev_recovery_image.bin" |
75 | 75 |
76 umount_from_loop_dev() { | 76 umount_from_loop_dev() { |
77 local mnt_pt=$1 | 77 local mnt_pt=$1 |
78 mount | grep -q " on ${mnt_pt}" && sudo umount ${mnt_pt} | 78 mount | grep -q " on ${mnt_pt}" && sudo umount ${mnt_pt} |
Will Drewry
2010/09/29 22:19:03
does this need to be umount -d, or is it implicit?
Tan Gao
2010/09/30 16:55:50
it's implicit. Quoting the man page
"The umount c
| |
79 rmdir ${mnt_pt} | 79 rmdir ${mnt_pt} |
80 } | 80 } |
81 | 81 |
82 cleanup_loop_dev() { | 82 cleanup_loop_dev() { |
83 sudo losetup -d ${1} || /bin/true | 83 sudo losetup -d ${1} || /bin/true |
84 } | 84 } |
85 | 85 |
86 get_loop_dev() { | 86 get_loop_dev() { |
87 local loop_dev=$(sudo losetup -f) | 87 local loop_dev=$(sudo losetup -f) |
88 if [ -z "${loop_dev}" ]; then | 88 if [ -z "${loop_dev}" ]; then |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 local stateful_offset=$(partoffset ${FLAGS_dev_install_shim} 1) | 169 local stateful_offset=$(partoffset ${FLAGS_dev_install_shim} 1) |
170 local stateful_count=$(partsize ${FLAGS_dev_install_shim} 1) | 170 local stateful_count=$(partsize ${FLAGS_dev_install_shim} 1) |
171 dd if="${FLAGS_dev_install_shim}" of="${temp_state}" conv=notrunc bs=512 \ | 171 dd if="${FLAGS_dev_install_shim}" of="${temp_state}" conv=notrunc bs=512 \ |
172 skip=${stateful_offset} count=${stateful_count} &>/dev/null | 172 skip=${stateful_offset} count=${stateful_count} &>/dev/null |
173 | 173 |
174 local resized_sectors=$(resize_partition $temp_state $PAYLOAD_DIR_SIZE) | 174 local resized_sectors=$(resize_partition $temp_state $PAYLOAD_DIR_SIZE) |
175 | 175 |
176 # Mount resized stateful FS and copy payload content to its root directory | 176 # Mount resized stateful FS and copy payload content to its root directory |
177 local temp_mnt=$(mktemp -d "/tmp/temp_mnt.XXXXXX") | 177 local temp_mnt=$(mktemp -d "/tmp/temp_mnt.XXXXXX") |
178 local loop_dev=$(get_loop_dev) | 178 local loop_dev=$(get_loop_dev) |
179 trap "umount_from_loop_dev ${temp_mnt} && cleanup_loop_dev ${loop_dev}" EXIT | 179 trap "umount_from_loop_dev ${temp_mnt} && rm -f \"${temp_state}\"" EXIT |
180 mkdir -p "${temp_mnt}" | 180 mkdir -p "${temp_mnt}" |
181 sudo mount -o loop=${loop_dev} "${temp_state}" "${temp_mnt}" | 181 sudo mount -o loop=${loop_dev} "${temp_state}" "${temp_mnt}" |
182 sudo cp -R "${FLAGS_payload_dir}" "${temp_mnt}" | 182 sudo cp -R "${FLAGS_payload_dir}" "${temp_mnt}" |
183 sudo mv "${temp_mnt}/$(basename ${FLAGS_payload_dir})" \ | 183 sudo mv "${temp_mnt}/$(basename ${FLAGS_payload_dir})" \ |
184 "${temp_mnt}/dev_payload" | 184 "${temp_mnt}/dev_payload" |
185 # Mark image as dev recovery | 185 # Mark image as dev recovery |
186 sudo touch "${temp_mnt}/.recovery" | 186 sudo touch "${temp_mnt}/.recovery" |
187 sudo touch "${temp_mnt}/.dev_recovery" | 187 sudo touch "${temp_mnt}/.dev_recovery" |
188 | 188 |
189 # TODO(tgao): handle install script (for default and custom cases) | 189 # TODO(tgao): handle install script (for default and custom cases) |
190 local temp_img=$(update_partition_table $temp_state $resized_sectors) | 190 local temp_img=$(update_partition_table $temp_state $resized_sectors) |
191 | 191 |
192 rm -f "${temp_state}" | |
193 # trap handler will clean up loop device and temp mount point | 192 # trap handler will clean up loop device and temp mount point |
194 echo ${temp_img} | 193 echo ${temp_img} |
195 } | 194 } |
196 | 195 |
197 # Main | 196 # Main |
198 DST_PATH="${INSTALL_SHIM_DIR}/${DEV_RECOVERY_IMAGE}" | 197 DST_PATH="${INSTALL_SHIM_DIR}/${DEV_RECOVERY_IMAGE}" |
199 info "Attempting to create dev recovery image using dev install shim \ | 198 info "Attempting to create dev recovery image using dev install shim \ |
200 ${FLAGS_dev_install_shim}" | 199 ${FLAGS_dev_install_shim}" |
201 TEMP_IMG=$(create_dev_recovery_image) | 200 TEMP_IMG=$(create_dev_recovery_image) |
202 | 201 |
203 mv -f $TEMP_IMG $DST_PATH | 202 mv -f $TEMP_IMG $DST_PATH |
204 info "Dev recovery image created at ${DST_PATH}" | 203 info "Dev recovery image created at ${DST_PATH}" |
OLD | NEW |