2eb7a3c6fbd60260bad47076c34a5f551615c80c
[releng/builder.git] / vagrant / baseline / bootstrap.sh
1 #!/bin/bash
2
3 # vim: ts=4 sw=4 sts=4 et tw=72 :
4
5 rh_systems() {
6     # Handle the occurance where SELINUX is actually disabled
7     if [ `grep SELINUX=permissive /etc/selinux/config` ]; then
8         # make sure that the filesystem is properly labelled.
9         # it could be not fully labeled correctly if it was just switched
10         # from disabled, the autorelabel misses some things
11         # skip relabelling on /dev as it will generally throw errors
12         restorecon -R -e /dev /
13
14         # enable enforcing mode from the very start
15         setenforce enforcing
16
17         # configure system for enforcing mode on next boot
18         sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/selinux/config
19     else
20         sed -i 's/SELINUX=disabled/SELINUX=permissive/' /etc/selinux/config
21         touch /.autorelabel
22
23         echo "*******************************************"
24         echo "** SYSTEM REQUIRES A RESTART FOR SELINUX **"
25         echo "*******************************************"
26     fi
27
28     echo "---> Updating operating system"
29     yum clean all -q
30     yum update -y -q
31
32     # add in components we need or want on systems
33     echo "---> Installing base packages"
34     yum install -y -q @base unzip xz puppet git perl-XML-XPath
35
36     # All of our systems require Java (because of Jenkins)
37     # Install all versions of the OpenJDK devel but force 1.7.0 to be the
38     # default
39
40     echo "---> Configuring OpenJDK"
41     yum install -y -q 'java-*-openjdk-devel'
42     alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
43     alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
44 }
45
46 ubuntu_systems() {
47     # Ignore SELinux since slamming that onto Ubuntu leads to
48     # frustration
49
50     echo "---> Updating operating system"
51     apt-get update -qq
52     apt-get upgrade -y --force-yes -qq
53
54     # add in stuff we know we need
55     echo "---> Installing base packages"
56     apt-get install -y --force-yes -qq unzip xz-utils puppet git libxml-xpath-perl
57
58     # install Java 7
59     echo "---> Configuring OpenJDK"
60     apt-get install -y --force-yes -qq openjdk-7-jdk
61     
62     # make jdk8 available
63     add-apt-repository -y ppa:openjdk-r/ppa
64     apt-get update -qq
65     # We need to force openjdk-8-jdk to install
66     apt-get install -y -qq openjdk-8-jdk
67
68     # make sure that we still default to openjdk 7
69     update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
70     update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
71 }
72
73 all_systems() {
74     # To handle the prompt style that is expected all over the environment
75     # with how use use robotframework we need to make sure that it is
76     # consistent for any of the users that are created during dynamic spin
77     # ups
78     echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
79
80     # Do any Distro specific installations here
81     echo "Checking distribution"
82     FACTER_OS=`/usr/bin/facter operatingsystem`
83     case "$FACTER_OS" in
84         RedHat|CentOS)
85             if [ `/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1` = "7" ]; then
86                 echo
87                 echo "---> CentOS 7"
88                 echo "No extra steps currently for CentOS 7"
89                 echo
90             else
91                 echo "---> CentOS 6"
92                 echo "Installing ODL YUM repo"
93                 yum install -q -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
94             fi
95         ;;
96         *)
97             echo "---> $FACTER_OS found"
98             echo "No extra steps for $FACTER_OS"
99         ;;
100     esac
101 }
102
103 echo "---> Attempting to detect OS"
104 # OS selector
105 if [ -f /usr/bin/yum ]
106 then
107     OS='RH'
108 else
109     OS='UBUNTU'
110 fi
111
112 case "$OS" in
113     RH)
114         echo "---> RH type system detected"
115         rh_systems
116     ;;
117     UBUNTU)
118         echo "---> Ubuntu system detected"
119         ubuntu_systems
120     ;;
121     *)
122         echo "---> Unknown operating system"
123     ;;
124 esac
125
126 # execute steps for all systems
127 all_systems