arch-create-system: handle config-file and config-name
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -25,6 +25,7 @@ version="0.1.0"
|
||||
# global variables
|
||||
color=1
|
||||
config_json="$progname.json"
|
||||
config_name="null"
|
||||
dryrun=0
|
||||
quiet=0
|
||||
verbose=0
|
||||
@@ -419,14 +420,15 @@ get_config_id () {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
||||
# | {Id: .ConfigId, Name: .ConfigName} ' \
|
||||
# ${config_json}"
|
||||
cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
||||
| .ConfigId as \config_id \
|
||||
| select(. == \"${ConfigId}\") \
|
||||
| \$ConfigName'
|
||||
| .ConfigName ' \
|
||||
${config_json}"
|
||||
|
||||
config_name=$(eval $cmd)
|
||||
config_name=$(echo $config_names | sed -e 's/\n//g')
|
||||
#config_name=$(echo $config_name | sed -e 's/\n//g')
|
||||
|
||||
if [ $verbose -ge 2 ]; then
|
||||
printf "${MAGENTA}Config environment id: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
@@ -436,7 +438,7 @@ get_config_id () {
|
||||
|
||||
get_config_name () {
|
||||
local config_json=${configfile:-$config_json}
|
||||
local config_name=${1}
|
||||
local name=${1}
|
||||
local cmd
|
||||
|
||||
if [ $verbose -ge 1 ]; then
|
||||
@@ -448,17 +450,25 @@ get_config_name () {
|
||||
printf "${RED}Error:${MAGENTA} config file ${GREEN}'%s'${MAGENTA} can't be opend!${NO_COLOR}\n" \
|
||||
"config_json"
|
||||
fi
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
||||
cmd="jq -r --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
||||
| select(.ConfigName == \"${name}\") \
|
||||
| .ConfigName ' \
|
||||
${config_json}"
|
||||
config_name=$(eval $cmd)
|
||||
config_name=$(echo $config_names | sed -e 's/\n//g')
|
||||
config_name=$(echo $config_name | sed -e 's/\n//g')
|
||||
|
||||
if [ ${#config_name} = 0 ]; then
|
||||
if [ $verbose -ge 2 ]; then
|
||||
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${MAGENTA} not found!${NO_COLOR}\n" \
|
||||
"$name"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
if [ $verbose -ge 2 ]; then
|
||||
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${MAGENTA} exists.${NO_COLOR}\n" \
|
||||
"$config_name"
|
||||
fi
|
||||
}
|
||||
@@ -677,9 +687,9 @@ parse_config_file () {
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ${#config_name} -eq 0 ]; then
|
||||
get_config_names
|
||||
fi
|
||||
#if [ ${#config_name} -eq 0 ]; then
|
||||
# get_config_names
|
||||
#fi
|
||||
}
|
||||
|
||||
parse_params () {
|
||||
@@ -698,16 +708,23 @@ parse_params () {
|
||||
color=1
|
||||
shift 1
|
||||
;;
|
||||
-c | --config)
|
||||
--config-file)
|
||||
config_json="$2"
|
||||
shift 2
|
||||
;;
|
||||
--get-config-name)
|
||||
-c | --config)
|
||||
shift 1
|
||||
config_params=${*}
|
||||
config_params="${config_params%% -?[a-z-]*}"
|
||||
config_params="${config_params%% -?[a-z]*}"
|
||||
params=$*
|
||||
set -- $config_params
|
||||
count=$#
|
||||
( test $count -lt 1 || test ${#config_params} -eq 0 ) \
|
||||
&& printf "missing argument: config_name\n" \
|
||||
&& exit 1
|
||||
test $count -ge 1 && config_name="$1"
|
||||
set -- $params
|
||||
shift $count
|
||||
cmd=get-config-name
|
||||
;;
|
||||
--get-config-names)
|
||||
@@ -784,10 +801,14 @@ parse_params () {
|
||||
esac
|
||||
shift
|
||||
;;
|
||||
--c=* | --config=*)
|
||||
--config-file=*)
|
||||
config_json=${1#*=}
|
||||
shift
|
||||
;;
|
||||
-c | --config=*)
|
||||
config_name=${1#*=}
|
||||
shift
|
||||
;;
|
||||
--disk_label_data=*|--DISK_LABEL_DATA=*)
|
||||
disk_label_data=${1#*=}
|
||||
shift
|
||||
@@ -1034,6 +1055,7 @@ show_config () {
|
||||
printf "${BLUE}$progname (runtime arguments) ...${NO_COLOR}\n"
|
||||
i=0
|
||||
printf " Config File: '%s'\n" "$config_json"
|
||||
printf " Config: '%s'\n" "$config_name"
|
||||
printf " Mount Point: '%s'\n" "$mount_point"
|
||||
printf " Label Prefix: '%s'\n" "$label_prefix"
|
||||
printf " Target OS: '%s'\n" "$disk_dev_root"
|
||||
@@ -1061,9 +1083,11 @@ usage () {
|
||||
"$progname $version" \
|
||||
"Usage: $progname [options]" \
|
||||
"Options:" \
|
||||
" -c, --config Read config parameters from given file" \
|
||||
" -c, --config-file Use given given file" \
|
||||
" --config use pre-defined values from given config name" \
|
||||
" --color Enable colored output messages" \
|
||||
" --dry-run perform a trial run (no changes are written)" \
|
||||
" --get-config-names show pre-defined configs from config-file" \
|
||||
" --mountpoint Specify MountPoint preparing targets OS-Disk" \
|
||||
" --label_prefix <prefix> Specify the partion label prefix" \
|
||||
" -t, --disk_dev_root <target> Specify the blockdevice for the target OS (e.g /dev/sda)" \
|
||||
@@ -1088,24 +1112,21 @@ parse_params $@
|
||||
|
||||
# commandline options handled with priority
|
||||
parse_config_file
|
||||
show_config
|
||||
|
||||
printf "${MAGENTA}cmd: ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
||||
|
||||
case $cmd in
|
||||
get-config-name)
|
||||
get_config_name
|
||||
#get_config_name 'HyperV-SingleDisk'
|
||||
get_config_name $config_name
|
||||
if test $? -gt 0; then
|
||||
exit 1
|
||||
else
|
||||
if [ $quiet -eq 0 ]; then
|
||||
printf "${MAGENTA}Config Environment: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
"${config_name}"
|
||||
fi
|
||||
#else
|
||||
# if [ $quiet -eq 0 ]; then
|
||||
# printf "${MAGENTA}Config Environment: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
# "${config_name}"
|
||||
# fi
|
||||
fi
|
||||
;;
|
||||
get-config-names)
|
||||
#echo $config_names
|
||||
get_config_names
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 1
|
||||
@@ -1114,25 +1135,9 @@ case $cmd in
|
||||
printf "${MAGENTA}Config environment names: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
"${config_names}"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
get-config-disk-names)
|
||||
valid_member=0
|
||||
get_config_disk_names "${config_name}" "${disk_name}"
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 1
|
||||
else
|
||||
if [ $quiet = 0 ]; then
|
||||
printf "Config environment ${GREEN}'%s'${NO_COLOR} with disks: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||
"${config_name}" "${disk_names}"
|
||||
fi
|
||||
valid_member=${#disk_names}
|
||||
fi
|
||||
;;
|
||||
get-config-partition_names)
|
||||
echo get_config_partition_names
|
||||
;;
|
||||
|
||||
install-target)
|
||||
prepare_target_disks
|
||||
prepare_target_filesystems
|
||||
@@ -1150,3 +1155,7 @@ case $cmd in
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $quiet -eq 0 ]; then
|
||||
show_config
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user