Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: mod_image_for_recovery.sh

Issue 3007005: issue 2825046 (Closed) Base URL: http://src.chromium.org/git/crosutils.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 modify a pristine/dev Chrome OS image to be used for recovery 7 # Script to modify a pristine/dev Chrome OS image to be used for recovery
8 8
9 . "$(dirname "$0")/common.sh" 9 . "$(dirname "$0")/common.sh"
10 10
11 # Load functions and constants for chromeos-install
12 . "$(dirname "$0")/chromeos-common.sh"
13
11 # Script must be run inside the chroot. 14 # Script must be run inside the chroot.
12 restart_in_chroot_if_needed $* 15 restart_in_chroot_if_needed $*
13 16
14 DEFINE_string image_dir "" \ 17 get_default_board
15 "Directory to pristine/base image." 18
16 DEFINE_string image_name "chromiumos_image.bin" \ 19 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built"
17 "Name of Chrome OS image to modify." 20 DEFINE_string image "" "Location of the rootfs raw image file"
18 21
19 # Parse command line 22 # Parse command line
20 FLAGS "$@" || exit 1 23 FLAGS "$@" || exit 1
21 eval set -- "${FLAGS_ARGV}" 24 eval set -- "${FLAGS_ARGV}"
22 25
23 set -e 26 # No board, no default and no image set then we can't find the image
27 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then
28 setup_board_warning
29 die "mod_image_for_recovery failed. No board set and no image set"
30 fi
24 31
25 if [ -z $FLAGS_image_dir ] || [ ! -d $FLAGS_image_dir ]; then 32 # We have a board name but no image set. Use image at default location
26 echo "Error: invalid flag --image_dir" 33 if [ -z $FLAGS_image ] ; then
34 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
35 FILENAME="chromiumos_image.bin"
36 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}"
37 fi
38
39 # Turn path into an absolute path.
40 FLAGS_image=$(eval readlink -f ${FLAGS_image})
41
42 # Abort early if we can't find the image
43 if [ ! -f $FLAGS_image ] ; then
44 echo "No image found at $FLAGS_image"
27 exit 1 45 exit 1
28 fi 46 fi
29 47
30 SRC_PATH="${FLAGS_image_dir}/${FLAGS_image_name}" 48 set -e
31 if [ -z $FLAGS_image_name ] || [ ! -f $SRC_PATH ]; then
32 echo "Error: invalid flag --image_name"
33 exit 1
34 fi
35 49
36 # Constants 50 # Constants
37 OUTPUT_DIR=$FLAGS_image_dir 51 IMAGE_DIR="$(dirname "$FLAGS_image")"
38 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" 52 IMAGE_NAME="$(basename "$FLAGS_image")"
39 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" 53 ROOT_FS_DIR="$IMAGE_DIR/rootfs"
54 STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
40 RECOVERY_IMAGE="recovery_image.bin" 55 RECOVERY_IMAGE="recovery_image.bin"
41 56
42 mount_gpt_cleanup() { 57 mount_gpt_cleanup() {
43 "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2" 58 "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2"
44 } 59 }
45 60
46 # Modifies an existing image for recovery use 61 # Modifies an existing image for recovery use
47 update_recovery_packages() { 62 update_recovery_packages() {
48 local image_name=$1 63 local image_name=$1
49 64
50 echo "Modifying image ${image_name} for recovery use" 65 echo "Modifying image ${image_name} for recovery use"
51 66
52 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT 67 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_DIR}\"" EXIT
53 68
54 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ 69 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${IMAGE_DIR}" \
55 --image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \ 70 --image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \
56 -s "${STATEFUL_FS_DIR}" 71 -s "${STATEFUL_DIR}"
57 72
58 # Mark the image as a recovery image (needed for recovery boot) 73 # Mark the image as a recovery image (needed for recovery boot)
59 sudo touch "${STATEFUL_FS_DIR}/.recovery" 74 sudo touch "${STATEFUL_DIR}/.recovery"
60 75
61 trap - EXIT 76 trap - EXIT
62 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ 77 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
63 -s "${STATEFUL_FS_DIR}" 78 -s "${STATEFUL_DIR}"
64 } 79 }
65 80
66 # Main 81 # Main
67 82
68 DST_PATH="${OUTPUT_DIR}/${RECOVERY_IMAGE}" 83 DST_PATH="${IMAGE_DIR}/${RECOVERY_IMAGE}"
69 echo "Making a copy of original image ${SRC_PATH}" 84 echo "Making a copy of original image ${FLAGS_image}"
70 cp $SRC_PATH $DST_PATH 85 cp $FLAGS_image $DST_PATH
71 update_recovery_packages $DST_PATH 86 update_recovery_packages $DST_PATH
72 echo "Recovery image created at ${DST_PATH}" 87 echo "Recovery image created at ${DST_PATH}"
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698