From d2631cd95274033609b0826e93ba3be346c0a13b Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Sat, 17 Sep 2011 18:36:11 +0800 Subject: [PATCH] crosutils: add 'archive_factory' to create factory bundles To generate a bundle with mini-omaha and all utility scripts, we need a new archive script. BUG=chrome-os-partner:5979 TEST=./archive_factory --factory_test factory_test \ --factory_install factory_install --script . --dev ../platform/dev/ \ --bin ../../chroot/usr/bin # output: [ 0/2.4G] adding: bin/cgpt (stored 0%) [633K/2.4G] adding: dev/autoupdate.py (stored 0%) [658K/2.4G] adding: dev/buildutil.py (stored 0%) [660K/2.4G] adding: dev/devserver.py (stored 0%) [671K/2.4G] adding: dev/static/ (stored 0%) [671K/2.4G] adding: factory_test/chromiumos_factory_image.bin [1.9G/506M] adding: factory_test/pack_partitions.sh (stored 0%) [1.9G/506M] adding: factory_test/unpack_partitions.sh (stored 0%) [1.9G/506M] adding: hwid/hwid_bundle_zgb_all.sh (stored 0%) [1.9G/502M] adding: install_shim/factory_install_shim.bin [2.4G/119K] adding: install_shim/pack_partitions.sh (stored 0%) [2.4G/115K] adding: install_shim/unpack_partitions.sh (stored 0%) [2.4G/112K] adding: scripts/lib/cros_image_common.sh (stored 0%) [2.4G/102K] adding: scripts/lib/shflags/shflags (stored 0%) [2.4G/ 71K] adding: scripts/common.sh (stored 0%) [2.4G/ 49K] adding: scripts/chromeos-common.sh (stored 0%) [2.4G/ 33K] adding: scripts/make_factory_package.sh (stored 0%) [2.4G/ 11K] adding: scripts/make_universal_factory_shim.sh (stored 0%) [2.4G/4.0K] adding: scripts/mk_memento_images.sh (stored 0%) Change-Id: Idd645c908c4fed70408406278163309037c285dd Reviewed-on: http://gerrit.chromium.org/gerrit/7906 Tested-by: Hung-Te Lin Reviewed-by: Nick Sanders --- archive_factory | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 archive_factory diff --git a/archive_factory b/archive_factory new file mode 100755 index 0000000000..89b5e9bf00 --- /dev/null +++ b/archive_factory @@ -0,0 +1,129 @@ +#!/bin/bash + +# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Script to take an archived build result and prepare a factory bundle. + +# --- BEGIN COMMON.SH BOILERPLATE --- +# Load common CrOS utilities. Inside the chroot this file is installed in +# /usr/lib/crosutils. Outside the chroot we find it relative to the script's +# location. +find_common_sh() { + local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) + local path + + SCRIPT_ROOT= + for path in "${common_paths[@]}"; do + if [ -r "${path}/common.sh" ]; then + SCRIPT_ROOT=${path} + break + fi + done +} + +find_common_sh +. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; } +# --- END COMMON.SH BOILERPLATE --- + +# Flags +DEFINE_string factory_test "" "Directory with factory test image." +DEFINE_string factory_install "" "Directory with factory install image." +DEFINE_string scripts "" "Directory with factory setup scripts." +DEFINE_string devserver "" "Directory with mini-omaha files." +DEFINE_string bin "" "Directory with binary programs (ex: cgpt)." +DEFINE_string output "factory.zip" "Output zip archive file path." +DEFINE_boolean fast $FLAGS_FALSE "Build faster (lower compression rate)." + +# Parse command line +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" +set -e + +STAGE_DIR="" + +clean_up() { + [ -z "$STAGE_DIR" ] || rm -rf "$STAGE_DIR" || true +} + +# Builds the factory bundle +build_factory_bundle() { + local stage_dir="$(mktemp -d --tmpdir)" + local output="$(readlink -f "$FLAGS_output")" + local level="-9" + STAGE_DIR="$stage_dir" + rm -f "$output" + + if [ "$FLAGS_fast" = "$FLAGS_TRUE" ]; then + level='-1' + fi + + (cd "$stage_dir" + ln -s "$FLAGS_factory_test" factory_test + ln -s "$FLAGS_factory_install" install_shim + ln -s "$FLAGS_scripts" scripts + ln -s "$FLAGS_devserver" dev + ln -s "$FLAGS_bin" bin + if [ -e "factory_test/hwid" ]; then + ln -s factory_test/hwid hwid + fi + + # Archive file resources. + zip $level -db -dd "$output" \ + bin/cgpt \ + dev/autoupdate.py \ + dev/buildutil.py \ + dev/devserver.py \ + dev/static \ + factory_test/*factory_image* \ + factory_test/*partition* \ + hwid/hwid* \ + install_shim/*factory_install* \ + install_shim/*partition* \ + install_shim/netboot/* \ + scripts/chromeos-common.sh \ + scripts/common.sh \ + scripts/lib/cros_image_common.sh \ + scripts/lib/shflags/shflags \ + scripts/make_factory_package.sh \ + scripts/make_universal_factory_shim.sh \ + scripts/mk_memento_images.sh \ + # End of resource list + + # Adds symlinks as script helpers + ln -s . platform + ln -s . src + zip --grow --symlinks "$output" platform src + ) +} + +normalize_directory_param() { + local param="$1" + local value="$(eval "echo \$FLAGS_$param")" + + if [ -z "$value" ]; then + die "Need directory parameter: --$param" + elif [ ! -d "$(readlink -f "$value")" ]; then + die "--$param: '$value' is not a directory." + else + eval "FLAGS_$param=\"$(readlink -f "$value")\"" + fi +} + +main() { + local param + for param in factory_test \ + factory_install \ + scripts \ + devserver \ + bin; do + normalize_directory_param "$param" + done + [ -n "$FLAGS_output" ] || die "Need output file name: --output" + build_factory_bundle + info "Done. Factory bundle created: $FLAGS_output" +} + +trap clean_up EXIT +main "$@"