Merge "Modify logs publisher"
[ci-management.git] / packer / provision / baseline.sh
index d97f0e2..2546d44 100644 (file)
@@ -115,6 +115,41 @@ Dpkg::Options {
 
 EOF
 
+    # Wrap apt-get to wait for the lock to become available for operation
+    # http://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running
+    cat << 'EOF' >> /usr/local/bin/apt-get
+#!/bin/bash
+
+TTY=$(tty)
+test -z "$TTY" && TERM=dumb
+
+i=0
+tput sc
+LOCKFILES="/var/lib/dpkg/lock /var/lib/apt/lists/lock /var/cache/apt/archives/lock"
+while fuser ${LOCKFILES} >/dev/null 2>&1 ; do
+    case $(($i % 4)) in
+        0 ) j="-" ;;
+        1 ) j="\\" ;;
+        2 ) j="|" ;;
+        3 ) j="/" ;;
+    esac
+    tput rc
+    echo -en "\r[$j] Waiting for other software managers to finish..."
+    sleep 0.5
+    ((i=i+1))
+done
+
+if [ $i==0 ]
+then
+  /usr/bin/apt-get "$@"
+else
+  sleep 1
+  exec /usr/local/bin/apt-get "$@"
+fi
+
+EOF
+    chmod +x /usr/local/bin/apt-get
+
     echo "---> Updating operating system"
     apt-get update
     apt-get upgrade
@@ -173,6 +208,38 @@ EOF
 
 }
 
+opensuse_systems() {
+    # SELinux?
+
+    # Replacing cloud.cfg, it's not supported by cloud-init
+    cp /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg.orig
+
+    # Clean and add repos and refresh
+    zypper clean -a
+    zypper --non-interactive --gpg-auto-import-keys ar \
+        http://download.opensuse.org/update/leap/42.3/oss/openSUSE:Leap:42.3:Update.repo
+    zypper --gpg-auto-import-keys ref
+    zypper --non-interactive --gpg-auto-import-keys ar \
+        http://download.opensuse.org/repositories/Cloud:/Tools/openSUSE_Leap_42.3/ Cloud:Tools.repo
+
+    # Add in components we need or want on systems
+    echo "---> Installing base packages"
+    zypper -n install unzip xz puppet perl-XML-XPath
+
+    # Instlal tools
+    echo "---> Installing tools packages"
+    zypper -n install git git-review wget libstdc++-devel ruby-devel
+
+    # All of our systems require Java (because of Jenkins)
+    echo "---> Configuring OpenJDK"
+    zypper -n install 'java-*-openjdk-devel'
+
+    # Needed to parse OpenStack commands used by infra stack commands
+    # to initialize Heat template based systems.
+    zypper -n install jq
+
+}
+
 all_systems() {
     # Allow jenkins access to update-alternatives command to switch java version
     cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
@@ -180,6 +247,13 @@ Defaults:jenkins !requiretty
 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
 EOF
 
+    # Enable Hugepages
+    puppet module install thias-sysctl --version 1.0.6
+    puppet apply -e "sysctl {'vm.nr_hugepages': value => '128'}"
+    puppet apply -e "file { '/mnt/huge': ensure => directory }"
+    puppet apply -e "mount { '/mnt/huge': ensure => mounted, atboot => true, \
+      device => 'none', fstype => 'hugetlbfs', options => 'mode=01777' }"
+
     # Do any Distro specific installations here
     echo "Checking distribution"
     FACTER_OS=$(/usr/bin/facter operatingsystem)
@@ -196,10 +270,15 @@ echo "---> Attempting to detect OS"
 ORIGIN=$(if [ -e /etc/redhat-release ]
     then
         echo redhat
-    else
+    else [ -e /etc/os-release ]
+      DIST="$(grep "\<ID\>" /etc/os-release)"
+      if [ $DIST = "ID=ubuntu" ]
+      then
         echo ubuntu
+      else
+        echo opensuse
+      fi
     fi)
-#ORIGIN=$(logname)
 
 case "${ORIGIN}" in
     fedora|centos|redhat)
@@ -210,6 +289,10 @@ case "${ORIGIN}" in
         echo "---> Ubuntu system detected"
         ubuntu_systems
     ;;
+    opensuse)
+        echo "---> openSuSE system detected"
+        opensuse_systems
+    ;;
     *)
         echo "---> Unknown operating system"
     ;;