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 echo "$i: Installing $pkg"
83 if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
84 apt-cache policy "$pkg"
85 apt-get install "$pkg"
88 echo "$pkg already installed."
96 # Handle the occurance where SELINUX is actually disabled
97 SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
98 MODE=$(echo "$SELINUX" | cut -f 2 -d '=')
101 echo "************************************"
102 echo "** SYSTEM ENTERING ENFORCING MODE **"
103 echo "************************************"
104 # make sure that the filesystem is properly labelled.
105 # it could be not fully labeled correctly if it was just switched
106 # from disabled, the autorelabel misses some things
107 # skip relabelling on /dev as it will generally throw errors
108 restorecon -R -e /dev /
110 # enable enforcing mode from the very start
113 # configure system for enforcing mode on next boot
114 sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
117 sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
120 echo "*******************************************"
121 echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
122 echo "*******************************************"
125 echo "*********************************"
126 echo "** SYSTEM IS IN ENFORCING MODE **"
127 echo "*********************************"
131 # Allow jenkins access to alternatives command to switch java version
132 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
133 Defaults:jenkins !requiretty
134 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
137 echo "---> Updating operating system"
139 yum install -y deltarpm
142 ensure_kernel_install
144 # add in components we need or want on systems
145 echo "---> Installing base packages"
146 yum install -y @base https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
147 # separate group installs from package installs since a non-existing
148 # group with dnf based systems (F21+) will fail the install if such
149 # a group does not exist
150 yum install -y unzip xz puppet git git-review perl-XML-XPath
152 # All of our systems require Java (because of Jenkins)
153 # Install all versions of the OpenJDK devel but force 1.7.0 to be the
156 echo "---> Configuring OpenJDK"
157 yum install -y 'java-*-openjdk-devel'
159 FACTER_OS=$(/usr/bin/facter operatingsystem)
160 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
163 if [ "$FACTER_OSVER" -ge "21" ]
165 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
167 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
168 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
172 if [ "$(echo "$FACTER_OSVER" | cut -d'.' -f1)" -ge "7" ]
174 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
176 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
177 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
181 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
182 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
186 ########################
187 # --- START LFTOOLS DEPS
189 # Used by various scripts to push patches to Gerrit
190 yum install -y git-review
192 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
193 # to initialize Heat template based systems.
196 # Used by lftools scripts to parse XML
197 yum install -y xmlstarlet
200 # Cabal update fails on a 1G system so workaround that with a swap file
201 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
205 yum install -y cabal-install
207 cabal install "Cabal<1.18" # Pull Cabal version that is capable of building shellcheck
208 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
210 # --- END LFTOOLS DEPS
211 ######################
213 # install haveged to avoid low entropy rejecting ssh connections
214 yum install -y haveged
215 systemctl enable haveged.service
218 yum install -y sysstat
219 enable_service sysstat
221 # Install python3 and dependencies, needed for Coala linting at least
222 yum install -y python34
223 yum install -y python34-{devel,virtualenv,setuptools,pip}
225 # Install python dependencies, useful generally
226 yum install -y python-{devel,virtualenv,setuptools,pip}
230 # Ignore SELinux since slamming that onto Ubuntu leads to
233 # Allow jenkins access to update-alternatives command to switch java version
234 cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
235 Defaults:jenkins !requiretty
236 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
239 export DEBIAN_FRONTEND=noninteractive
240 cat <<EOF >> /etc/apt/apt.conf
244 allow-change-held-packages "true";
245 allow-downgrades "true";
246 allow-remove-essential "true";
257 # Add hostname to /etc/hosts to fix 'unable to resolve host' issue with sudo
258 sed -i "/127.0.0.1/s/$/ $(hostname)/" /etc/hosts
260 echo "---> Updating operating system"
262 # add additional repositories
263 sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
265 echo "---> Installing base packages"
269 apt-get dist-upgrade -m
271 ensure_ubuntu_install unzip xz-utils puppet git libxml-xpath-perl
273 # Install python3 and dependencies, needed for Coala linting
274 ensure_ubuntu_install python3
275 ensure_ubuntu_install python3-{dev,setuptools,pip}
277 # Install python and dependencies
278 ensure_ubuntu_install python-{dev,virtualenv,setuptools,pip}
280 FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
281 case "$FACTER_OSVER" in
283 echo "---> Installing OpenJDK"
284 apt-get install openjdk-7-jdk
285 # make jdk8 available
286 add-apt-repository -y ppa:openjdk-r/ppa
288 # We need to force openjdk-8-jdk to install
289 apt-get install openjdk-8-jdk
290 echo "---> Configuring OpenJDK"
291 # make sure that we still default to openjdk 7
292 update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
293 update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
296 echo "---> Installing OpenJDK"
297 apt-get install openjdk-8-jdk
299 echo "---> Installing python3 virtualenv"
300 # python3-virtualenv is available starting with 16.04.
301 ensure_ubuntu_install python3-virtualenv
304 echo "---> Unknown Ubuntu version $FACTER_OSVER"
309 ########################
310 # --- START LFTOOLS DEPS
312 # Used by various scripts to push patches to Gerrit
313 ensure_ubuntu_install git-review
315 # Needed to parse OpenStack commands used by opendaylight-infra stack commands
316 # to initialize Heat template based systems.
317 ensure_ubuntu_install jq
319 # Used by lftools scripts to parse XML
320 ensure_ubuntu_install xmlstarlet
323 # Cabal update fails on a 1G system so workaround that with a swap file
324 dd if=/dev/zero of=/tmp/swap bs=1M count=1024
328 ensure_ubuntu_install cabal-install
330 cabal install --bindir=/usr/local/bin "shellcheck-0.4.6" # Pin shellcheck version
332 # --- END LFTOOLS DEPS
333 ######################
336 ensure_ubuntu_install sysstat
337 sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
338 enable_service sysstat
340 # install haveged to avoid low entropy rejecting ssh connections
341 apt-get install haveged
342 update-rc.d haveged defaults
344 # disable unattended upgrades & daily updates
345 echo '---> Disabling automatic daily upgrades'
346 sed -ine 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
347 echo 'APT::Periodic::Unattended-Upgrade "0";' >> /etc/apt/apt.conf.d/10periodic
349 # Install packaging job dependencies for building debs
350 ensure_ubuntu_install build-essential devscripts equivs dh-systemd python-yaml \
356 # To handle the prompt style that is expected all over the environment
357 # with how use use robotframework we need to make sure that it is
358 # consistent for any of the users that are created during dynamic spin
360 echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
362 # Do any Distro specific installations here
363 echo "Checking distribution"
364 FACTER_OS=$(/usr/bin/facter operatingsystem)
367 if [ "$(/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1)" = "7" ]; then
370 echo "No extra steps currently for CentOS 7"
374 echo "Installing ODL YUM repo"
375 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
379 echo "---> $FACTER_OS found"
380 echo "No extra steps for $FACTER_OS"
385 echo "---> Attempting to detect OS"
386 # upstream cloud images use the distro name as the initial user
387 ORIGIN=$(if [ -e /etc/redhat-release ]
396 fedora|centos|redhat)
397 echo "---> RH type system detected"
401 echo "---> Ubuntu system detected"
405 echo "---> Unknown operating system"
409 # execute steps for all systems