From 1bf0ccc4fa4d5929bc911c0f9854f45d5f45d9a2 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Thu, 9 Mar 2023 12:23:02 +0100 Subject: [PATCH] create-install-iso: switch config to use a search path --- scripts/create-install-iso.sh | 13 +++++++++---- scripts/create-installimg.sh | 18 +++++++++--------- scripts/lib/misc.sh | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/scripts/create-install-iso.sh b/scripts/create-install-iso.sh index 3897fb2..066e856 100755 --- a/scripts/create-install-iso.sh +++ b/scripts/create-install-iso.sh @@ -9,7 +9,7 @@ topdir=$mydir/.. usage() { cat <] +Usage: $0 [] [:]* Options: -V (mandatory) ISO volume ID @@ -71,12 +71,17 @@ if [ $DOREPO = 0 -a -n "$KEYID" ]; then die_usage "signing key is useless on netinstall media" fi -[ -z "$VERBOSE" ] || set -x - -DIST="$1" +parse_config_search_path "$1" +DIST="$(basename ${CFG_SEARCH_PATH[0]})" INSTALLIMG="$2" OUTISO="$3" +[ -z "$VERBOSE" ] || set -x + +YUMCONF_TMPL=$(find_config yum.conf.tmpl) +YUMREPOSCONF_TMPL=$(find_config yum-repos.conf.tmpl) +PACKAGES_LST=$(find_config packages.lst) +YUMDL_FLAGS=$(find_config yumdl.flags) maybe_set_srcurl "$DIST" test -r "$INSTALLIMG" || die "cannot read '$INSTALLIMG' for install.img" diff --git a/scripts/create-installimg.sh b/scripts/create-installimg.sh index 8439bd7..bd0dc2d 100755 --- a/scripts/create-installimg.sh +++ b/scripts/create-installimg.sh @@ -9,7 +9,7 @@ topdir=$mydir/.. usage() { cat <] +Usage: $0 [] [:]* Options: --srcurl get RPMs from repo at @@ -52,15 +52,15 @@ while [ $# -ge 1 ]; do done [ $# = 1 ] || die_usage "need exactly 1 non-option argument" +parse_config_search_path "$1" +DIST="$(basename ${CFG_SEARCH_PATH[0]})" [ -z "$VERBOSE" ] || set -x -DIST="$1" -confdir="$topdir/configs/$DIST" - -[ -r "$confdir/yum.conf.tmpl" ] || die "cannot find yum config for '$DIST'" -[ -r "$confdir/yum-repos.conf.tmpl" ] || die "cannot find yum-repos config for '$DIST'" -[ -r "$confdir/packages.lst" ] || die "cannot find package list for '$DIST'" +YUMCONF_TMPL=$(find_config yum.conf.tmpl) +YUMREPOSCONF_TMPL=$(find_config yum-repos.conf.tmpl) +PACKAGES_LST=$(find_config packages.lst) +YUMDL_FLAGS=$(find_config yumdl.flags) maybe_set_srcurl "$DIST" [ -n "$OUTPUT_IMG" ] || OUTPUT_IMG="install-$DIST-$RPMARCH.img" @@ -73,7 +73,7 @@ command -v yum >/dev/null || die "required tool not found: yum" # expand template YUMCONF=$(mktemp yum-XXXXXX.conf) CLEANUP_FILES+=("$YUMCONF") -cat "$confdir/yum.conf.tmpl" "$confdir/yum-repos.conf.tmpl" | +cat "$YUMCONF_TMPL" "$YUMREPOSCONF_TMPL" | sed \ -e "s,@@SRCURL@@,$SRCURL," \ -e "s,@@RPMARCH@@,$RPMARCH," \ @@ -91,7 +91,7 @@ YUM=( $([ -n "$VERBOSE" ] || printf -- "-q") ) -xargs < "$confdir/packages.lst" \ +xargs < "$PACKAGES_LST" \ ${YUM[@]} install \ --assumeyes \ --noplugins diff --git a/scripts/lib/misc.sh b/scripts/lib/misc.sh index 91c2ace..aa05b0e 100644 --- a/scripts/lib/misc.sh +++ b/scripts/lib/misc.sh @@ -15,6 +15,36 @@ die_usage() { } +# populates CFG_SEARCH_PATH array +parse_config_search_path() { + local pathstr="$1" + CFG_SEARCH_PATH=() + while true; do + local dir=${pathstr%%:*} + local absdir + case "$dir" in + /*) absdir="$dir" ;; + *) absdir=$(realpath "$topdir/configs/$dir") ;; + esac + [ -d "$absdir" ] || die "directory not found: $absdir" + CFG_SEARCH_PATH+=("$absdir") + [ "$pathstr" != "$dir" ] || break # was last component in search path + pathstr=${pathstr#${dir}:} # strip this dir and loop + done +} + +find_config() { + local filename="$1" + for dir in "${CFG_SEARCH_PATH[@]}"; do + try="$dir/$filename" + if [ -r "$try" ]; then + echo "$try" + return + fi + done + die "cannot find '$filename' in ${CFG_SEARCH_PATH[*]}" +} + # default src URL depending on selected $DIST maybe_set_srcurl() { @@ -98,8 +128,7 @@ setup_yum_download() { enable_plugins=0 fi - confdir="$topdir/configs/$DIST" - cat "$confdir/yumdl.conf.tmpl" "$confdir/yum-repos.conf.tmpl" | + cat "$YUMCONF_TMPL" "$YUMREPOSCONF_TMPL" | sed \ -e "s,@@SRCURL@@,$SRCURL," \ -e "s,@@RPMARCH@@,$RPMARCH," \ @@ -113,7 +142,7 @@ setup_yum_download() { --disablerepo="*" --installroot="$DUMMYROOT" ) - . "$confdir/yumdl.flags" + . "$YUMDL_FLAGS" } get_rpms() {