mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-30 10:01:32 +02:00
Read script parameters from config file.
make_factory_package.sh needs many parameters and to support multi-board installation it has to be run twice (without and with --subfolder). This change adds the functionality to read sections of parameters from a config file and executes them in order. BUG=chrome-os-partner:5850 TEST=1. Create a config file (mp_factory.conf) with the following content: [x86-zgb] --factory ~/trunk/src/build/images/${BOARD}/latest/chromiumos_factory_image.bin --release ~/trunk/src/build/images/${BOARD}/latest/chromiumos_image.bin --hwid_updater ~/trunk/src/platform/chromeos-hwid/hwid_bundle_zgb.sh --firmware_updater none --detect_release_image [x86-zgb-he] --subfolder x86-zgb-he --factory ~/trunk/src/build/images/${BOARD}/latest/chromiumos_factory_image.bin --release ~/trunk/src/build/images/${BOARD}/latest/chromiumos_image.bin --hwid_updater ~/trunk/src/platform/chromeos-hwid/hwid_bundle_zgb.sh --firmware_updater none --detect_release_image 2. BOARD=x86-zgb ./make_factory_package.sh --config mp_factory.conf Change-Id: I3435f3afbf40ec3b8bd02a3514f599a7a535510e Reviewed-on: http://gerrit.chromium.org/gerrit/7473 Tested-by: Chinyue Chen <chinyue@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org>
This commit is contained in:
parent
b392153c54
commit
67594116c0
@ -74,6 +74,8 @@ DEFINE_boolean preserve ${FLAGS_FALSE} \
|
||||
DEFINE_integer sectors 31277232 "Size of image in sectors"
|
||||
DEFINE_boolean detect_release_image ${FLAGS_TRUE} \
|
||||
"If set, try to auto-detect the type of release image and convert if required"
|
||||
DEFINE_string config "" \
|
||||
"Config file where parameters are read from"
|
||||
|
||||
# Parse command line
|
||||
FLAGS "$@" || exit 1
|
||||
@ -617,10 +619,74 @@ To run the server:
|
||||
python2.6 devserver.py --factory_config miniomaha.conf"
|
||||
}
|
||||
|
||||
parse_and_run_config() {
|
||||
# This function parses parameters from config file. Parameters can be put
|
||||
# in sections and sections of parameters will be run in turn.
|
||||
#
|
||||
# Config file format:
|
||||
# [section1]
|
||||
# --param value
|
||||
# --another_param # comment
|
||||
#
|
||||
# # some more comment
|
||||
# [section2]
|
||||
# --yet_another_param
|
||||
#
|
||||
# Note that it's not allowed to read from config file recursively.
|
||||
|
||||
local config_file="$1"
|
||||
local -a cmds
|
||||
local cmd=""
|
||||
|
||||
echo "Read parameters from: $config_file"
|
||||
local config="$(<$config_file)"
|
||||
local IFS=$'\n'
|
||||
for line in $config
|
||||
do
|
||||
if [[ "$line" =~ \[.*\] ]]; then
|
||||
if [ -n "$cmd" ]; then
|
||||
cmds+=("$cmd")
|
||||
cmd=""
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
line="${line%%#*}"
|
||||
cmd="$cmd $line"
|
||||
done
|
||||
if [ -n "$cmd" ]; then
|
||||
cmds+=("$cmd")
|
||||
fi
|
||||
|
||||
for cmd in "${cmds[@]}"
|
||||
do
|
||||
info "Executing: $0 $cmd"
|
||||
eval "MFP_SUBPROCESS=1 $0 $cmd"
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
set -e
|
||||
trap on_exit EXIT
|
||||
|
||||
if [ -n "$FLAGS_config" ]; then
|
||||
[ -z "$MFP_SUBPROCESS" ] ||
|
||||
die "Recursively reading from config file is not allowed"
|
||||
|
||||
check_file_param FLAGS_config ""
|
||||
check_empty_param FLAGS_release "when using config file"
|
||||
check_empty_param FLAGS_factory "when using config file"
|
||||
check_empty_param FLAGS_firmware_updater "when using config file"
|
||||
check_empty_param FLAGS_hwid_updater "when using config file"
|
||||
check_empty_param FLAGS_install_shim "when using config file"
|
||||
check_empty_param FLAGS_complete_script "when using config file"
|
||||
check_empty_param FLAGS_usbimg "when using config file"
|
||||
check_empty_param FLAGS_diskimg "when using config file"
|
||||
check_empty_param FLAGS_subfolder "when using config file"
|
||||
|
||||
parse_and_run_config "$FLAGS_config"
|
||||
exit
|
||||
fi
|
||||
|
||||
check_parameters
|
||||
setup_environment
|
||||
if [ "$FLAGS_detect_release_image" = "$FLAGS_TRUE" ]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user