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 | tr '[:upper:]' '[:lower:]')
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
83 # Wait for any background apt processes to finish before running apt
84 while pgrep apt > /dev/null; do sleep 1; done
86 echo "$i: Installing $pkg"
87 if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
88 apt-cache policy "$pkg"
89 apt-get install "$pkg"
92 echo "$pkg already installed."
100 # Handle the occurance where SELINUX is actually disabled
101 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
102 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
105 echo "************************************"
106 echo "** SYSTEM ENTERING ENFORCING MODE **"
107 echo "************************************"
108 # make sure that the filesystem is properly labelled.
109 # it could be not fully labeled correctly if it was just switched
110 # from disabled, the autorelabel misses some things
111 # skip relabelling on /dev as it will generally throw errors
112 restorecon -R -e /dev /
114 # enable enforcing mode from the very start
117 # configure system for enforcing mode on next boot
118 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
121 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
124 echo "*******************************************"
125 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
126 echo "*******************************************"
129 echo "*********************************"
130 echo "** SYSTEM IS IN ENFORCING MODE **"
131 echo "*********************************"
135 # Allow jenkins access to alternatives command to switch java version
136 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
137 Defaults:jenkins !requiretty
138 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
141 echo "---> Updating operating system"
143 yum install -y deltarpm
146 ensure_kernel_install
148 # add in components we need or want on systems
149 echo "---> Installing base packages"
150 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
151 # separate group installs from package installs since a non-existing
152 # group with dnf based systems (F21+) will fail the install if such
153 # a group does not exist
154 yum install -y unzip xz git git-review perl-XML-XPath
156 # facter is not installed by default on the base image and facter package
157 # gets removed when puppet4 is updated. To fix this use version of facter
158 # shipped with puppet4.
159 yum install -y facter
161 # ensure facter is available in $PATH avoid failures in retry loop
162 export PATH="/opt/puppetlabs/bin/:$PATH"
165 rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
166 yum -y install -y puppet-agent
168 # Create symlink for facter and puppet
169 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
170 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
172 # All of our systems require Java (because of Jenkins)
173 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
176 echo "---> Configuring OpenJDK"
177 yum install -y 'java-*-openjdk-devel'
179 FACTER_OS=$(/usr/bin/facter operatingsystem | tr '[:upper:]' '[:lower:]')
180 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
183 if [ "$FACTER_OSVER" -ge "21" ]
185 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
187 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
188 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
192 if [ "$(echo "$FACTER_OSVER" | cut -d'.' -f1)" -ge "7" ]
194 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
196 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
197 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
201 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
202 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
206 ########################
207 # --- START LFTOOLS DEPS
209 # Used by various scripts to push patches to Gerrit
210 yum install -y git-review
212 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
213 # to initialize Heat template based systems.
216 # Used py lftools to speend up some scripts
217 wget http://ftp.riken.jp/Linux/cern/centos/7/cern/x86_64/Packages/parallel-20150522-1.el7.cern.noarch.rpm
218 yum localinstall -y parallel-20150522-1.el7.cern.noarch.rpm
220 # Used by lftools scripts to parse XML
221 yum install -y xmlstarlet
224 # Cabal update fails on a 1G system so workaround that with a swap file
225 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
229 yum install -y cabal-install
231 cabal install "Cabal<1.18" # Pull Cabal version that is capable of building shellcheck
232 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
234 # NLTK_DATA Cache: many jobs that use coala pull down nltk_data
235 wget -nv -O /opt/nltk_data.zip https://github.com/nltk/nltk_data/archive/gh-pages.zip
237 # --- END LFTOOLS DEPS
238 ######################
240 # install haveged to avoid low entropy rejecting ssh connections
241 yum install -y haveged
242 systemctl enable haveged.service
245 yum install -y sysstat
246 enable_service sysstat
248 # Install python3 and dependencies, needed for Coala linting at least
249 yum install -y python34
250 yum install -y python34-{devel,virtualenv,setuptools,pip}
252 # Install python dependencies, useful generally
253 yum install -y python-{devel,virtualenv,setuptools,pip}
257 # Ignore SELinux since slamming that onto Ubuntu leads to
260 # Allow jenkins access to update-alternatives command to switch java version
261 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
262 Defaults:jenkins !requiretty
263 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
266 export DEBIAN_FRONTEND=noninteractive
267 cat <<EOF >> /etc/apt/apt.conf
271 allow-change-held-packages "true";
272 allow-downgrades "true";
273 allow-remove-essential "true";
284 echo "---> Updating operating system"
286 # add additional repositories
287 sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
289 echo "---> Installing base packages"
293 apt-get dist-upgrade -m
294 apt-get install facter
296 # facter is not installed by default on the base image and facter package
297 # gets removed when puppet4 is updated. To fix this use version of facter
298 # shipped with puppet4.
299 # ensure facter is available in $PATH avoid failures in retry loop
300 export PATH="/opt/puppetlabs/bin/:$PATH"
302 ensure_ubuntu_install unzip xz-utils git libxml-xpath-perl
304 # Install python3 and dependencies, needed for Coala linting
305 ensure_ubuntu_install python3
306 ensure_ubuntu_install python3-{dev,setuptools,pip}
308 # Install python and dependencies
309 ensure_ubuntu_install python-{dev,virtualenv,setuptools,pip}
311 FACTER_OSVER=$(facter operatingsystemrelease)
312 case "$FACTER_OSVER" in
314 echo "---> Installing OpenJDK"
315 apt-get install openjdk-7-jdk
316 # make jdk8 available
317 add-apt-repository -y ppa:openjdk-r/ppa
319 # We need to force openjdk-8-jdk to install
320 apt-get install openjdk-8-jdk
321 echo "---> Configuring OpenJDK"
322 # make sure that we still default to openjdk 7
323 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
324 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
326 echo "---> Install puppet repository for 14.04"
327 apt-get purge puppet puppet-common
328 wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
329 dpkg -i puppetlabs-release-pc1-trusty.deb
331 echo "---> Installing puppet"
333 ensure_ubuntu_install puppet-agent
334 # Create symlink for facter and puppet
335 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
336 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
339 echo "---> Installing OpenJDK"
340 apt-get install openjdk-8-jdk
342 echo "---> Install puppet4 repository for 16.04"
343 apt-get purge puppet puppet-common
344 wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
345 dpkg -i puppetlabs-release-pc1-xenial.deb
347 echo "---> Installing puppet"
349 ensure_ubuntu_install puppet-agent
351 # Create symlink for facter and puppet
352 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
353 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
355 echo "---> Installing python3 virtualenv"
356 # python3-virtualenv is available starting with 16.04.
357 ensure_ubuntu_install python3-virtualenv
360 echo "---> Unknown Ubuntu version $FACTER_OSVER"
365 ########################
366 # --- START LFTOOLS DEPS
368 # Used by various scripts to push patches to Gerrit
369 ensure_ubuntu_install git-review
371 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
372 # to initialize Heat template based systems.
373 ensure_ubuntu_install jq
375 # Used py lftools to speend up some scripts
376 ensure_ubuntu_install parallel
378 # Used by lftools scripts to parse XML
379 ensure_ubuntu_install xmlstarlet
382 # Cabal update fails on a 1G system so workaround that with a swap file
383 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
387 ensure_ubuntu_install cabal-install
389 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
391 # NLTK_DATA Cache: many jobs that use coala pull down nltk_data
392 wget -nv -O /opt/nltk_data.zip https://github.com/nltk/nltk_data/archive/gh-pages.zip
394 # --- END LFTOOLS DEPS
395 ######################
398 ensure_ubuntu_install sysstat
399 sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
400 enable_service sysstat
402 # Install haveged to avoid low entropy rejecting ssh connections
403 apt-get install haveged
404 update-rc.d haveged defaults
406 # Disable unattended upgrades & daily updates
407 echo '---> Disabling automatic daily upgrades'
408 sed -ine 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
409 echo 'APT::Periodic::Unattended-Upgrade "0";' >> /etc/apt/apt.conf.d/10periodic
411 # Install packaging job dependencies for building debs
412 ensure_ubuntu_install build-essential devscripts equivs dh-systemd python-yaml \
417 # To handle the prompt style that is expected all over the environment
418 # with how use use robotframework we need to make sure that it is
419 # consistent for any of the users that are created during dynamic spin
421 echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
423 # Do any Distro specific installations here
424 echo "Checking distribution"
425 FACTER_OS=$(/usr/bin/facter operatingsystem | tr '[:upper:]' '[:lower:]')
428 if [ "$(/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1)" = "7" ]; then
431 echo "No extra steps currently for CentOS 7"
435 echo "Installing ODL YUM repo"
436 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
440 echo "---> $FACTER_OS found"
441 echo "No extra steps for $FACTER_OS"
445 # Update /etc/nss-switch.conf to map hostname with IP instead of using `localhost`
446 # from /etc/hosts which is required by some of the Java API's to avoid
447 # Java UnknownHostException: "Name or service not known" error.
448 sed -i "/^hosts:/s/$/ myhostname/" /etc/nsswitch.conf
451 echo "---> Attempting to detect OS"
452 # upstream cloud images use the distro name as the initial user
453 ORIGIN=$(if [ -e /etc/redhat-release ]
462 fedora|centos|redhat)
463 echo "---> RH type system detected"
467 echo "---> Ubuntu system detected"
471 echo "---> Unknown operating system"
475 # execute steps for all systems