This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathChrootBuild.sh
executable file
·180 lines (165 loc) · 3.93 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
#!/bin/bash
#
# Install minimal RPM-set into chroot
#
#####################################
PROGNAME=$(basename "$0")
CHROOT="${CHROOT:-/mnt/ec2-root}"
CONFROOT=$(dirname $0)
REPORFILEPMS=($(rpm --qf '%{name}\n' -qf /etc/yum.repos.d/* 2>&1 | \
grep -v "not owned" | sort -u))
if [[ $(rpm --quiet -q redhat-release-server)$? -eq 0 ]]
then
OSREPOS=(
rhui-REGION-client-config-server-6
rhui-REGION-rhel-server-releases
rhui-REGION-rhel-server-rh-common
)
elif [[ $(rpm --quiet -q centos-release)$? -eq 0 ]]
then
OSREPOS=(
base
updates
extras
)
fi
DEFAULTREPOS=$(IFS=,; echo "${OSREPOS[*]}")
YCM="/usr/bin/yum-config-manager"
function PrepChroot() {
if [[ ! -e ${CHROOT}/etc/init.d ]]
then
ln -t ${CHROOT}/etc -s rc.d/init.d
fi
# Enable DNS resolution in the chroot
if [[ ! -e ${CHROOT}/etc/resolv.conf ]]
then
install -m 0644 /etc/resolv.conf "${CHROOT}/etc"
fi
yumdownloader --destdir=/tmp $(rpm --qf '%{name}\n' -qf /etc/redhat-release)
yumdownloader --destdir=/tmp "${REPORFILEPMS[@]}"
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 "${REPORFILEPMS[@]}"
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}"
YUMCMD="yum --nogpgcheck --installroot=${CHROOT} ${ENABREPO} install -y"
else
YUMCMD="yum --nogpgcheck --installroot=${CHROOT} install -y"
fi
# Activate repos in the chroot...
chroot "$CHROOT" "${YCM}" --disable "*"
chroot "$CHROOT" "${YCM}" --enable "${BONUSREPO}"
# Install main RPM-groups
${YUMCMD} @Core -- \
"${REPORFILEPMS[@]}" \
authconfig \
cloud-init \
kernel \
lvm2 \
man \
ntp \
ntpdate \
openssh-clients \
selinux-policy \
wget \
yum-cron \
yum-utils \
-abrt \
-abrt-addon-ccpp \
-abrt-addon-kerneloops \
-abrt-addon-python \
-abrt-cli \
-abrt-libs \
-gcc-gfortran \
-libvirt-client \
-libvirt-devel \
-libvirt-java \
-libvirt-java-devel \
-nc \
-sendmail
# Install additionally-requested RPMs
if [[ ! -z ${EXTRARPMS+xxx} ]]
then
printf "##########\n## Installing requested RPMs/groups\n##########\n"
${YUMCMD} "${EXTRARPMS[@]}"
else
echo "No 'extra' RPMs requested"
fi