71fa0625d043f050c8a40508861a5af3ac665166
[ci-management.git] / vagrant / lib / bootstrap-functions.sh
1 #!/bin/bash
2
3 do_setup() {
4     echo "127.0.1.1 $(hostname) # temporary" >> /etc/hosts
5 }
6
7 do_mvn_install() {
8     MAVEN_VERSION=3.3.9
9     MAVEN_FILENAME=apache-maven-${MAVEN_VERSION}-bin.tar.gz
10     MAVEN_HOME=/opt/apache/maven
11
12     mkdir -p ${MAVEN_HOME}
13     tar -C ${MAVEN_HOME} --strip-components 1 -xzf /vagrant/${MAVEN_FILENAME}
14 }
15
16
17 do_cleanup() {
18     perl -i -ne 'print unless /^127.0.1.1.*# temporary$/' /etc/hosts
19 }
20
21 deb_probe_modules() {
22     for mod in "$@"
23     do
24         modprobe ${mod}
25     done
26 }
27
28 deb_enable_modules() {
29     for mod in "$@"
30     do
31     echo ${mod} >> /etc/modules
32     done
33 }
34
35 deb_aptconf_batchconf() {
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 quiet "2";
52
53 EOF
54 }
55
56 deb_sync_minor() {
57     echo '---> Updating OS'
58     # Standard update + upgrade dance
59     apt-get update
60     apt-get upgrade
61     apt-get dist-upgrade
62 }
63
64 deb_correct_shell() {
65     echo '---> Correcting system shell'
66     # Fix the silly notion that /bin/sh should point to dash by pointing it to bash
67     update-alternatives --install /bin/sh sh /bin/bash 100
68 }
69
70 deb_flush() {
71     echo '---> Flushing extra packages and package cache'
72     apt-get autoremove
73     apt-get clean
74 }
75
76 deb_add_ppa() {
77     echo "---> Adding '$1' PPA"
78     apt-get install software-properties-common
79     ATTEMPT=0
80     while [ ${ATTEMPT} -le 4 ]
81     do
82         FAIL=0
83         apt-add-repository -y $1 || FAIL=1
84         if [ ${FAIL} -eq 0 ]
85         then
86             break
87         fi
88         ATTEMPT=$(expr $ATTEMPT + 1)
89     done
90     apt-get update
91 }
92
93 deb_install_pkgs() {
94     apt-get install lsb-release
95     LSB_PATH=$(which lsb_release)
96
97     VERSION=$(lsb_release -r | awk '{print $2}')
98     DIST=$(lsb_release -i | awk '{print $3}')
99     CODENAME=$(lsb_release -c | awk '{print $2}')
100
101     echo "---> Detected [${DIST} v${VERSION} (${CODENAME})]"
102
103     # initialize PACKAGES
104     PACKAGES="cloud-initramfs-dyn-netconf cloud-initramfs-growroot
105               cloud-initramfs-rescuevol"
106
107     if [ "$VERSION" = '14.04' ]
108     then
109         # openjdk-8-jdk is not available in 14.04 repos by default
110           deb_add_ppa ppa:openjdk-r/ppa
111
112         # Install OpenJDK v8 *and* v7 on Trusty
113         PACKAGES="$PACKAGES openjdk-8-jdk-headless openjdk-7-jdk emacs24-nox"
114     elif [ "$VERSION" = '16.04' ]
115     then
116         # Install default jdk (v8 on this platform)
117         PACKAGES="$PACKAGES default-jdk-headless emacs-nox"
118
119           # plymouth-label and plymouth-themes are required to get rid of
120         # initrd warnings / errors on 16.04
121           apt-get install plymouth-themes plymouth-label
122     fi
123
124     # Build tools - should match vpp/Makefile DEB_DEPENDS variable
125     PACKAGES="$PACKAGES curl build-essential autoconf automake bison libssl-dev
126               ccache debhelper dkms git libtool libganglia1-dev libapr1-dev
127               dh-systemd libconfuse-dev git-review exuberant-ctags cscope indent"
128
129     # Interface manipulation tools, editors, debugger and lsb
130     PACKAGES="$PACKAGES iproute2 ethtool vlan bridge-utils
131               vim gdb lsb-release"
132
133     # Install latest kernel and uio
134     PACKAGES="$PACKAGES linux-image-extra-virtual linux-headers-virtual"
135
136     # $$$ comment out for the moment
137     # PACKAGES="$PACKAGES maven3"
138
139     # Install virtualenv for test execution
140     PACKAGES="$PACKAGES python-virtualenv python-pip python-dev"
141
142     # Install to allow the vpp-docs job to zip up docs to push them
143     PACKAGES="$PACKAGES zip"
144
145     echo '---> Installing packages'
146     # disable double quoting check
147     # shellcheck disable=SC2086
148     apt-get install ${PACKAGES}
149
150     # Specify documentation packages
151     DOC_PACKAGES="doxygen graphviz python-pyparsing"
152     apt-get install ${DOC_PACKAGES}
153 }
154
155 deb_enable_hugepages() {
156     # Setup for hugepages using sysctl so it persists across reboots
157     AVP="vm.nr_hugepages=1024"
158     sysctl -w ${AVP}
159     echo "${AVP}" >> /etc/sysctl.conf
160
161     mkdir -p /mnt/huge
162     echo "hugetlbfs       /mnt/huge  hugetlbfs       defaults        0 0" >> /etc/fstab
163 }
164
165 deb_mount_hugepages() {
166     mount /mnt/huge
167 }
168
169 deb_reup_certs() {
170     # update CA certificates
171     echo '---> Forcing CA certificate update'
172     update-ca-certificates -f
173 }
174
175 deb_remove_pkgs() {
176     echo '---> Removing unattended-upgrades packge to avoid it locking /var/lib/dpkg/lock'
177     apt-get remove unattended-upgrades
178 }
179
180 deb_disable_apt_systemd_daily() {
181     echo '---> Stopping and disabling apt.systemd.daily to avoid it locking /var/lib/dpkg/lock'
182     if [ -f /usr/bin/systemctl ]
183     then
184         systemctl stop apt.systemd.daily
185         systemctl disable apt.systemd.daily
186     else
187         /etc/init.d/unattended-upgrades stop
188         update-rc.d -f unattended-upgrades remove
189     fi
190 }
191
192 rh_clean_pkgs() {
193     echo '---> Cleaning caches'
194     yum clean all -q
195 }
196
197 rh_update_pkgs() {
198     echo '---> Updating OS'
199     yum upgrade -q -y
200 }
201
202 rh_install_pkgs() {
203     echo '---> Installing tools'
204
205     # Install build tools
206     yum install -q -y @development redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils \
207                       openssl-devel apr-devel indent
208
209     # Specify documentation packages
210     DOC_PACKAGES="doxygen graphviz"
211     yum install -q -y install ${DOC_PACKAGES}
212
213     # Install python development
214     OUTPUT=$(yum search python34-devel 2>&1 | grep 'No matches')
215     if [ -z "$OUTPUT" ]
216     then
217     echo '---> Installing python34-devel'
218         yum install -q -y python34-devel
219     else
220     echo '---> Installing python-devel'
221         yum install -q -y python-devel
222     fi
223
224     echo '---> Configuring EPEL'
225     # Install EPEL
226     OUTPUT=$(rpm -qa epel-release)
227     if [ -z "$OUTPUT" ]
228     then
229         yum install -q -y /vagrant/epel-release-latest-7.noarch.rpm
230     fi
231
232     # Install components to build Ganglia modules
233     yum install -q -y --enablerepo=epel {libconfuse,ganglia}-devel mock
234
235     # Install debuginfo packages
236     debuginfo-install -q -y glibc-2.17-106.el7_2.4.x86_64 openssl-libs-1.0.1e-51.el7_2.4.x86_64 zlib-1.2.7-15.el7.x86_64
237 }