aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/install-redhat.sh
blob: 7b6c6b2a277505095f52ee1bb0812d2f4ef2afe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/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
	# with this yum uses the (empty) installroot repos dir,
	# so we don't have to hop through enablerepo/disablerepo
	# loops to disable the host repos
	mkdir -p ${dest}/etc/yum.repos.d
	;;
*)
	# should not happen
	echo "Oops"
	exit 1
	;;
esac

mkdir -p ${dest}/{dev,proc,sys,mnt}
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,yum}

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 ..."