Fix autorelease logrotate
[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     # Allow jenkins access to alternatives command to switch java version
29     cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
30 Defaults:jenkins !requiretty
31 jenkins ALL = NOPASSWD: /usr/sbin/alternatives
32 EOF
33
34     echo "---> Updating operating system"
35     yum clean all -q
36     yum update -y -q
37
38     # add in components we need or want on systems
39     echo "---> Installing base packages"
40     yum install -y -q @base
41     # separate group installs from package installs since a non-existing
42     # group with dnf based systems (F21+) will fail the install if such
43     # a group does not exist
44     yum install -y -q unzip xz puppet git perl-XML-XPath
45
46     # All of our systems require Java (because of Jenkins)
47     # Install all versions of the OpenJDK devel but force 1.7.0 to be the
48     # default
49
50     echo "---> Configuring OpenJDK"
51     yum install -y -q 'java-*-openjdk-devel'
52
53     FACTER_OS=`/usr/bin/facter operatingsystem`
54     FACTER_OSVER=`/usr/bin/facter operatingsystemrelease`
55     case "$FACTER_OS" in
56         Fedora)
57             if [ "$FACTER_OSVER" -ge "21" ]
58             then
59                 echo "---> not modifying java alternatives as OpenJDK 1.7.0 does not exist"
60             else
61                 alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
62                 alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
63             fi
64         ;;
65         *)
66             alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
67             alternatives --set java_sdk_openjdk /usr/lib/jvm/java-1.7.0-openjdk.x86_64
68         ;;
69     esac
70 }
71
72 ubuntu_systems() {
73     # Ignore SELinux since slamming that onto Ubuntu leads to
74     # frustration
75
76     # Allow jenkins access to update-alternatives command to switch java version
77     cat <<EOF >/etc/sudoers.d/89-jenkins-user-defaults
78 Defaults:jenkins !requiretty
79 jenkins ALL = NOPASSWD: /usr/bin/update-alternatives
80 EOF
81
82     echo "---> Updating operating system"
83     apt-get update -qq
84     apt-get upgrade -y --force-yes -qq
85
86     # add in stuff we know we need
87     echo "---> Installing base packages"
88     apt-get install -y --force-yes -qq unzip xz-utils puppet git libxml-xpath-perl
89
90     # install Java 7
91     echo "---> Configuring OpenJDK"
92     apt-get install -y --force-yes -qq openjdk-7-jdk
93
94     # make jdk8 available
95     add-apt-repository -y ppa:openjdk-r/ppa
96     apt-get update -qq
97     # We need to force openjdk-8-jdk to install
98     apt-get install -y -qq openjdk-8-jdk
99
100     # make sure that we still default to openjdk 7
101     update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
102     update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
103 }
104
105 all_systems() {
106     # To handle the prompt style that is expected all over the environment
107     # with how use use robotframework we need to make sure that it is
108     # consistent for any of the users that are created during dynamic spin
109     # ups
110     echo 'PS1="[\u@\h \W]> "' >> /etc/skel/.bashrc
111
112     # Do any Distro specific installations here
113     echo "Checking distribution"
114     FACTER_OS=`/usr/bin/facter operatingsystem`
115     case "$FACTER_OS" in
116         RedHat|CentOS)
117             if [ `/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1` = "7" ]; then
118                 echo
119                 echo "---> CentOS 7"
120                 echo "No extra steps currently for CentOS 7"
121                 echo
122             else
123                 echo "---> CentOS 6"
124                 echo "Installing ODL YUM repo"
125                 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
126             fi
127         ;;
128         *)
129             echo "---> $FACTER_OS found"
130             echo "No extra steps for $FACTER_OS"
131         ;;
132     esac
133 }
134
135 echo "---> Attempting to detect OS"
136 # OS selector
137 if [ -f /usr/bin/yum ]
138 then
139     OS='RH'
140 else
141     OS='UBUNTU'
142 fi
143
144 case "$OS" in
145     RH)
146         echo "---> RH type system detected"
147         rh_systems
148     ;;
149     UBUNTU)
150         echo "---> Ubuntu system detected"
151         ubuntu_systems
152     ;;
153     *)
154         echo "---> Unknown operating system"
155     ;;
156 esac
157
158 # execute steps for all systems
159 all_systems