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