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
8 ensure_kernel_install() {
9 # Workaround for mkinitrd failing on occassion.
10 # On CentOS 7 it seems like the kernel install can fail it's mkinitrd
11 # run quietly, so we may not notice the failure. This script retries for a
12 # few times before giving up.
13 initramfs_ver=$(rpm -q kernel | tail -1 | sed "s/kernel-/initramfs-/")
14 grub_conf="/boot/grub/grub.conf"
15 # Public cloud does not use /boot/grub/grub.conf and uses grub2 instead.
16 if [ ! -e "$grub_conf" ]; then
17 echo "$grub_conf not found. Using Grub 2 conf instead."
18 grub_conf="/boot/grub2/grub.cfg"
22 if grep "$initramfs_ver" "$grub_conf"; then
25 echo "Kernel initrd missing. Retrying to install kernel..."
26 yum reinstall -y kernel
28 if ! grep "$initramfs_ver" "$grub_conf"; then
29 cat /boot/grub/grub.conf
30 echo "ERROR: Failed to install kernel."
35 ensure_ubuntu_install() {
36 # Workaround for mirrors occassionally failing to install a package.
37 # On Ubuntu sometimes the mirrors fail to install a package. This wrapper
38 # checks that a package is successfully installed before moving on.
42 for pkg in "${packages[@]}"
44 # Retry installing package 5 times if necessary
47 if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
48 apt-cache policy "$pkg"
49 apt-get install "$pkg"
52 echo "$pkg already installed."
60 # Handle the occurance where SELINUX is actually disabled
61 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
62 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
65 echo "************************************"
66 echo "** SYSTEM ENTERING ENFORCING MODE **"
67 echo "************************************"
68 # make sure that the filesystem is properly labelled.
69 # it could be not fully labeled correctly if it was just switched
70 # from disabled, the autorelabel misses some things
71 # skip relabelling on /dev as it will generally throw errors
72 restorecon -R -e /dev /
74 # enable enforcing mode from the very start
77 # configure system for enforcing mode on next boot
78 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
81 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
84 echo "*******************************************"
85 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
86 echo "*******************************************"
89 echo "*********************************"
90 echo "** SYSTEM IS IN ENFORCING MODE **"
91 echo "*********************************"
95 # Allow jenkins access to alternatives command to switch java version
96 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
97 Defaults:jenkins !requiretty
98 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
101 echo "---> Updating operating system"
103 yum install -y deltarpm
106 ensure_kernel_install
108 # add in components we need or want on systems
109 echo "---> Installing base packages"
110 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
111 # separate group installs from package installs since a non-existing
112 # group with dnf based systems (F21+) will fail the install if such
113 # a group does not exist
114 yum install -y unzip xz puppet git git-review perl-XML-XPath
116 # All of our systems require Java (because of Jenkins)
117 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
120 echo "---> Configuring OpenJDK"
121 yum install -y 'java-*-openjdk-devel'
123 FACTER_OS=$(/usr/bin/facter operatingsystem)
124 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
127 if [ "$FACTER_OSVER" -ge "21" ]
129 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
131 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
132 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
136 if [ "$(echo "$FACTER_OSVER" | cut -d'.' -f1)" -ge "7" ]
138 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
140 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
141 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
145 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
146 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
150 ########################
151 # --- START LFTOOLS DEPS
153 # Used by various scripts to push patches to Gerrit
154 yum install -y git-review
156 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
157 # to initialize Heat template based systems.
160 # Used by lftools scripts to parse XML
161 yum install -y xmlstarlet
164 # Cabal update fails on a 1G system so workaround that with a swap file
165 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
169 yum install -y cabal-install
171 cabal install "Cabal<1.18" # Pull Cabal version that is capable of building shellcheck
172 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
174 # --- END LFTOOLS DEPS
175 ######################
177 # install haveged to avoid low entropy rejecting ssh connections
178 yum install -y haveged
179 systemctl enable haveged.service
183 # Ignore SELinux since slamming that onto Ubuntu leads to
186 # Allow jenkins access to update-alternatives command to switch java version
187 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
188 Defaults:jenkins !requiretty
189 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
192 export DEBIAN_FRONTEND=noninteractive
193 cat <<EOF >> /etc/apt/apt.conf
197 allow-change-held-packages "true";
198 allow-downgrades "true";
199 allow-remove-essential "true";
210 # Add hostname to /etc/hosts to fix 'unable to resolve host' issue with sudo
211 sed -i "/127.0.0.1/s/$/ $(hostname)/" /etc/hosts
213 echo "---> Updating operating system"
215 # add additional repositories
216 sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
218 echo "---> Installing base packages"
222 apt-get dist-upgrade -m
224 ensure_ubuntu_install unzip xz-utils puppet git libxml-xpath-perl
227 echo "---> Configuring OpenJDK"
228 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
229 case "$FACTER_OSVER" in
231 apt-get install openjdk-7-jdk
232 # make jdk8 available
233 add-apt-repository -y ppa:openjdk-r/ppa
235 # We need to force openjdk-8-jdk to install
236 apt-get install openjdk-8-jdk
237 # make sure that we still default to openjdk 7
238 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
239 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
242 apt-get install openjdk-8-jdk
245 echo "---> Unknown Ubuntu version $FACTER_OSVER"
250 ########################
251 # --- START LFTOOLS DEPS
253 # Used by various scripts to push patches to Gerrit
254 ensure_ubuntu_install git-review
256 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
257 # to initialize Heat template based systems.
258 ensure_ubuntu_install jq
260 # Used by lftools scripts to parse XML
261 ensure_ubuntu_install xmlstarlet
264 # Cabal update fails on a 1G system so workaround that with a swap file
265 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
269 ensure_ubuntu_install cabal-install
271 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
273 # --- END LFTOOLS DEPS
274 ######################
276 # install haveged to avoid low entropy rejecting ssh connections
277 apt-get install haveged
278 update-rc.d haveged defaults
280 # disable unattended upgrades & daily updates
281 echo '---> Disabling automatic daily upgrades'
282 sed -ine 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
283 echo 'APT::Periodic::Unattended-Upgrade "0";' >> /etc/apt/apt.conf.d/10periodic
287 # To handle the prompt style that is expected all over the environment
288 # with how use use robotframework we need to make sure that it is
289 # consistent for any of the users that are created during dynamic spin
291 echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
293 # Do any Distro specific installations here
294 echo "Checking distribution"
295 FACTER_OS=$(/usr/bin/facter operatingsystem)
298 if [ "$(/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1)" = "7" ]; then
301 echo "No extra steps currently for CentOS 7"
305 echo "Installing ODL YUM repo"
306 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
310 echo "---> $FACTER_OS found"
311 echo "No extra steps for $FACTER_OS"
316 echo "---> Attempting to detect OS"
317 # upstream cloud images use the distro name as the initial user
318 ORIGIN=$(if [ -e /etc/redhat-release ]
327 fedora|centos|redhat)
328 echo "---> RH type system detected"
332 echo "---> Ubuntu system detected"
336 echo "---> Unknown operating system"
340 # execute steps for all systems