Cleanup vagrant
[ci-management.git] / vagrant / basebuild / bootstrap.sh
1 #!/bin/bash -x
2
3 # die on errors
4 set -e
5
6 # Redirect stdout ( 1> ) and stderr ( 2> ) into named pipes ( >() ) running "tee"
7 #exec 1> >(tee -i /tmp/bootstrap-out.log)
8 #exec 2> >(tee -i /tmp/bootstrap-err.log)
9
10 ubuntu_systems() {
11
12     PACKAGES="" # initialize PACKAGES
13
14     if [ $? == 0 ]
15     then
16         VERSION=$(lsb_release -r | awk '{print $2}')
17         DIST=$(lsb_release -i | awk '{print $3}')
18         CODENAME=$(lsb_release -c | awk '{print $2}')
19     else
20         ISSUE_TXT=$(head -1 /etc/issue)
21         DIST=$(echo "${ISSUE_TXT}" | awk '{print $1}')
22         if [ "$DIST" = "Ubuntu" ]
23         then
24             VERSION=$(echo "${ISSUE_TXT}" | awk '{print $2}' | sed -e 's/^(\d+\.\d+)(\.\d+)?$/\1/')
25         elif [ "$DIST" = "Debian" ]
26         then
27             VERSION=$(echo "${ISSUE_TXT}" | awk '{print $3}')
28         else
29             echo "Unrecognized distribution: ${DIST}"
30         fi
31     fi
32
33     echo "---> Detected [${DIST} v${VERSION} (${CODENAME})]"
34
35     export DEBIAN_FRONTEND=noninteractive
36     cat <<EOF >> /etc/apt/apt.conf
37 APT {
38   Get {
39     Assume-Yes "true";
40     allow-change-held-packages "true";
41     allow-downgrades "true";
42     allow-remove-essential "true";
43   };
44 };
45
46 Dpkg::Options {
47    "--force-confdef";
48    "--force-confold";
49 };
50
51 EOF
52
53     # Install plymouth labels and themes to get rid of initrd warnings / errors
54     if [ "$VERSION" = '14.04' ]
55     then
56
57         # openjdk-8-jdk is not available in 14.04 repos by default
58         add-apt-repository ppa:openjdk-r/ppa
59
60         # Install OpenJDK
61         PACKAGES="$PACKAGES openjdk-8-jdk-headless"
62
63         # Install Oracle's jdk version 8
64 #        apt-add-repository -y ppa:webupd8team/java
65 #        apt-get -qq update
66 #        echo "debconf shared/accepted-oracle-license-v1-1 select true
67 #              debconf shared/accepted-oracle-license-v1-1 seen true" | sudo debconf-set-selections
68 #        PACKAGES="$PACKAGES oracle-java8-installer"
69     else
70         # Install default jdk and plymouth packages
71         PACKAGES="$PACKAGES plymouth-themes plymouth-label default-jdk-headless"
72     fi
73
74
75     echo '---> Updating OS'
76     # Standard update + upgrade dance
77     apt-get -qq update
78     apt-get -qq upgrade
79     apt-get -qq dist-upgrade
80
81     # Fix the silly notion that /bin/sh should point to dash by pointing it to bash
82
83     update-alternatives --install /bin/sh sh /bin/bash 100
84
85     # Install build tools
86     PACKAGES="$PACKAGES build-essential autoconf automake bison libssl-dev ccache libtool git dkms debhelper libganglia1-dev libapr1-dev libconfuse-dev"
87
88     # Install interface manipulation tools, editor, debugger and lsb
89     PACKAGES="$PACKAGES iproute2 bridge-utils vim gdb lsb-release"
90
91     # Install debian packaging tools
92     PACKAGES="$PACKAGES debhelper dh-systemd dkms"
93
94     # Install latest kernel and uio
95     PACKAGES="$PACKAGES linux-image-extra-virtual"
96
97     # $$$ comment out for the moment
98     # PACKAGES="$PACKAGES maven3"
99
100     # Install virtualenv for test execution
101     PACKAGES="$PACKAGES python-virtualenv python-pip python-dev"
102
103     echo '---> Installing packages'
104     # disable double quoting check
105     # shellcheck disable=SC2086 
106     apt-get -qq install ${PACKAGES}
107     apt-get -qq autoremove
108     apt-get -qq clean
109
110     # update CA certificates
111     echo '---> Forcing CA certificate update'
112     update-ca-certificates -f
113
114     # It is not necessary to load the uio kernel module during the bootstrap phase
115 #    modprobe uio_pci_generic
116
117     # Make sure uio loads at boot time
118     echo uio_pci_generic >> /etc/modules
119
120     # Setup for hugepages using sysctl so it persists across reboots
121     sysctl -w vm.nr_hugepages=1024
122
123     mkdir -p /mnt/huge
124     echo "hugetlbfs       /mnt/huge  hugetlbfs       defaults        0 0" >> /etc/fstab
125     mount /mnt/huge
126
127 }
128
129 rh_systems() {
130     echo '---> Updating OS'
131     yum clean all -q
132     yum upgrade -q -y
133
134     echo '---> Installing tools'
135     yum install -q -y @development openssl-devel glibc-static
136
137     # Install jdk and maven
138     yum install -q -y java-1.8.0-openjdk-devel
139
140     # Install python development
141     yum search python34-devel 2>&1 | grep -q 'No matches'
142     if [ $? -eq 0 ]
143     then
144         echo '---> Installing python-devel'
145         yum install -q -y python-devel
146     else
147         echo '---> Installying python34-devel'
148         yum install -q -y python34-devel
149     fi
150
151     echo '---> Configuring EPEL'
152     # Install EPEL
153     yum install -q -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
154
155     # Install components to build Ganglia modules
156     yum install -q -y {apr,libconfuse,ganglia}-devel mock
157 }
158
159 echo "---> Attempting to detect OS"
160 # OS selector
161 if [ -f /usr/bin/yum ]
162 then
163     OS='RH'
164 else
165     OS='UBUNTU'
166 fi
167
168 case "$OS" in
169     RH)
170         echo "---> RH type system detected"
171         rh_systems
172     ;;
173     UBUNTU)
174         echo "---> Ubuntu system detected"
175         ubuntu_systems
176     ;;
177     *)
178         echo "---> Unknown operating system"
179     ;;
180 esac
181
182 echo "bootstrap process (PID=$$) complete."
183
184 #exec 1>&- # close STDOUT
185 #exec 2>&- # close STDERR
186
187 exit 0