-
Notifications
You must be signed in to change notification settings - Fork 1
/
redhat.logic
185 lines (182 loc) · 5.4 KB
/
redhat.logic
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
#
set -e
#
LYNX=$(which lynx)
RPM=$(which rpm)
YUM=$(which yum)
#
if [ ${ARCH} = amd64 ]; then
ARCH=x86_64
fi
#
if [ ${ARCH} = i386 ]; then
cmdPREFIX="setarch ${ARCH}"
fi
#
MIRROR=http://jenkins.percona.com/yum-repo/rhel8/BaseOS/
IMAGE_NEEDS="git openssh openssh-server openssh-clients audit"
#
createTempYumConf(){
echo "[main]
reposdir=${MOUNTDIR}/etc/yum.repos.d
exactarch=0
obsoletes=1
debuglevel=2
gpgcheck=0
" > /tmp/yum.conf
}
#
createImageYumConf(){
mkdir -p ${MOUNTDIR}/etc/yum
echo "[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
" > ${MOUNTDIR}/etc/yum/yum.conf
}
#
installBaseSystem(){
echo "* Installing RedHat-${RELEASE}-${ARCH} system to ${MOUNTDIR}"
mkdir -p ${MOUNTDIR}/var/lib/rpm
${RPM} --rebuilddb --root=${MOUNTDIR}
REDHAT_RELEASE_RPM=$(lynx --dump ${MIRROR}/Packages | egrep -o "http.*redhat-release-.*rpm")
wget ${REDHAT_RELEASE_RPM} -O ${MOUNTDIR}/redhat-release-${RELEASE}.rpm
${RPM} -i --root=${MOUNTDIR} --nodeps ${MOUNTDIR}/redhat-release-${RELEASE}.rpm
mkdir -p ${MOUNTDIR}/etc/yum.repos.d
wget https://jenkins.percona.com/yum-repo/rhel8/rhel8-beta.repo -O ${MOUNTDIR}/etc/yum.repos.d/rhel8-beta.repo
mkdir -p /etc/pki/rpm-gpg
cp -av ${MOUNTDIR}/etc/pki/rpm-gpg/* /etc/pki/rpm-gpg
createTempYumConf
createImageYumConf
${cmdPREFIX} ${YUM} -y --config=/tmp/yum.conf --installroot=${MOUNTDIR} install rpm yum
chroot ${MOUNTDIR} rpm -i --force --nodeps /redhat-release-${RELEASE}.rpm
rm -fv /tmp/yum.conf ${MOUNTDIR}/redhat-release-${RELEASE}.rpm
echo 'nameserver 10.30.6.240' > ${MOUNTDIR}/etc/resolv.conf
${cmdPREFIX} chroot ${MOUNTDIR} yum -y groupinstall "Minimal Install"
}
#
configureFSTab(){
# Setup fstab
echo "# /etc/fstab: static file system information.
UUID=${UUID} / ext4 noatime 1 1
" > ${MOUNTDIR}/etc/fstab
}
#
setLocale(){
echo "setLocale()"
}
#
createRepositories(){
#install EPEL repo
echo "createRepositories()"
}
#
upgradeSystem(){
${cmdPREFIX} chroot ${MOUNTDIR} yum -y install dhclient sudo cloud-init cloud-utils-growpart kernel syslinux-extlinux network-scripts
${cmdPREFIX} chroot ${MOUNTDIR} yum -y install selinux-policy selinux-policy-targeted acpid
${cmdPREFIX} chroot ${MOUNTDIR} yum -y install ${IMAGE_NEEDS}
${cmdPREFIX} chroot ${MOUNTDIR} yum -y upgrade
${cmdPREFIX} chroot ${MOUNTDIR} sed -i 's:SELINUX=enforcing:SELINUX=permissive:g' /etc/selinux/config
${cmdPREFIX} chroot ${MOUNTDIR} systemctl disable firewalld
}
#
adjustCloudSettings(){
#Allow SSH in as root, even though it might be unsecure
sed -i 's/disable_root: true/disable_root: false/' ${MOUNTDIR}/etc/cloud/cloud.cfg
sed -i "s/name: cloud-user/name: ${CLOUD_USER}/" ${MOUNTDIR}/etc/cloud/cloud.cfg
#Since we implemented backdoor we want to be able to use it :)
sed -i 's/PermitRootLogin yes/PermitRootLogin without-password/' ${MOUNTDIR}/etc/ssh/sshd_config
# copy SKEL to root userdir
cp -v ${MOUNTDIR}/etc/skel/.b* ${MOUNTDIR}/root/
#set timezone
cp ${MOUNTDIR}/usr/share/zoneinfo/America/New_York ${MOUNTDIR}/etc/localtime
}
#
configureBoot(){
KERNEL=$(chroot ${MOUNTDIR} find boot -name 'vmlinuz-*' | sort | tail -n 1)
RAMDISK=$(chroot ${MOUNTDIR} find boot -name 'initramfs-*.img' | sort | tail -n 1)
kVERSION=$(echo ${RAMDISK%.img} | awk -F'-' '{print $2"-"$3}')
mkdir -p ${MOUNTDIR}/boot/extlinux
echo "default linux
timeout 10
label linux
kernel /${KERNEL}
append initrd=/${RAMDISK} root=UUID=${UUID} rootfstype=ext4 console=tty0 console=ttyS0,115200 net.ifnames=0" > ${MOUNTDIR}/boot/extlinux/extlinux.conf
#
extlinux --install ${MOUNTDIR}/boot/extlinux
#
${cmdPREFIX} chroot ${MOUNTDIR} dracut --add-drivers "virtio_crypto virtio_net virtio_scsi virtio_blk virtio-gpu virtio_input virtio_balloon virtio_console" -v -f /boot/initramfs-${kVERSION}.img ${kVERSION}
}
#
configureNetwork(){
echo "
DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=dhcp
ONBOOT=yes
" > ${MOUNTDIR}/etc/sysconfig/network-scripts/ifcfg-eth0
}
#
cleanupSystem(){
echo "* removing SSH keys ..."
rm -f ${MOUNTDIR}/etc/ssh/ssh_host_*
echo "* removing UDEV persistent net rules ..."
rm -f ${MOUNTDIR}/etc/udev/rules.d/*-persistent-net.rules
rm -f ${MOUNTDIR}/lib*/udev/write_net_rules
echo "* cleaning downloaded YUM data and packages ..."
${cmdPREFIX} chroot ${MOUNTDIR} yum clean all
echo "/sbin/fixfiles -F restore" ${MOUNTDIR}/etc/rc.d/rc.local
if [ ${RELEASE} -gt 6 ]; then
rm -fr ${MOUNTDIR}/var/run
fi
rm -f /etc/yum.repos.d/rhel8-beta.repo
}
#
setupConsole(){
echo "Setting up console params ..."
}
#
configureModules(){
echo "#
blacklist i8xx_tco
blacklist aty128fb
blacklist atyfb
blacklist radeonfb
blacklist i810fb
blacklist cirrusfb
blacklist intelfb
blacklist kyrofb
blacklist i2c-matroxfb
blacklist hgafb
blacklist nvidiafb
blacklist rivafb
blacklist savagefb
blacklist sstfb
blacklist neofb
blacklist tridentfb
blacklist tdfxfb
blacklist virgefb
blacklist vga16fb
blacklist viafb
blacklist hisax
blacklist hisax_fcpcipnp
blacklist snd-pcsp
blacklist chsc_sch
" > ${MOUNTDIR}/etc/modprobe.d/blacklist.conf
#
echo "# Required for cinder hotplug
acpiphp
pci_hotplug
" >> ${MOUNTDIR}/etc/modules
}
#
setHostname(){
echo "NETWORKING=yes" > ${MOUNTDIR}/etc/sysconfig/network
echo "HOSTNAME=${DISTRO}.${RELEASE}.openstack" >> ${MOUNTDIR}/etc/sysconfig/network
}
#
createCloudUser(){
echo "* adding cloud user ${CLOUD_USER} ..."
${cmdPREFIX} chroot ${MOUNTDIR} adduser --create-home --shell /bin/bash --user-group --comment ${DISTRO}-cloud-user ${CLOUD_USER}
}
#