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

Unified Diff: make_factory_package.sh

Issue 5168001: cros_utils: refine factory and imaging related scripts (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: merge with latest changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/cros_image_common.sh ('k') | mk_memento_images.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: make_factory_package.sh
diff --git a/make_factory_package.sh b/make_factory_package.sh
index 57c23a159ca00b13d526df1940826a114df47584..0eb200e52a5141e27784bd2915cae7d487075570 100755
--- a/make_factory_package.sh
+++ b/make_factory_package.sh
@@ -39,32 +39,33 @@ DEFINE_string subfolder "" \
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
-if [ ! -f "${FLAGS_release}" ] ; then
+if [ ! -f "${FLAGS_release}" ]; then
echo "Cannot find image file ${FLAGS_release}"
exit 1
fi
-if [ ! -f "${FLAGS_factory}" ] ; then
+if [ ! -f "${FLAGS_factory}" ]; then
echo "Cannot find image file ${FLAGS_factory}"
exit 1
fi
-if [ ! -z "${FLAGS_firmware_updater}" ] && \
- [ ! -f "${FLAGS_firmware_updater}" ] ; then
+if [ -n "${FLAGS_firmware_updater}" ] &&
+ [ ! -f "${FLAGS_firmware_updater}" ]; then
echo "Cannot find firmware file ${FLAGS_firmware_updater}"
exit 1
fi
# Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work.
-OMAHA_DIR=${SRC_ROOT}/platform/dev
-OMAHA_DATA_DIR=${OMAHA_DIR}/static/
+OMAHA_DIR="${SRC_ROOT}/platform/dev"
+OMAHA_CONF="${OMAHA_DIR}/miniomaha.conf"
+OMAHA_DATA_DIR="${OMAHA_DIR}/static/"
# Note: The subfolder flag can only append configs. That means you will need
# to have unique board IDs for every time you run. If you delete miniomaha.conf
# you can still use this flag and it will start fresh.
-if [ -n "${FLAGS_subfolder}" ] ; then
- OMAHA_DATA_DIR=${OMAHA_DIR}/static/${FLAGS_subfolder}/
+if [ -n "${FLAGS_subfolder}" ]; then
+ OMAHA_DATA_DIR="${OMAHA_DIR}/static/${FLAGS_subfolder}/"
fi
if [ ${INSIDE_CHROOT} -eq 0 ]; then
@@ -74,20 +75,20 @@ if [ ${INSIDE_CHROOT} -eq 0 ]; then
fi
# Use this image as the source image to copy
-RELEASE_DIR=`dirname ${FLAGS_release}`
-FACTORY_DIR=`dirname ${FLAGS_factory}`
-RELEASE_IMAGE=`basename ${FLAGS_release}`
-FACTORY_IMAGE=`basename ${FLAGS_factory}`
+RELEASE_DIR="$(dirname "${FLAGS_release}")"
+FACTORY_DIR="$(dirname "${FLAGS_factory}")"
+RELEASE_IMAGE="$(basename "${FLAGS_release}")"
+FACTORY_IMAGE="$(basename "${FLAGS_factory}")"
prepare_omaha() {
- sudo rm -rf ${OMAHA_DATA_DIR}/rootfs-test.gz
- sudo rm -rf ${OMAHA_DATA_DIR}/rootfs-release.gz
- rm -rf ${OMAHA_DATA_DIR}/efi.gz
- rm -rf ${OMAHA_DATA_DIR}/oem.gz
- rm -rf ${OMAHA_DATA_DIR}/state.gz
- if [ ! -f "${OMAHA_DATA_DIR}" ] ; then
- mkdir -p ${OMAHA_DATA_DIR}
+ sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-test.gz"
+ sudo rm -rf "${OMAHA_DATA_DIR}/rootfs-release.gz"
+ rm -rf "${OMAHA_DATA_DIR}/efi.gz"
+ rm -rf "${OMAHA_DATA_DIR}/oem.gz"
+ rm -rf "${OMAHA_DATA_DIR}/state.gz"
+ if [ ! -d "${OMAHA_DATA_DIR}" ]; then
+ mkdir -p "${OMAHA_DATA_DIR}"
fi
}
@@ -102,12 +103,12 @@ prepare_dir() {
compress_and_hash_memento_image() {
local input_file="$1"
- if has_part_tools; then
- sudo "${SCRIPTS_DIR}/mk_memento_images.sh" "$input_file" 2 3 |
+ if [ -n "${IMAGE_IS_UNPACKED}" ]; then
+ sudo "${SCRIPTS_DIR}/mk_memento_images.sh" part_2 part_3 |
grep hash |
awk '{print $4}'
else
- sudo "${SCRIPTS_DIR}/mk_memento_images.sh" part_2 part_3 |
+ sudo "${SCRIPTS_DIR}/mk_memento_images.sh" "$input_file" 2 3 |
grep hash |
awk '{print $4}'
fi
@@ -119,12 +120,12 @@ compress_and_hash_file() {
if [ -z "$input_file" ]; then
# Runs as a pipe processor
- gzip_compress -c -9 |
+ image_gzip_compress -c -9 |
tee "$output_file" |
openssl sha1 -binary |
openssl base64
else
- gzip_compress -c -9 "$input_file" |
+ image_gzip_compress -c -9 "$input_file" |
tee "$output_file" |
openssl sha1 -binary |
openssl base64
@@ -136,30 +137,38 @@ compress_and_hash_partition() {
local part_num="$2"
local output_file="$3"
- if has_part_tools; then
- dump_partition "$input_file" "$part_num" |
- compress_and_hash_file "" "$output_file"
- else
+ if [ -n "${IMAGE_IS_UNPACKED}" ]; then
compress_and_hash_file "part_$part_num" "$output_file"
+ else
+ image_dump_partition "$input_file" "$part_num" |
+ compress_and_hash_file "" "$output_file"
fi
}
# Clean up stale config and data files.
prepare_omaha
+# Decide if we should unpack partition
+if image_has_part_tools; then
+ IMAGE_IS_UNPACKED=
+else
+ #TODO(hungte) Currently we run unpack_partitions.sh if part_tools are not
+ # found. If the format of unpack_partitions.sh is reliable, we can prevent
+ # creating temporary files. See image_part_offset for more information.
+ echo "WARNING: cannot find partition tools. Using unpack_partitions.sh." >&2
+ IMAGE_IS_UNPACKED=1
+fi
+
# Get the release image.
-pushd ${RELEASE_DIR} > /dev/null
+pushd "${RELEASE_DIR}" >/dev/null
echo "Generating omaha release image from ${FLAGS_release}"
echo "Generating omaha factory image from ${FLAGS_factory}"
echo "Output omaha image to ${OMAHA_DATA_DIR}"
-echo "Output omaha config to ${OMAHA_DIR}/miniomaha.conf"
+echo "Output omaha config to ${OMAHA_CONF}"
prepare_dir
-if ! has_part_tools; then
- #TODO(hungte) we can still avoid running unpack_partitions.sh
- # by $(cat unpack_partitions.sh | grep Label | sed "s/#//" | grep ${name}" |
- # awk '{ print $1}') to fetch offset/size.
+if [ -n "${IMAGE_IS_UNPACKED}" ]; then
echo "Unpacking image ${RELEASE_IMAGE} ..." >&2
sudo ./unpack_partitions.sh "${RELEASE_IMAGE}" 2>/dev/null
fi
@@ -167,24 +176,24 @@ fi
release_hash="$(compress_and_hash_memento_image "${RELEASE_IMAGE}")"
sudo chmod a+rw update.gz
mv update.gz rootfs-release.gz
-mv rootfs-release.gz ${OMAHA_DATA_DIR}
+mv rootfs-release.gz "${OMAHA_DATA_DIR}"
echo "release: ${release_hash}"
oem_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 8 "oem.gz")"
-mv oem.gz ${OMAHA_DATA_DIR}
+mv oem.gz "${OMAHA_DATA_DIR}"
echo "oem: ${oem_hash}"
efi_hash="$(compress_and_hash_partition "${RELEASE_IMAGE}" 12 "efi.gz")"
-mv efi.gz ${OMAHA_DATA_DIR}
+mv efi.gz "${OMAHA_DATA_DIR}"
echo "efi: ${efi_hash}"
-popd > /dev/null
+popd >/dev/null
# Go to retrieve the factory test image.
-pushd ${FACTORY_DIR} > /dev/null
+pushd "${FACTORY_DIR}" >/dev/null
prepare_dir
-if ! has_part_tools; then
+if [ -n "${IMAGE_IS_UNPACKED}" ]; then
echo "Unpacking image ${FACTORY_IMAGE} ..." >&2
sudo ./unpack_partitions.sh "${FACTORY_IMAGE}" 2>/dev/null
fi
@@ -192,16 +201,16 @@ fi
test_hash="$(compress_and_hash_memento_image "${FACTORY_IMAGE}")"
sudo chmod a+rw update.gz
mv update.gz rootfs-test.gz
-mv rootfs-test.gz ${OMAHA_DATA_DIR}
+mv rootfs-test.gz "${OMAHA_DATA_DIR}"
echo "test: ${test_hash}"
state_hash="$(compress_and_hash_partition "${FACTORY_IMAGE}" 1 "state.gz")"
-mv state.gz ${OMAHA_DATA_DIR}
+mv state.gz "${OMAHA_DATA_DIR}"
echo "state: ${state_hash}"
-popd > /dev/null
+popd >/dev/null
-if [ ! -z ${FLAGS_firmware_updater} ] ; then
+if [ -n "${FLAGS_firmware_updater}" ]; then
SHELLBALL="${FLAGS_firmware_updater}"
if [ ! -f "$SHELLBALL" ]; then
echo "Failed to find firmware updater: $SHELLBALL."
@@ -209,70 +218,70 @@ if [ ! -z ${FLAGS_firmware_updater} ] ; then
fi
firmware_hash="$(compress_and_hash_file "$SHELLBALL" "firmware.gz")"
- mv firmware.gz ${OMAHA_DATA_DIR}
+ mv firmware.gz "${OMAHA_DATA_DIR}"
echo "firmware: ${firmware_hash}"
fi
# If the file does exist and we are using the subfolder flag we are going to
# append another config.
-if [ -n "${FLAGS_subfolder}" ] && \
- [ -f "${OMAHA_DIR}"/miniomaha.conf"" ] ; then
+if [ -n "${FLAGS_subfolder}" ] &&
+ [ -f "${OMAHA_CONF}" ]; then
# Remove the ']' from the last line of the file so we can add another config.
- while [ -s "${OMAHA_DIR}/miniomaha.conf" ]; do
+ while [ -s "${OMAHA_CONF}" ]; do
# If the last line is null
- if [ -z "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" ]; then
- sed -i '$d' "${OMAHA_DIR}/miniomaha.conf"
- elif [ "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" != ']' ]; then
- sed -i '$d' "${OMAHA_DIR}/miniomaha.conf"
+ if [ -z "$(tail -1 "${OMAHA_CONF}")" ]; then
+ sed -i '$d' "${OMAHA_CONF}"
+ elif [ "$(tail -1 "${OMAHA_CONF}")" != ']' ]; then
+ sed -i '$d' "${OMAHA_CONF}"
else
break
fi
done
# Remove the last ]
- if [ "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" = ']' ]; then
- sed -i '$d' "${OMAHA_DIR}/miniomaha.conf"
+ if [ "$(tail -1 "${OMAHA_CONF}")" = ']' ]; then
+ sed -i '$d' "${OMAHA_CONF}"
fi
# If the file is empty, create it from scratch
- if [ ! -s "${OMAHA_DIR}/miniomaha.conf" ]; then
- echo "config = [" > "${OMAHA_DIR}/miniomaha.conf"
+ if [ ! -s "${OMAHA_CONF}" ]; then
+ echo "config = [" >"${OMAHA_CONF}"
fi
else
- echo "config = [" > "${OMAHA_DIR}/miniomaha.conf"
+ echo "config = [" >"${OMAHA_CONF}"
fi
-if [ -n "${FLAGS_subfolder}" ] ; then
+if [ -n "${FLAGS_subfolder}" ]; then
subfolder="${FLAGS_subfolder}/"
fi
echo -n "{
'qual_ids': set([\"${FLAGS_board}\"]),
- 'factory_image': '"${subfolder}"rootfs-test.gz',
+ 'factory_image': '${subfolder}rootfs-test.gz',
'factory_checksum': '${test_hash}',
- 'release_image': '"${subfolder}"rootfs-release.gz',
+ 'release_image': '${subfolder}rootfs-release.gz',
'release_checksum': '${release_hash}',
- 'oempartitionimg_image': '"${subfolder}"oem.gz',
+ 'oempartitionimg_image': '${subfolder}oem.gz',
'oempartitionimg_checksum': '${oem_hash}',
- 'efipartitionimg_image': '"${subfolder}"efi.gz',
+ 'efipartitionimg_image': '${subfolder}efi.gz',
'efipartitionimg_checksum': '${efi_hash}',
- 'stateimg_image': '"${subfolder}"state.gz',
- 'stateimg_checksum': '${state_hash}'," >> ${OMAHA_DIR}/miniomaha.conf
+ 'stateimg_image': '${subfolder}state.gz',
+ 'stateimg_checksum': '${state_hash}'," >>"${OMAHA_CONF}"
-if [ ! -z "${FLAGS_firmware_updater}" ] ; then
+if [ -n "${FLAGS_firmware_updater}" ] ; then
echo -n "
- 'firmware_image': '"${subfolder}"firmware.gz',
- 'firmware_checksum': '${firmware_hash}'," >> ${OMAHA_DIR}/miniomaha.conf
+ 'firmware_image': '${subfolder}firmware.gz',
+ 'firmware_checksum': '${firmware_hash}'," >>"${OMAHA_CONF}"
fi
echo -n "
},
]
-" >> ${OMAHA_DIR}/miniomaha.conf
-
-echo "The miniomaha server lives in src/platform/dev"
-echo "to validate the configutarion, run:"
-echo " python2.6 devserver.py --factory_config miniomaha.conf \
---validate_factory_config"
-echo "To run the server:"
-echo " python2.6 devserver.py --factory_config miniomaha.conf"
+" >>"${OMAHA_CONF}"
+
+echo "The miniomaha server lives in src/platform/dev.
+To validate the configutarion, run:
+ python2.6 devserver.py --factory_config miniomaha.conf \
+ --validate_factory_config
+To run the server:
+ python2.6 devserver.py --factory_config miniomaha.conf"
« no previous file with comments | « lib/cros_image_common.sh ('k') | mk_memento_images.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698