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