forked from plus3it/amigen7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChrootBuild.sh
executable file
·248 lines (231 loc) · 5.63 KB
/
ChrootBuild.sh
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
# shellcheck disable=SC2005,SC2001,SC2181
#
# Install minimal RPM-set into chroot
#
#####################################
PROGNAME=$(basename "$0")
CHROOT="${CHROOT:-/mnt/ec2-root}"
if [[ $(rpm --quiet -q redhat-release-server)$? -eq 0 ]]
then
OSREPOS=(
rhui-REGION-client-config-server-7
rhui-REGION-rhel-server-releases
rhui-REGION-rhel-server-rh-common
rhui-REGION-rhel-server-optional
rhui-REGION-rhel-server-extras
)
elif [[ $(rpm --quiet -q centos-release)$? -eq 0 ]]
then
OSREPOS=(
os
base
updates
extras
)
fi
DEFAULTREPOS=$(printf ",%s" "${OSREPOS[@]}" | sed 's/^,//')
FIPSDISABLE="${FIPSDISABLE:-UNDEF}"
YCM="/bin/yum-config-manager"
function PrepChroot() {
local REPOPKGS=($(echo \
"$(rpm --qf '%{name}\n' -qf /etc/redhat-release)" ; \
echo "$(rpm --qf '%{name}\n' -qf \
/etc/yum.repos.d/* 2>&1 | \
grep -v "not owned" | sort -u)" ; \
echo yum-utils
))
# Enable DNS resolution in the chroot
if [[ ! -e ${CHROOT}/etc/resolv.conf ]]
then
install -m 0644 /etc/resolv.conf "${CHROOT}/etc"
fi
# Do this so that install of chkconfig RPM succeeds
if [[ ! -e ${CHROOT}/etc/init.d ]]
then
ln -t "${CHROOT}/etc" -s ./rc.d/init.d
fi
if [[ ! -e ${CHROOT}/etc/rc.d/init.d ]]
then
install -d -m 0755 "${CHROOT}/etc/rc.d/init.d"
fi
yumdownloader --destdir=/tmp "${REPOPKGS[@]}"
rpm --root "${CHROOT}" --initdb
rpm --root "${CHROOT}" -ivh --nodeps /tmp/*.rpm
# When we don't specify repos, default to a sensible value-list
if [[ -z ${BONUSREPO+xxx} ]]
then
BONUSREPO=${DEFAULTREPOS}
fi
yum --disablerepo="*" --enablerepo="${BONUSREPO}" \
--installroot="${CHROOT}" -y reinstall "${REPOPKGS[@]}"
yum --disablerepo="*" --enablerepo="${BONUSREPO}" \
--installroot="${CHROOT}" -y install yum-utils
# if alt-repo defined, disable everything, then install alt-repos
if [[ ! -z ${REPORPMS+xxx} ]]
then
for RPM in "${REPORPMS[@]}"
do
rpm --root "${CHROOT}" -ivh --nodeps "${RPM}"
done
fi
}
######################
## Main program flow
######################
# See if we'e passed any valid flags
OPTIONBUFR=$(getopt -o r:b:e: --long repouri:bonusrepos:extras: -n "${PROGNAME}" -- "$@")
eval set -- "${OPTIONBUFR}"
while true
do
case "$1" in
-r|--repouri)
case "$2" in
"")
echo "Error: option required but not specified" > /dev/stderr
shift 2;
exit 1
;;
*)
REPORPMS=($(echo "${2}" | sed 's/,/ /g'))
shift 2;
;;
esac
;;
-b|--bonusrepos)
case "$2" in
"")
echo "Error: option required but not specified" > /dev/stderr
shift 2;
exit 1
;;
*)
BONUSREPO=${2}
shift 2;
;;
esac
;;
-e|--extras)
case "$2" in
"")
echo "Error: option required but not specified" > /dev/stderr
shift 2;
exit 1
;;
*)
EXTRARPMS=($(echo "${2}" | sed 's/,/ /g'))
shift 2;
;;
esac
;;
--)
shift
break
;;
*)
echo "Internal error!" > /dev/stderr
exit 1
;;
esac
done
# Stage useable repo-defs into $CHROOT/etc/yum.repos.d
PrepChroot
if [[ ! -z ${BONUSREPO+xxx} ]]
then
ENABREPO=--enablerepo=${BONUSREPO}
# shellcheck disable=SC2125
YUMDO="yum --nogpgcheck --installroot=${CHROOT} --disablerepo="*" ${ENABREPO} install -y"
else
YUMDO="yum --nogpgcheck --installroot=${CHROOT} install -y"
fi
# Activate repos in the chroot...
chroot "$CHROOT" "${YCM}" --disable "*"
chroot "$CHROOT" "${YCM}" --enable "${BONUSREPO}"
# Whether to include FIPS kernel modules...
case "${FIPSDISABLE}" in
true|TRUE|1|on)
FIPSRPM=''
;;
UNDEF|''|false|FALSE|0)
FIPSRPM='dracut-fips'
;;
esac
# Install main RPM-groups
${YUMDO} @core -- \
"$(rpm --qf '%{name}\n' -qf /etc/yum.repos.d/* 2>&1 | grep -v "not owned" | sort -u)" \
authconfig \
chrony \
cloud-init \
cloud-utils-growpart \
dracut-config-generic \
"${FIPSRPM}" \
dracut-norescue \
gdisk \
grub2 \
grub2-tools \
iptables-services \
iptables-utils \
kernel \
kexec-tools \
lvm2 \
ntp \
ntpdate \
openssh-clients \
openssh-server \
rootfiles \
rsync \
selinux-policy-targeted \
sudo \
tar \
vim-common \
wget \
yum-utils \
-abrt \
-abrt-addon-ccpp \
-abrt-addon-kerneloops \
-abrt-addon-python \
-abrt-cli \
-abrt-libs \
-aic94xx-firmware \
-alsa-firmware \
-alsa-lib \
-alsa-tools-firmware \
-biosdevname \
-gcc-gfortran \
-iprutils \
-ivtv-firmware \
-iwl1000-firmware \
-iwl100-firmware \
-iwl105-firmware \
-iwl135-firmware \
-iwl2000-firmware \
-iwl2030-firmware \
-iwl3160-firmware \
-iwl3945-firmware \
-iwl4965-firmware \
-iwl5000-firmware \
-iwl5150-firmware \
-iwl6000-firmware \
-iwl6000g2a-firmware \
-iwl6000g2b-firmware \
-iwl6050-firmware \
-iwl7260-firmware \
-libertas-sd8686-firmware \
-libertas-sd8787-firmware \
-libertas-usb8388-firmware \
-libvirt-client \
-libvirt-devel \
-libvirt-java \
-libvirt-java-devel \
-nc \
-NetworkManager \
-plymouth \
-sendmail
# Install additionally-requested RPMs
if [[ ! -z ${EXTRARPMS+xxx} ]]
then
printf "##########\n## Installing requested RPMs/groups\n##########\n"
${YUMDO} "${EXTRARPMS[@]}"
else
echo "No 'extra' RPMs requested"
fi