blob: 99e7460cf6733b13c93197488c7b5a037872c353 [file] [log] [blame]
Andrew Grimbergebc710a2017-01-30 12:59:38 -08001#!/bin/bash
2
3# vim: ts=4 sw=4 sts=4 et tw=72 :
4
Andrew Grimberg8ffb2132017-02-07 10:48:06 -08005# force any errors to cause the script and job to end in failure
Andrew Grimberg7fb50b32017-02-07 10:54:58 -08006set -xeu -o pipefail
Andrew Grimberg8ffb2132017-02-07 10:48:06 -08007
Andrew Grimbergebc710a2017-01-30 12:59:38 -08008rh_systems() {
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 '=')
12 case "$MODE" in
13 permissive)
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 /
22
23 # enable enforcing mode from the very start
24 setenforce enforcing
25
26 # configure system for enforcing mode on next boot
27 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
28 ;;
29 disabled)
30 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
31 touch /.autorelabel
32
33 echo "*******************************************"
34 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
35 echo "*******************************************"
36 ;;
37 enforcing)
38 echo "*********************************"
39 echo "** SYSTEM IS IN ENFORCING MODE **"
40 echo "*********************************"
41 ;;
42 esac
43
44 echo "---> Updating operating system"
Andrew Grimberg8ffb2132017-02-07 10:48:06 -080045 yum clean all
46 yum install -y deltarpm
47 yum update -y
Andrew Grimbergebc710a2017-01-30 12:59:38 -080048
49 # add in components we need or want on systems
50 echo "---> Installing base packages"
Andrew Grimberg8ffb2132017-02-07 10:48:06 -080051 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Andrew Grimbergebc710a2017-01-30 12:59:38 -080052 # 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
Andrew Grimberg8ffb2132017-02-07 10:48:06 -080055 yum install -y unzip xz puppet git git-review perl-XML-XPath wget make
Andrew Grimbergebc710a2017-01-30 12:59:38 -080056
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
59 # default
60
61 echo "---> Configuring OpenJDK"
Andrew Grimberg8ffb2132017-02-07 10:48:06 -080062 yum install -y 'java-*-openjdk-devel'
Andrew Grimbergebc710a2017-01-30 12:59:38 -080063
64 FACTER_OS=$(/usr/bin/facter operatingsystem)
65 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
66 case "$FACTER_OS" in
67 Fedora)
68 if [ "$FACTER_OSVER" -ge "21" ]
69 then
70 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
71 else
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
74 fi
75 ;;
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -080076 RedHat|CentOS)
Andrew Grimberg8ffb2132017-02-07 10:48:06 -080077 if [ "$(echo $FACTER_OSVER | cut -d'.' -f1)" -ge "7" ]
78 then
79 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
80 else
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
83 fi
84 ;;
Andrew Grimbergebc710a2017-01-30 12:59:38 -080085 *)
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
88 ;;
89 esac
90
91 # Needed to parse OpenStack commands used by infra stack commands
92 # to initialize Heat template based systems.
93 yum install -y jq
94}
95
96ubuntu_systems() {
97 # Ignore SELinux since slamming that onto Ubuntu leads to
98 # frustration
99
100 export DEBIAN_FRONTEND=noninteractive
101 cat <<EOF >> /etc/apt/apt.conf
102APT {
103 Get {
104 Assume-Yes "true";
105 allow-change-held-packages "true";
106 allow-downgrades "true";
107 allow-remove-essential "true";
108 };
109};
110
111Dpkg::Options {
112 "--force-confdef";
113 "--force-confold";
114};
115
116EOF
117
Andrew Grimberg3d868632017-02-15 07:02:53 -0800118 # 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
121#!/bin/bash
122
123i=0
124tput sc
125while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
126 case $(($i % 4)) in
127 0 ) j="-" ;;
128 1 ) j="\\" ;;
129 2 ) j="|" ;;
130 3 ) j="/" ;;
131 esac
132 tput rc
133 echo -en "\r[$j] Waiting for other software managers to finish..."
134 sleep 0.5
135 ((i=i+1))
136done
137
138/usr/bin/apt-get "$@"
139
140EOF
141 chmod +x /usr/local/bin/apt-get
142
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800143 echo "---> Updating operating system"
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800144 apt-get update
145 apt-get upgrade
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800146
147 # add in stuff we know we need
148 echo "---> Installing base packages"
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800149 apt-get install unzip xz-utils puppet git git-review libxml-xpath-perl make wget
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800150
151 # install Java 7
152 echo "---> Configuring OpenJDK"
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800153 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
154 case "$FACTER_OSVER" in
155 14.04)
156 apt-get install openjdk-7-jdk
157 # make jdk8 available
158 add-apt-repository -y ppa:openjdk-r/ppa
159 apt-get update
160 # We need to force openjdk-8-jdk to install
161 apt-get install openjdk-8-jdk
162 # make sure that we still default to openjdk 7
163 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
164 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
Andrew Grimberg3d868632017-02-15 07:02:53 -0800165
166 # disable auto-update service?
167 if [ -f /etc/cron.daily/apt ]
168 then
169 rm -rf /etc/cron.daily/apt
170 fi
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800171 ;;
172 16.04)
173 apt-get install openjdk-8-jdk
Andrew Grimberg3d868632017-02-15 07:02:53 -0800174
175 # force auto-update services off and mask them so they can't
176 # be started
177 for i in apt-daily.{service,timer}
178 do
179 systemctl disable ${i}
180 systemctl mask ${i}
181 done
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800182 ;;
183 *)
184 echo "---> Unknown Ubuntu version $FACTER_OSVER"
185 exit 1
186 ;;
187 esac
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800188
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800189
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800190
191 # Needed to parse OpenStack commands used by infra stack commands
192 # to initialize Heat template based systems.
Andrew Grimberg5c9ca7a2017-02-07 11:09:40 -0800193 apt-get install jq
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800194
195 # disable unattended upgrades & daily updates
196 echo '---> Disabling automatic daily upgrades'
Andrew Grimberg3d868632017-02-15 07:02:53 -0800197 grep -lR 'APT::Periodic' /etc/apt/apt.conf.d/ | perl -pi -e 's/"1"/"0"/g'
198
Andrew Grimbergebc710a2017-01-30 12:59:38 -0800199}
200
201all_systems() {
202 # Allow jenkins access to update-alternatives command to switch java version
203 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
204Defaults:jenkins !requiretty
205jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
206EOF
207
208 # Do any Distro specific installations here
209 echo "Checking distribution"
210 FACTER_OS=$(/usr/bin/facter operatingsystem)
211 case "$FACTER_OS" in
212 *)
213 echo "---> $FACTER_OS found"
214 echo "No extra steps for $FACTER_OS"
215 ;;
216 esac
217}
218
219echo "---> Attempting to detect OS"
220# upstream cloud images use the distro name as the initial user
221ORIGIN=$(if [ -e /etc/redhat-release ]
222 then
223 echo redhat
224 else
225 echo ubuntu
226 fi)
227#ORIGIN=$(logname)
228
229case "${ORIGIN}" in
230 fedora|centos|redhat)
231 echo "---> RH type system detected"
232 rh_systems
233 ;;
234 ubuntu)
235 echo "---> Ubuntu system detected"
236 ubuntu_systems
237 ;;
238 *)
239 echo "---> Unknown operating system"
240 ;;
241esac
242
243# execute steps for all systems
244all_systems