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
10 # We purposely want to allow globbing to build the package array
11 # shellcheck disable=SC2206
14 for service in "${services[@]}"; do
15 echo "---> Enable service: $service"
16 FACTER_OS=$(/usr/bin/facter operatingsystem | tr '[:upper:]' '[:lower:]')
17 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
18 if [ "$FACTER_OS" == "centos" ]; then
19 systemctl enable "$service"
20 systemctl start "$service"
21 systemctl status "$service"
22 elif [ "$FACTER_OS" == "ubuntu" ]; then
23 case "$FACTER_OSVER" in
25 service "$service" start
26 service "$service" status
29 systemctl enable "$service"
30 systemctl start "$service"
31 systemctl status "$service"
34 echo "---> Unknown Ubuntu version $FACTER_OSVER"
39 echo "---> Unknown OS $FACTER_OS"
45 ensure_kernel_install() {
46 # Workaround for mkinitrd failing on occassion.
47 # On CentOS 7 it seems like the kernel install can fail it's mkinitrd
48 # run quietly, so we may not notice the failure. This script retries for a
49 # few times before giving up.
50 initramfs_ver=$(rpm -q kernel | tail -1 | sed "s/kernel-/initramfs-/")
51 grub_conf="/boot/grub/grub.conf"
52 # Public cloud does not use /boot/grub/grub.conf and uses grub2 instead.
53 if [ ! -e "$grub_conf" ]; then
54 echo "$grub_conf not found. Using Grub 2 conf instead."
55 grub_conf="/boot/grub2/grub.cfg"
59 if grep "$initramfs_ver" "$grub_conf"; then
62 echo "Kernel initrd missing. Retrying to install kernel..."
63 yum reinstall -y kernel
65 if ! grep "$initramfs_ver" "$grub_conf"; then
66 cat /boot/grub/grub.conf
67 echo "ERROR: Failed to install kernel."
72 ensure_ubuntu_install() {
73 # Workaround for mirrors occassionally failing to install a package.
74 # On Ubuntu sometimes the mirrors fail to install a package. This wrapper
75 # checks that a package is successfully installed before moving on.
77 # We purposely want to allow globbing to build the package array
78 # shellcheck disable=SC2206
81 for pkg in "${packages[@]}"
83 # Retry installing package 5 times if necessary
87 # Wait for any background apt processes to finish before running apt
88 while pgrep apt > /dev/null; do sleep 1; done
90 echo "$i: Installing $pkg"
91 if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
92 apt-cache policy "$pkg"
93 apt-get install "$pkg"
96 echo "$pkg already installed."
104 # Handle the occurance where SELINUX is actually disabled
105 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
106 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
109 echo "************************************"
110 echo "** SYSTEM ENTERING ENFORCING MODE **"
111 echo "************************************"
112 # make sure that the filesystem is properly labelled.
113 # it could be not fully labeled correctly if it was just switched
114 # from disabled, the autorelabel misses some things
115 # skip relabelling on /dev as it will generally throw errors
116 restorecon -R -e /dev /
118 # enable enforcing mode from the very start
121 # configure system for enforcing mode on next boot
122 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
125 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
128 echo "*******************************************"
129 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
130 echo "*******************************************"
133 echo "*********************************"
134 echo "** SYSTEM IS IN ENFORCING MODE **"
135 echo "*********************************"
139 # Allow jenkins access to alternatives command to switch java version
140 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
141 Defaults:jenkins !requiretty
142 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
145 echo "---> Updating operating system"
147 yum install -y deltarpm
150 ensure_kernel_install
152 # add in components we need or want on systems
153 echo "---> Installing base packages"
154 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
155 # separate group installs from package installs since a non-existing
156 # group with dnf based systems (F21+) will fail the install if such
157 # a group does not exist
158 yum install -y unzip xz git git-review perl-XML-XPath
160 # facter is not installed by default on the base image and facter package
161 # gets removed when puppet4 is updated. To fix this use version of facter
162 # shipped with puppet4.
163 yum install -y facter
165 # ensure facter is available in $PATH avoid failures in retry loop
166 export PATH="/opt/puppetlabs/bin/:$PATH"
169 rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
170 yum -y install -y puppet-agent
172 # Create symlink for facter and puppet
173 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
174 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
176 # All of our systems require Java (because of Jenkins)
177 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
180 echo "---> Configuring OpenJDK"
181 yum install -y 'java-*-openjdk-devel'
183 FACTER_OS=$(/usr/bin/facter operatingsystem | tr '[:upper:]' '[:lower:]')
184 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
187 if [ "$FACTER_OSVER" -ge "21" ]
189 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
191 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
192 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
196 if [ "$(echo "$FACTER_OSVER" | cut -d'.' -f1)" -ge "7" ]
198 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
200 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
201 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
205 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
206 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
210 ########################
211 # --- START LFTOOLS DEPS
213 # Used by various scripts to push patches to Gerrit
214 yum install -y git-review
216 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
217 # to initialize Heat template based systems.
220 # Used py lftools to speend up some scripts
221 wget http://ftp.riken.jp/Linux/cern/centos/7/cern/x86_64/Packages/parallel-20150522-1.el7.cern.noarch.rpm
222 yum localinstall -y parallel-20150522-1.el7.cern.noarch.rpm
224 # Used by lftools scripts to parse XML
225 yum install -y xmlstarlet
228 # Cabal update fails on a 1G system so workaround that with a swap file
229 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
233 yum install -y cabal-install
235 cabal install "Cabal<1.18" # Pull Cabal version that is capable of building shellcheck
236 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
238 # NLTK_DATA Cache: many jobs that use coala pull down nltk_data
239 wget -nv -O /opt/nltk_data.zip https://github.com/nltk/nltk_data/archive/gh-pages.zip
241 # --- END LFTOOLS DEPS
242 ######################
244 # install haveged to avoid low entropy rejecting ssh connections
245 yum install -y haveged
246 systemctl enable haveged.service
249 yum install -y sysstat
250 enable_service sysstat
252 # Install python3 and dependencies, needed for Coala linting at least
253 yum install -y python34
254 yum install -y python34-{devel,virtualenv,setuptools,pip}
256 # Install python dependencies, useful generally
257 yum install -y python-{devel,virtualenv,setuptools,pip}
261 # Ignore SELinux since slamming that onto Ubuntu leads to
264 # Allow jenkins access to update-alternatives command to switch java version
265 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
266 Defaults:jenkins !requiretty
267 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
270 export DEBIAN_FRONTEND=noninteractive
271 cat <<EOF >> /etc/apt/apt.conf
275 allow-change-held-packages "true";
276 allow-downgrades "true";
277 allow-remove-essential "true";
288 echo "---> Updating operating system"
290 # add additional repositories
291 sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
293 echo "---> Installing base packages"
297 apt-get dist-upgrade -m
298 apt-get install facter
300 # facter is not installed by default on the base image and facter package
301 # gets removed when puppet4 is updated. To fix this use version of facter
302 # shipped with puppet4.
303 # ensure facter is available in $PATH avoid failures in retry loop
304 export PATH="/opt/puppetlabs/bin/:$PATH"
306 ensure_ubuntu_install unzip xz-utils git libxml-xpath-perl
308 # Install python3 and dependencies, needed for Coala linting
309 ensure_ubuntu_install python3
310 ensure_ubuntu_install python3-{dev,setuptools,pip}
312 # Install python and dependencies
313 ensure_ubuntu_install python-{dev,virtualenv,setuptools,pip}
315 FACTER_OSVER=$(facter operatingsystemrelease)
316 case "$FACTER_OSVER" in
318 echo "---> Installing OpenJDK"
319 apt-get install openjdk-7-jdk
320 # make jdk8 available
321 add-apt-repository -y ppa:openjdk-r/ppa
323 # We need to force openjdk-8-jdk to install
324 apt-get install openjdk-8-jdk
325 echo "---> Configuring OpenJDK"
326 # make sure that we still default to openjdk 7
327 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
328 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
330 echo "---> Install puppet repository for 14.04"
331 apt-get purge puppet puppet-common
332 wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
333 dpkg -i puppetlabs-release-pc1-trusty.deb
335 echo "---> Installing puppet"
337 ensure_ubuntu_install puppet-agent
338 # Create symlink for facter and puppet
339 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
340 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
343 echo "---> Installing OpenJDK"
344 apt-get install openjdk-8-jdk
346 echo "---> Install puppet4 repository for 16.04"
347 apt-get purge puppet puppet-common
348 wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
349 dpkg -i puppetlabs-release-pc1-xenial.deb
351 echo "---> Installing puppet"
353 ensure_ubuntu_install puppet-agent
355 # Create symlink for facter and puppet
356 ln -sf /opt/puppetlabs/bin/facter /usr/bin/facter
357 ln -sf /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
359 echo "---> Installing python3 virtualenv"
360 # python3-virtualenv is available starting with 16.04.
361 ensure_ubuntu_install python3-virtualenv
364 echo "---> Unknown Ubuntu version $FACTER_OSVER"
369 ########################
370 # --- START LFTOOLS DEPS
372 # Used by various scripts to push patches to Gerrit
373 ensure_ubuntu_install git-review
375 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
376 # to initialize Heat template based systems.
377 ensure_ubuntu_install jq
379 # Used py lftools to speend up some scripts
380 ensure_ubuntu_install parallel
382 # Used by lftools scripts to parse XML
383 ensure_ubuntu_install xmlstarlet
386 # Cabal update fails on a 1G system so workaround that with a swap file
387 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
391 ensure_ubuntu_install cabal-install
393 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
395 # NLTK_DATA Cache: many jobs that use coala pull down nltk_data
396 wget -nv -O /opt/nltk_data.zip https://github.com/nltk/nltk_data/archive/gh-pages.zip
398 # --- END LFTOOLS DEPS
399 ######################
402 ensure_ubuntu_install sysstat
403 sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
404 enable_service sysstat
406 # Install haveged to avoid low entropy rejecting ssh connections
407 apt-get install haveged
408 update-rc.d haveged defaults
410 # Disable unattended upgrades & daily updates
411 echo '---> Disabling automatic daily upgrades'
412 sed -ine 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
413 echo 'APT::Periodic::Unattended-Upgrade "0";' >> /etc/apt/apt.conf.d/10periodic
415 # Install packaging job dependencies for building debs
416 ensure_ubuntu_install build-essential devscripts equivs dh-systemd python-yaml \
421 # To handle the prompt style that is expected all over the environment
422 # with how use use robotframework we need to make sure that it is
423 # consistent for any of the users that are created during dynamic spin
425 echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
427 # Do any Distro specific installations here
428 echo "Checking distribution"
429 FACTER_OS=$(/usr/bin/facter operatingsystem | tr '[:upper:]' '[:lower:]')
432 if [ "$(/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1)" = "7" ]; then
435 echo "No extra steps currently for CentOS 7"
439 echo "Installing ODL YUM repo"
440 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
444 echo "---> $FACTER_OS found"
445 echo "No extra steps for $FACTER_OS"
449 # Update /etc/nss-switch.conf to map hostname with IP instead of using `localhost`
450 # from /etc/hosts which is required by some of the Java API's to avoid
451 # Java UnknownHostException: "Name or service not known" error.
452 sed -i "/^hosts:/s/$/ myhostname/" /etc/nsswitch.conf
455 echo "---> Attempting to detect OS"
456 # upstream cloud images use the distro name as the initial user
457 ORIGIN=$(if [ -e /etc/redhat-release ]
466 fedora|centos|redhat)
467 echo "---> RH type system detected"
471 echo "---> Ubuntu system detected"
475 echo "---> Unknown operating system"
479 # execute steps for all systems