Add jobs for deb_dpdk
[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     # Install for deb_dpdk debian package buiding
146     PACKAGES="$PACKAGES dpkg-dev dh-python inkscape libcap-dev libpcap-dev"
147     PACKAGES="$PACKAGES libxen-dev libxenstore3.0 python-sphinx python-sphinx-rtd-theme"
148     PACKAGES="$PACKAGES texlive-fonts-recommended texlive-latex-extra"
149
150     echo '---> Installing packages'
151     # disable double quoting check
152     # shellcheck disable=SC2086
153     apt-get install ${PACKAGES}
154
155     # Specify documentation packages
156     DOC_PACKAGES="doxygen graphviz python-pyparsing"
157     apt-get install ${DOC_PACKAGES}
158 }
159
160 deb_enable_hugepages() {
161     # Setup for hugepages using sysctl so it persists across reboots
162     AVP="vm.nr_hugepages=1024"
163     sysctl -w ${AVP}
164     echo "${AVP}" >> /etc/sysctl.conf
165
166     mkdir -p /mnt/huge
167     echo "hugetlbfs       /mnt/huge  hugetlbfs       defaults        0 0" >> /etc/fstab
168 }
169
170 deb_mount_hugepages() {
171     mount /mnt/huge
172 }
173
174 deb_reup_certs() {
175     # update CA certificates
176     echo '---> Forcing CA certificate update'
177     update-ca-certificates -f
178 }
179
180 deb_remove_pkgs() {
181     echo '---> Removing unattended-upgrades packge to avoid it locking /var/lib/dpkg/lock'
182     apt-get remove unattended-upgrades
183 }
184
185 deb_disable_apt_systemd_daily() {
186     echo '---> Stopping and disabling apt.systemd.daily to avoid it locking /var/lib/dpkg/lock'
187     if [ -f /usr/bin/systemctl ]
188     then
189         systemctl stop apt.systemd.daily
190         systemctl disable apt.systemd.daily
191     else
192         /etc/init.d/unattended-upgrades stop
193         update-rc.d -f unattended-upgrades remove
194     fi
195 }
196
197 rh_clean_pkgs() {
198     echo '---> Cleaning caches'
199     yum clean all -q
200 }
201
202 rh_update_pkgs() {
203     echo '---> Updating OS'
204     yum upgrade -q -y
205 }
206
207 rh_install_pkgs() {
208     echo '---> Installing tools'
209
210     # Install build tools
211     yum install -q -y @development redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils \
212                       openssl-devel apr-devel indent
213
214     # Specify documentation packages
215     DOC_PACKAGES="doxygen graphviz"
216     yum install -q -y install ${DOC_PACKAGES}
217
218     # Install python development
219     OUTPUT=$(yum search python34-devel 2>&1 | grep 'No matches')
220     if [ -z "$OUTPUT" ]
221     then
222     echo '---> Installing python34-devel'
223         yum install -q -y python34-devel
224     else
225     echo '---> Installing python-devel'
226         yum install -q -y python-devel
227     fi
228
229     echo '---> Configuring EPEL'
230     # Install EPEL
231     OUTPUT=$(rpm -qa epel-release)
232     if [ -z "$OUTPUT" ]
233     then
234         yum install -q -y /vagrant/epel-release-latest-7.noarch.rpm
235     fi
236
237     # Install components to build Ganglia modules
238     yum install -q -y --enablerepo=epel {libconfuse,ganglia}-devel mock
239
240     # Install debuginfo packages
241     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
242 }