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

Side by Side Diff: scripts/image_signing/common.sh

Issue 3772013: make_dev_ssd: new script to change SSD image to dev key (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: Refine shflags dependency Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | scripts/image_signing/make_dev_firmware.sh » ('j') | 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 # Determine script directory 7 # Determine script directory
8 SCRIPT_DIR=$(dirname $0) 8 SCRIPT_DIR=$(dirname $0)
9 PROG=$(basename $0) 9 PROG=$(basename $0)
10 GPT=cgpt 10 GPT=cgpt
11 11
12 # The tag when the rootfs is changed. 12 # The tag when the rootfs is changed.
13 TAG_NEEDS_TO_BE_SIGNED="/root/.need_to_be_signed" 13 TAG_NEEDS_TO_BE_SIGNED="/root/.need_to_be_signed"
14 14
15 # Load shflags 15 # Finds and loads the 'shflags' library, or return as failed.
16 if [ -f /usr/lib/shflags ]; then 16 load_shflags() {
17 . /usr/lib/shflags 17 # Load shflags
18 else 18 if [ -f /usr/lib/shflags ]; then
19 . "${SCRIPT_DIR}/lib/shflags/shflags" 19 . /usr/lib/shflags
20 fi 20 elif [ -f "${SCRIPT_DIR}/shflags" ]; then
21 . "${SCRIPT_DIR}/shflags"
22 elif [ -f "${SCRIPT_DIR}/lib/shflags/shflags" ]; then
23 . "${SCRIPT_DIR}/lib/shflags/shflags"
24 else
25 echo "ERROR: Cannot find the required shflags library."
26 return 1
27 fi
28 }
21 29
22 # List of Temporary files and mount points. 30 # List of Temporary files and mount points.
23 TEMP_FILE_LIST=$(mktemp) 31 TEMP_FILE_LIST=$(mktemp)
24 TEMP_DIR_LIST=$(mktemp) 32 TEMP_DIR_LIST=$(mktemp)
25 33
26 # Read GPT table to find the starting location of a specific partition. 34 # Read GPT table to find the starting location of a specific partition.
27 # Args: DEVICE PARTNUM 35 # Args: DEVICE PARTNUM
28 # Returns: offset (in sectors) of partition PARTNUM 36 # Returns: offset (in sectors) of partition PARTNUM
29 partoffset() { 37 partoffset() {
30 sudo $GPT show -b -i $2 $1 38 sudo $GPT show -b -i $2 $1
31 } 39 }
32 40
33 # Read GPT table to find the size of a specific partition. 41 # Read GPT table to find the size of a specific partition.
34 # Args: DEVICE PARTNUM 42 # Args: DEVICE PARTNUM
35 # Returns: size (in sectors) of partition PARTNUM 43 # Returns: size (in sectors) of partition PARTNUM
36 partsize() { 44 partsize() {
37 sudo $GPT show -s -i $2 $1 45 sudo $GPT show -s -i $2 $1
38 } 46 }
39 47
40 # Tags a file system as "needs to be resigned". 48 # Tags a file system as "needs to be resigned".
41 # Args: MOUNTDIRECTORY 49 # Args: MOUNTDIRECTORY
42 tag_as_needs_to_be_resigned() { 50 tag_as_needs_to_be_resigned() {
43 local mount_dir="$1" 51 local mount_dir="$1"
44 sudo touch "$mount_dir/$TAG_NEEDS_TO_BE_SIGNED" 52 sudo touch "$mount_dir/$TAG_NEEDS_TO_BE_SIGNED"
45 } 53 }
46 54
47 # Determines if the target file system has the tag for resign 55 # Determines if the target file system has the tag for resign
48 # Args: MOUNTDIRECTORY 56 # Args: MOUNTDIRECTORY
49 # Returns: $FLAGS_TRUE if the tag is there, otherwise $FLAGS_FALSE 57 # Returns: true if the tag is there otherwise false
50 has_needs_to_be_resigned_tag() { 58 has_needs_to_be_resigned_tag() {
51 local mount_dir="$1" 59 local mount_dir="$1"
52 if [ -f "$mount_dir/$TAG_NEEDS_TO_BE_SIGNED" ]; then 60 [ -f "$mount_dir/$TAG_NEEDS_TO_BE_SIGNED" ]
53 return ${FLAGS_TRUE}
54 else
55 return ${FLAGS_FALSE}
56 fi
57 } 61 }
58 62
59 # Determines if the target file system is a Chrome OS root fs 63 # Determines if the target file system is a Chrome OS root fs
60 # Args: MOUNTDIRECTORY 64 # Args: MOUNTDIRECTORY
61 # Returns: $FLAGS_TRUE if MOUNTDIRECTORY looks like root fs, 65 # Returns: true if MOUNTDIRECTORY looks like root fs, otherwise false
62 # otherwise $FLAGS_FALSE
63 is_rootfs_partition() { 66 is_rootfs_partition() {
64 local mount_dir="$1" 67 local mount_dir="$1"
65 if [ -f "$mount_dir/$(dirname "$TAG_NEEDS_TO_BE_SIGNED")" ]; then 68 [ -f "$mount_dir/$(dirname "$TAG_NEEDS_TO_BE_SIGNED")" ]
66 return ${FLAGS_TRUE}
67 else
68 return ${FLAGS_FALSE}
69 fi
70 } 69 }
71 70
72 # Mount a partition read-only from an image into a local directory 71 # Mount a partition read-only from an image into a local directory
73 # Args: IMAGE PARTNUM MOUNTDIRECTORY 72 # Args: IMAGE PARTNUM MOUNTDIRECTORY
74 mount_image_partition_ro() { 73 mount_image_partition_ro() {
75 local image=$1 74 local image=$1
76 local partnum=$2 75 local partnum=$2
77 local mount_dir=$3 76 local mount_dir=$3
78 local offset=$(partoffset "$image" "$partnum") 77 local offset=$(partoffset "$image" "$partnum")
79 sudo mount -o loop,ro,offset=$((offset * 512)) "$image" "$mount_dir" 78 sudo mount -o loop,ro,offset=$((offset * 512)) "$image" "$mount_dir"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 echo "Warning: image may be modified. Please resign image." 141 echo "Warning: image may be modified. Please resign image."
143 fi 142 fi
144 sudo umount -d $i 2>/dev/null 143 sudo umount -d $i 2>/dev/null
145 rm -rf $i 144 rm -rf $i
146 fi 145 fi
147 done 146 done
148 set -e 147 set -e
149 rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST 148 rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST
150 } 149 }
151 150
151 # Returns true if all files in parameters exist.
152 ensure_files_exist() {
153 local filename return_value=0
154 for filename in "$@"; do
155 if [ ! -f "$filename" -a ! -b "$filename" ]; then
156 echo "ERROR: Cannot find required file: $filename"
157 return_value=1
158 fi
159 done
160
161 return $return_value
162 }
163
152 trap "cleanup_temps_and_mounts" EXIT 164 trap "cleanup_temps_and_mounts" EXIT
153 165
OLDNEW
« no previous file with comments | « no previous file | scripts/image_signing/make_dev_firmware.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698