Skip to content

Commit

Permalink
create-install-iso: switch config to use a search path
Browse files Browse the repository at this point in the history
  • Loading branch information
ydirson committed Apr 18, 2023
1 parent 03ce297 commit 1bf0ccc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
13 changes: 9 additions & 4 deletions scripts/create-install-iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topdir=$mydir/..

usage() {
cat <<EOF
Usage: $0 [<options>] <dist> <install.img> <output-iso>
Usage: $0 [<options>] <base-config>[:<config-overlay>]* <install.img> <output-iso>
Options:
-V <VOLID> (mandatory) ISO volume ID
Expand Down Expand Up @@ -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"

Expand Down
18 changes: 9 additions & 9 deletions scripts/create-installimg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topdir=$mydir/..

usage() {
cat <<EOF
Usage: $0 [<options>] <dist>
Usage: $0 [<options>] <base-config>[:<config-overlay>]*
Options:
--srcurl <URL> get RPMs from repo at <URL>
Expand Down Expand Up @@ -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"

Expand All @@ -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," \
Expand All @@ -91,7 +91,7 @@ YUM=(
$([ -n "$VERBOSE" ] || printf -- "-q")
)

xargs < "$confdir/packages.lst" \
xargs < "$PACKAGES_LST" \
${YUM[@]} install \
--assumeyes \
--noplugins
Expand Down
35 changes: 32 additions & 3 deletions scripts/lib/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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," \
Expand All @@ -113,7 +142,7 @@ setup_yum_download() {
--disablerepo="*"
--installroot="$DUMMYROOT"
)
. "$confdir/yumdl.flags"
. "$YUMDL_FLAGS"
}

get_rpms() {
Expand Down

0 comments on commit 1bf0ccc

Please sign in to comment.