3 # vim: ts=4 sw=4 sts=4 et tw=72 :
5 # force any errors to cause the script and job to end in failure
9 # Handle the occurance where SELINUX is actually disabled
10 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
11 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
14 echo "************************************"
15 echo "** SYSTEM ENTERING ENFORCING MODE **"
16 echo "************************************"
17 # make sure that the filesystem is properly labelled.
18 # it could be not fully labeled correctly if it was just switched
19 # from disabled, the autorelabel misses some things
20 # skip relabelling on /dev as it will generally throw errors
21 restorecon -R -e /dev /
23 # enable enforcing mode from the very start
26 # configure system for enforcing mode on next boot
27 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
30 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
33 echo "*******************************************"
34 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
35 echo "*******************************************"
38 echo "*********************************"
39 echo "** SYSTEM IS IN ENFORCING MODE **"
40 echo "*********************************"
44 echo "---> Updating operating system"
46 yum install -y deltarpm
49 # add in components we need or want on systems
50 echo "---> Installing base packages"
51 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
52 # separate group installs from package installs since a non-existing
53 # group with dnf based systems (F21+) will fail the install if such
54 # a group does not exist
55 yum install -y unzip xz puppet git git-review perl-XML-XPath wget make
57 # All of our systems require Java (because of Jenkins)
58 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
61 echo "---> Configuring OpenJDK"
62 yum install -y 'java-*-openjdk-devel'
64 FACTER_OS=$(/usr/bin/facter operatingsystem)
65 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
68 if [ "$FACTER_OSVER" -ge "21" ]
70 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
72 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
73 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
77 if [ "$(echo $FACTER_OSVER | cut -d'.' -f1)" -ge "7" ]
79 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
81 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
82 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
86 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
87 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
91 # Needed to parse OpenStack commands used by infra stack commands
92 # to initialize Heat template based systems.
97 # Ignore SELinux since slamming that onto Ubuntu leads to
100 export DEBIAN_FRONTEND=noninteractive
101 cat <<EOF >> /etc/apt/apt.conf
105 allow-change-held-packages "true";
106 allow-downgrades "true";
107 allow-remove-essential "true";
118 # Wrap apt-get to wait for the lock to become available for operation
119 # http://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running
120 cat << 'EOF' >> /usr/local/bin/apt-get
125 LOCKFILES="/var/lib/dpkg/lock /var/lib/apt/lists/lock"
127 while [ fuser ${LOCKFILES} >/dev/null 2>&1 ]; do
136 echo -en "\r[$j] Waiting for other software managers to finish..."
143 /usr/bin/apt-get "$@"
145 exec /usr/local/bin/apt-get "$@"
149 chmod +x /usr/local/bin/apt-get
151 echo "---> Updating operating system"
155 # add in stuff we know we need
156 echo "---> Installing base packages"
157 apt-get install unzip xz-utils puppet git git-review libxml-xpath-perl make wget
160 echo "---> Configuring OpenJDK"
161 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
162 case "$FACTER_OSVER" in
164 apt-get install openjdk-7-jdk
165 # make jdk8 available
166 add-apt-repository -y ppa:openjdk-r/ppa
168 # We need to force openjdk-8-jdk to install
169 apt-get install openjdk-8-jdk
170 # make sure that we still default to openjdk 7
171 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
172 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
174 # disable auto-update service?
175 if [ -f /etc/cron.daily/apt ]
177 rm -rf /etc/cron.daily/apt
181 apt-get install openjdk-8-jdk
183 # force auto-update services off and mask them so they can't
185 for i in apt-daily.{service,timer}
187 systemctl disable ${i}
192 echo "---> Unknown Ubuntu version $FACTER_OSVER"
199 # Needed to parse OpenStack commands used by infra stack commands
200 # to initialize Heat template based systems.
203 # disable unattended upgrades & daily updates
204 echo '---> Disabling automatic daily upgrades'
205 grep -lR 'APT::Periodic' /etc/apt/apt.conf.d/ | perl -pi -e 's/"1"/"0"/g'
210 # Allow jenkins access to update-alternatives command to switch java version
211 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
212 Defaults:jenkins !requiretty
213 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
217 puppet module install thias-sysctl --version 1.0.6
218 puppet apply -e "sysctl {'vm.nr_hugepages': value => '128'}"
219 puppet apply -e "file { '/mnt/huge': ensure => directory }"
220 puppet apply -e "mount { '/mnt/huge': ensure => mounted, atboot => true, \
221 device => 'none', fstype => 'hugetlbfs', options => 'mode=01777' }"
223 # Do any Distro specific installations here
224 echo "Checking distribution"
225 FACTER_OS=$(/usr/bin/facter operatingsystem)
228 echo "---> $FACTER_OS found"
229 echo "No extra steps for $FACTER_OS"
234 echo "---> Attempting to detect OS"
235 # upstream cloud images use the distro name as the initial user
236 ORIGIN=$(if [ -e /etc/redhat-release ]
245 fedora|centos|redhat)
246 echo "---> RH type system detected"
250 echo "---> Ubuntu system detected"
254 echo "---> Unknown operating system"
258 # execute steps for all systems