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

Side by Side Diff: make_factory_package.sh

Issue 4824003: crosutils: refine memento image / factory package creation (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: should not compress twice Created 10 years, 1 month 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 | « image_common.sh ('k') | mk_memento_images.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) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 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 generate a factory install partition set and miniomaha.conf 7 # Script to generate a factory install partition set and miniomaha.conf
8 # file from a release image and a factory image. This creates a server 8 # file from a release image and a factory image. This creates a server
9 # configuration that can be installed using a factory install shim. 9 # configuration that can be installed using a factory install shim.
10 # 10 #
11 # miniomaha lives in src/platform/dev/ and miniomaha partition sets live 11 # miniomaha lives in src/platform/dev/ and miniomaha partition sets live
12 # in src/platform/dev/static. 12 # in src/platform/dev/static.
13 13
14 # Load common constants. This should be the first executable line. 14 # Load common constants. This should be the first executable line.
15 # The path to common.sh should be relative to your script's location. 15 # The path to common.sh should be relative to your script's location.
16 . "$(dirname "$0")/common.sh" 16 . "$(dirname "$0")/common.sh"
17 17
18 # Load functions and constants for chromeos-install 18 # Load functions and constants for chromeos-install
19 . "$(dirname "$0")/chromeos-common.sh" 19 . "$(dirname "$0")/chromeos-common.sh"
20 20
21 # Load functions designed for image processing
22 . "$(dirname "$0")/image_common.sh"
23
21 get_default_board 24 get_default_board
22 25
23 # Flags 26 # Flags
24 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" 27 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built"
25 DEFINE_string factory "" \ 28 DEFINE_string factory "" \
26 "Directory and file containing factory image: /path/chromiumos_test_image.bin" 29 "Directory and file containing factory image: /path/chromiumos_test_image.bin"
27 DEFINE_string firmware_updater "" \ 30 DEFINE_string firmware_updater "" \
28 "If set, include the firmware shellball into the server configuration" 31 "If set, include the firmware shellball into the server configuration"
29 DEFINE_string release "" \ 32 DEFINE_string release "" \
30 "Directory and file containing release image: /path/chromiumos_image.bin" 33 "Directory and file containing release image: /path/chromiumos_image.bin"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 91 }
89 92
90 prepare_dir() { 93 prepare_dir() {
91 sudo rm -rf rootfs-test.gz 94 sudo rm -rf rootfs-test.gz
92 sudo rm -rf rootfs-release.gz 95 sudo rm -rf rootfs-release.gz
93 rm -rf efi.gz 96 rm -rf efi.gz
94 rm -rf oem.gz 97 rm -rf oem.gz
95 rm -rf state.gz 98 rm -rf state.gz
96 } 99 }
97 100
101 compress_and_hash_memento_image() {
102 local input_file="$1"
103
104 if has_part_tools; then
105 sudo "${SCRIPTS_DIR}/mk_memento_images.sh" "$input_file" 2 3 |
106 grep hash |
107 awk '{print $4}'
108 else
109 sudo "${SCRIPTS_DIR}/mk_memento_images.sh" part_2 part_3 |
110 grep hash |
111 awk '{print $4}'
112 fi
113 }
114
115 compress_and_hash_file() {
116 local input_file="$1"
117 local output_file="$2"
118
119 if [ -z "$input_file" ]; then
120 # Runs as a pipe processor
121 gzip_compress -c -9 |
122 tee "$output_file" |
123 openssl sha1 -binary |
124 openssl base64
125 else
126 gzip_compress -c -9 "$input_file" |
127 tee "$output_file" |
128 openssl sha1 -binary |
129 openssl base64
130 fi
131 }
132
133 compress_and_hash_partition() {
134 local input_file="$1"
135 local part_num="$2"
136 local output_file="$3"
137
138 if has_part_tools; then
139 dump_partition "$input_file" "$part_num" |
140 compress_and_hash_file "" "$output_file"
141 else
142 compress_and_hash_file "part_$part_num" "$output_file"
143 fi
144 }
98 145
99 # Clean up stale config and data files. 146 # Clean up stale config and data files.
100 prepare_omaha 147 prepare_omaha
101 148
102 # Get the release image. 149 # Get the release image.
103 pushd ${RELEASE_DIR} > /dev/null 150 pushd ${RELEASE_DIR} > /dev/null
104 echo "Generating omaha release image from ${FLAGS_release}" 151 echo "Generating omaha release image from ${FLAGS_release}"
105 echo "Generating omaha factory image from ${FLAGS_factory}" 152 echo "Generating omaha factory image from ${FLAGS_factory}"
106 echo "Output omaha image to ${OMAHA_DATA_DIR}" 153 echo "Output omaha image to ${OMAHA_DATA_DIR}"
107 echo "Output omaha config to ${OMAHA_DIR}/miniomaha.conf" 154 echo "Output omaha config to ${OMAHA_DIR}/miniomaha.conf"
108 155
109 prepare_dir 156 prepare_dir
110 157
111 sudo ./unpack_partitions.sh ${RELEASE_IMAGE} &> /dev/null 158 if ! has_part_tools; then
112 release_hash=`sudo ${SCRIPTS_DIR}/mk_memento_images.sh part_2 part_3 \ 159 #TODO(hungte) we can still avoid running unpack_partitions.sh
113 | grep hash | awk '{print $4}'` 160 # by $(cat unpack_partitions.sh | grep Label | sed "s/#//" | grep ${name}" |
161 # awk '{ print $1}') to fetch offset/size.
162 echo "Unpacking image ${RELEASE_IMAGE} ..." >&2
163 sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
164 fi
165
166 release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")"
114 sudo chmod a+rw update.gz 167 sudo chmod a+rw update.gz
115 mv update.gz rootfs-release.gz 168 mv update.gz rootfs-release.gz
116 mv rootfs-release.gz ${OMAHA_DATA_DIR} 169 mv rootfs-release.gz ${OMAHA_DATA_DIR}
117 echo "release: ${release_hash}" 170 echo "release: ${release_hash}"
118 171
119 cat part_8 | gzip -9 > oem.gz 172 oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")"
120 oem_hash=`cat oem.gz | openssl sha1 -binary | openssl base64`
121 mv oem.gz ${OMAHA_DATA_DIR} 173 mv oem.gz ${OMAHA_DATA_DIR}
122 echo "oem: ${oem_hash}" 174 echo "oem: ${oem_hash}"
123 175
124 cat part_12 | gzip -9 > efi.gz 176 efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")"
125 efi_hash=`cat efi.gz | openssl sha1 -binary | openssl base64`
126 mv efi.gz ${OMAHA_DATA_DIR} 177 mv efi.gz ${OMAHA_DATA_DIR}
127 echo "efi: ${efi_hash}" 178 echo "efi: ${efi_hash}"
128 179
129 popd > /dev/null 180 popd > /dev/null
130 181
131 # Go to retrieve the factory test image. 182 # Go to retrieve the factory test image.
132 pushd ${FACTORY_DIR} > /dev/null 183 pushd ${FACTORY_DIR} > /dev/null
133 prepare_dir 184 prepare_dir
134 185
186 if ! has_part_tools; then
187 echo "Unpacking image ${FACTORY_IMAGE} ..." >&2
188 sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null
189 fi
135 190
136 sudo ./unpack_partitions.sh ${FACTORY_IMAGE} &> /dev/null 191 test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")"
137 test_hash=`sudo ${SCRIPTS_DIR}//mk_memento_images.sh part_2 part_3 \
138 | grep hash | awk '{print $4}'`
139 sudo chmod a+rw update.gz 192 sudo chmod a+rw update.gz
140 mv update.gz rootfs-test.gz 193 mv update.gz rootfs-test.gz
141 mv rootfs-test.gz ${OMAHA_DATA_DIR} 194 mv rootfs-test.gz ${OMAHA_DATA_DIR}
142 echo "test: ${test_hash}" 195 echo "test: ${test_hash}"
143 196
144 cat part_1 | gzip -9 > state.gz 197 state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")"
145 state_hash=`cat state.gz | openssl sha1 -binary | openssl base64`
146 mv state.gz ${OMAHA_DATA_DIR} 198 mv state.gz ${OMAHA_DATA_DIR}
147 echo "state: ${state_hash}" 199 echo "state: ${state_hash}"
148 200
149 popd > /dev/null 201 popd > /dev/null
150 202
151 if [ ! -z ${FLAGS_firmware_updater} ] ; then 203 if [ ! -z ${FLAGS_firmware_updater} ] ; then
152 SHELLBALL="${FLAGS_firmware_updater}" 204 SHELLBALL="${FLAGS_firmware_updater}"
153 if [ ! -f "$SHELLBALL" ]; then 205 if [ ! -f "$SHELLBALL" ]; then
154 echo "Failed to find firmware updater: $SHELLBALL." 206 echo "Failed to find firmware updater: $SHELLBALL."
155 exit 1 207 exit 1
156 fi 208 fi
157 209
158 cat $SHELLBALL | gzip -9 > firmware.gz 210 firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")"
159 firmware_hash=`cat firmware.gz | openssl sha1 -binary | openssl base64`
160 mv firmware.gz ${OMAHA_DATA_DIR} 211 mv firmware.gz ${OMAHA_DATA_DIR}
161 echo "firmware: ${firmware_hash}" 212 echo "firmware: ${firmware_hash}"
162 fi 213 fi
163 214
164 # If the file does exist and we are using the subfolder flag we are going to 215 # If the file does exist and we are using the subfolder flag we are going to
165 # append another config. 216 # append another config.
166 if [ -n "${FLAGS_subfolder}" ] && \ 217 if [ -n "${FLAGS_subfolder}" ] && \
167 [ -f "${OMAHA_DIR}"/miniomaha.conf"" ] ; then 218 [ -f "${OMAHA_DIR}"/miniomaha.conf"" ] ; then
168 # Remove the ']' from the last line of the file so we can add another config. 219 # Remove the ']' from the last line of the file so we can add another config.
169 sed -i '$d' ${OMAHA_DIR}/miniomaha.conf 220 sed -i '$d' ${OMAHA_DIR}/miniomaha.conf
(...skipping 28 matching lines...) Expand all
198 }, 249 },
199 ] 250 ]
200 " >> ${OMAHA_DIR}/miniomaha.conf 251 " >> ${OMAHA_DIR}/miniomaha.conf
201 252
202 echo "The miniomaha server lives in src/platform/dev" 253 echo "The miniomaha server lives in src/platform/dev"
203 echo "to validate the configutarion, run:" 254 echo "to validate the configutarion, run:"
204 echo " python2.6 devserver.py --factory_config miniomaha.conf \ 255 echo " python2.6 devserver.py --factory_config miniomaha.conf \
205 --validate_factory_config" 256 --validate_factory_config"
206 echo "To run the server:" 257 echo "To run the server:"
207 echo " python2.6 devserver.py --factory_config miniomaha.conf" 258 echo " python2.6 devserver.py --factory_config miniomaha.conf"
OLDNEW
« no previous file with comments | « image_common.sh ('k') | mk_memento_images.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698