aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/install-redhat.sh
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-02-05 12:51:44 +0100
committerGerd Hoffmann <kraxel@redhat.com>2017-02-05 12:51:44 +0100
commit885a7d55c67bb3504918229018523406a4822d09 (patch)
tree83c8c95597bfa46ba2413a8dcd5f53f30c885814 /scripts/install-redhat.sh
downloadimagefish-885a7d55c67bb3504918229018523406a4822d09.tar.gz
initial commit
Diffstat (limited to 'scripts/install-redhat.sh')
-rwxr-xr-xscripts/install-redhat.sh147
1 files changed, 147 insertions, 0 deletions
diff --git a/scripts/install-redhat.sh b/scripts/install-redhat.sh
new file mode 100755
index 0000000..d635445
--- /dev/null
+++ b/scripts/install-redhat.sh
@@ -0,0 +1,147 @@
+#!/bin/sh
+
+######################################################################
+# defaults
+
+dest=""
+tarb=""
+tool="dnf"
+grps="core"
+rpms=""
+conf=""
+
+######################################################################
+# create work dir
+
+WORK="${TMPDIR-/var/tmp}/${0##*/}-$$"
+mkdir "$WORK" || exit 1
+trap 'sudo rm -rf "$WORK"' EXIT
+
+######################################################################
+# parse args
+
+function print_help() {
+cat <<EOF
+usage: $0 [ options ]
+options:
+ what to create (one must be specified)
+ --tar <tarball>
+ --dest <dir>
+ what to install
+ --groups <groups> (default: $grps)
+ --packages <rpms>
+ package manager setup
+ --config <repos>
+ --dnf (default)
+ --yum
+EOF
+}
+
+while test "$1" != ""; do
+ case "$1" in
+ -d | --dest)
+ dest="$2"
+ shift; shift
+ ;;
+ -t | --tar | --tarball)
+ tarb="$2"
+ dest="$WORK/install"
+ shift; shift
+ ;;
+ -g | --groups)
+ grps="$2"
+ shift; shift
+ ;;
+ -p | --packages)
+ rpms="$2"
+ shift; shift
+ ;;
+ -c | --config)
+ conf="$2"
+ shift; shift
+ ;;
+ --dnf)
+ tool="dnf"
+ shift
+ ;;
+ --yum)
+ tool="yum"
+ shift
+ ;;
+ -h | --help)
+ print_help
+ exit 1
+ ;;
+ *) echo "ERROR: unknown arg: $1 (try --help)"
+ exit 1
+ ;;
+ esac
+done
+
+######################################################################
+# sanity checks
+
+if test "$dest" = ""; then
+ echo "ERROR: no dest given"
+ exit 1
+fi
+if test -d "$dest"; then
+ echo "ERROR: directory exists: $dest"
+ exit 1
+fi
+if test "$conf" != "" -a ! -f "$conf"; then
+ echo "ERROR: not found: $conf"
+ exit 1
+fi
+if test "$tarb" != "" -a -f "$tarb"; then
+ echo "ERROR: tarball exists: $tarb"
+ exit 1
+fi
+
+######################################################################
+# go!
+
+case "$tool" in
+dnf)
+ tool="$tool -y --quiet --installroot ${dest}"
+ if test "$conf" != ""; then
+ tool="$tool --config ${conf}"
+ tool="$tool --disablerepo=*"
+ tool="$tool --enablerepo=mkimage-*"
+ fi
+ ;;
+yum)
+ tool="$tool -y --installroot ${dest}"
+ if test "$conf" != ""; then
+ tool="$tool --config ${conf}"
+ fi
+ ;;
+*)
+ # should not happen
+ echo "Oops"
+ exit 1
+ ;;
+esac
+
+inst=""
+for item in $grps; do inst="${inst} @${item}"; done
+for item in $rpms; do inst="${inst} ${item}"; done
+echo "### dnf install to $dest ..."
+(set -x; sudo $tool install $inst) || exit 1
+sudo rm -rf "${dest}/var/cache/dnf"
+
+if test "$tarb" != ""; then
+ case "$tarb" in
+ *.gz) topt="--gzip"
+ ;;
+ *.xz) topt="--xz"
+ ;;
+ *) topt=""
+ ;;
+ esac
+ echo "### create tarball ..."
+ (cd $dest; sudo tar --create $topt .) > "$tarb"
+fi
+
+echo "### done, cleanup ..."
+