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 # Enable services for Ubuntu instances
12 for service in "${services[@]}"; do
13 echo "---> Enable service: $service"
14 FACTER_OS=$(/usr/bin/facter operatingsystem)
15 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
16 if [ "$FACTER_OS" == "CentOS" ]; then
17 systemctl enable "$service"
18 systemctl start "$service"
19 systemctl status "$service"
20 elif [ "$FACTER_OS" == "Ubuntu" ]; then
21 case "$FACTER_OSVER" in
23 service "$service" start
24 service "$service" status
27 systemctl enable "$service"
28 systemctl start "$service"
29 systemctl status "$service"
32 echo "---> Unknown Ubuntu version $FACTER_OSVER"
37 echo "---> Unknown OS $FACTER_OS"
43 ensure_kernel_install() {
44 # Workaround for mkinitrd failing on occassion.
45 # On CentOS 7 it seems like the kernel install can fail it's mkinitrd
46 # run quietly, so we may not notice the failure. This script retries for a
47 # few times before giving up.
48 initramfs_ver=$(rpm -q kernel | tail -1 | sed "s/kernel-/initramfs-/")
49 grub_conf="/boot/grub/grub.conf"
50 # Public cloud does not use /boot/grub/grub.conf and uses grub2 instead.
51 if [ ! -e "$grub_conf" ]; then
52 echo "$grub_conf not found. Using Grub 2 conf instead."
53 grub_conf="/boot/grub2/grub.cfg"
57 if grep "$initramfs_ver" "$grub_conf"; then
60 echo "Kernel initrd missing. Retrying to install kernel..."
61 yum reinstall -y kernel
63 if ! grep "$initramfs_ver" "$grub_conf"; then
64 cat /boot/grub/grub.conf
65 echo "ERROR: Failed to install kernel."
70 ensure_ubuntu_install() {
71 # Workaround for mirrors occassionally failing to install a package.
72 # On Ubuntu sometimes the mirrors fail to install a package. This wrapper
73 # checks that a package is successfully installed before moving on.
77 for pkg in "${packages[@]}"
79 # Retry installing package 5 times if necessary
82 if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
83 apt-cache policy "$pkg"
84 apt-get install "$pkg"
87 echo "$pkg already installed."
95 # Handle the occurance where SELINUX is actually disabled
96 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
97 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
100 echo "************************************"
101 echo "** SYSTEM ENTERING ENFORCING MODE **"
102 echo "************************************"
103 # make sure that the filesystem is properly labelled.
104 # it could be not fully labeled correctly if it was just switched
105 # from disabled, the autorelabel misses some things
106 # skip relabelling on /dev as it will generally throw errors
107 restorecon -R -e /dev /
109 # enable enforcing mode from the very start
112 # configure system for enforcing mode on next boot
113 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
116 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
119 echo "*******************************************"
120 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
121 echo "*******************************************"
124 echo "*********************************"
125 echo "** SYSTEM IS IN ENFORCING MODE **"
126 echo "*********************************"
130 # Allow jenkins access to alternatives command to switch java version
131 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
132 Defaults:jenkins !requiretty
133 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
136 echo "---> Updating operating system"
138 yum install -y deltarpm
141 ensure_kernel_install
143 # add in components we need or want on systems
144 echo "---> Installing base packages"
145 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
146 # separate group installs from package installs since a non-existing
147 # group with dnf based systems (F21+) will fail the install if such
148 # a group does not exist
149 yum install -y unzip xz puppet git git-review perl-XML-XPath
151 # All of our systems require Java (because of Jenkins)
152 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
155 echo "---> Configuring OpenJDK"
156 yum install -y 'java-*-openjdk-devel'
158 FACTER_OS=$(/usr/bin/facter operatingsystem)
159 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
162 if [ "$FACTER_OSVER" -ge "21" ]
164 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
166 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
167 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
171 if [ "$(echo "$FACTER_OSVER" | cut -d'.' -f1)" -ge "7" ]
173 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
175 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
176 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
180 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
181 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
185 ########################
186 # --- START LFTOOLS DEPS
188 # Used by various scripts to push patches to Gerrit
189 yum install -y git-review
191 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
192 # to initialize Heat template based systems.
195 # Used by lftools scripts to parse XML
196 yum install -y xmlstarlet
199 # Cabal update fails on a 1G system so workaround that with a swap file
200 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
204 yum install -y cabal-install
206 cabal install "Cabal<1.18" # Pull Cabal version that is capable of building shellcheck
207 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
209 # --- END LFTOOLS DEPS
210 ######################
212 # install haveged to avoid low entropy rejecting ssh connections
213 yum install -y haveged
214 systemctl enable haveged.service
217 yum install -y sysstat
218 enable_service sysstat
222 # Ignore SELinux since slamming that onto Ubuntu leads to
225 # Allow jenkins access to update-alternatives command to switch java version
226 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
227 Defaults:jenkins !requiretty
228 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
231 export DEBIAN_FRONTEND=noninteractive
232 cat <<EOF >> /etc/apt/apt.conf
236 allow-change-held-packages "true";
237 allow-downgrades "true";
238 allow-remove-essential "true";
249 # Add hostname to /etc/hosts to fix 'unable to resolve host' issue with sudo
250 sed -i "/127.0.0.1/s/$/ $(hostname)/" /etc/hosts
252 echo "---> Updating operating system"
254 # add additional repositories
255 sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
257 echo "---> Installing base packages"
261 apt-get dist-upgrade -m
263 ensure_ubuntu_install unzip xz-utils puppet git libxml-xpath-perl
266 echo "---> Configuring OpenJDK"
267 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
268 case "$FACTER_OSVER" in
270 apt-get install openjdk-7-jdk
271 # make jdk8 available
272 add-apt-repository -y ppa:openjdk-r/ppa
274 # We need to force openjdk-8-jdk to install
275 apt-get install openjdk-8-jdk
276 # make sure that we still default to openjdk 7
277 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
278 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
281 apt-get install openjdk-8-jdk
284 echo "---> Unknown Ubuntu version $FACTER_OSVER"
289 ########################
290 # --- START LFTOOLS DEPS
292 # Used by various scripts to push patches to Gerrit
293 ensure_ubuntu_install git-review
295 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
296 # to initialize Heat template based systems.
297 ensure_ubuntu_install jq
299 # Used by lftools scripts to parse XML
300 ensure_ubuntu_install xmlstarlet
303 # Cabal update fails on a 1G system so workaround that with a swap file
304 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
308 ensure_ubuntu_install cabal-install
310 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
312 # --- END LFTOOLS DEPS
313 ######################
316 ensure_ubuntu_install sysstat
317 sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
318 enable_service sysstat
320 # install haveged to avoid low entropy rejecting ssh connections
321 apt-get install haveged
322 update-rc.d haveged defaults
324 # disable unattended upgrades & daily updates
325 echo '---> Disabling automatic daily upgrades'
326 sed -ine 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
327 echo 'APT::Periodic::Unattended-Upgrade "0";' >> /etc/apt/apt.conf.d/10periodic
331 # To handle the prompt style that is expected all over the environment
332 # with how use use robotframework we need to make sure that it is
333 # consistent for any of the users that are created during dynamic spin
335 echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
337 # Do any Distro specific installations here
338 echo "Checking distribution"
339 FACTER_OS=$(/usr/bin/facter operatingsystem)
342 if [ "$(/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1)" = "7" ]; then
345 echo "No extra steps currently for CentOS 7"
349 echo "Installing ODL YUM repo"
350 yum install -y https://nexus.opendaylight.org/content/repositories/opendaylight-yum-epel-6-x86_64/rpm/opendaylight-release/0.1.0-1.el6.noarch/opendaylight-release-0.1.0-1.el6.noarch.rpm
354 echo "---> $FACTER_OS found"
355 echo "No extra steps for $FACTER_OS"
360 echo "---> Attempting to detect OS"
361 # upstream cloud images use the distro name as the initial user
362 ORIGIN=$(if [ -e /etc/redhat-release ]
371 fedora|centos|redhat)
372 echo "---> RH type system detected"
376 echo "---> Ubuntu system detected"
380 echo "---> Unknown operating system"
384 # execute steps for all systems