9a6067818667eb7f25d72142f8f845c97f744205
[ci-management.git] /
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     sysctl -w vm.nr_hugepages=1024
158
159     mkdir -p /mnt/huge
160     echo "hugetlbfs       /mnt/huge  hugetlbfs       defaults        0 0" >> /etc/fstab
161 }
162
163 deb_mount_hugepages() {
164     mount /mnt/huge
165 }
166
167 deb_reup_certs() {
168     # update CA certificates
169     echo '---> Forcing CA certificate update'
170     update-ca-certificates -f
171 }
172
173 deb_remove_pkgs() {
174     echo '---> Removing unattended-upgrades packge to avoid it locking /var/lib/dpkg/lock'
175     apt-get remove unattended-upgrades
176 }
177
178 deb_disable_apt_systemd_daily() {
179     echo '---> Stopping and disabling apt.systemd.daily to avoid it locking /var/lib/dpkg/lock'
180     if [ -f /usr/bin/systemctl ]
181     then
182         systemctl stop apt.systemd.daily
183         systemctl disable apt.systemd.daily
184     else
185         /etc/init.d/unattended-upgrades stop
186         update-rc.d -f unattended-upgrades remove
187     fi
188 }
189
190 rh_clean_pkgs() {
191     echo '---> Cleaning caches'
192     yum clean all -q
193 }
194
195 rh_update_pkgs() {
196     echo '---> Updating OS'
197     yum upgrade -q -y
198 }
199
200 rh_install_pkgs() {
201     echo '---> Installing tools'
202
203     # Install build tools
204     yum install -q -y @development redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils \
205                       openssl-devel apr-devel indent
206
207     # Specify documentation packages
208     DOC_PACKAGES="doxygen graphviz"
209     yum install -q -y install ${DOC_PACKAGES}
210
211     # Install python development
212     OUTPUT=$(yum search python34-devel 2>&1 | grep 'No matches')
213     if [ -z "$OUTPUT" ]
214     then
215     echo '---> Installing python34-devel'
216         yum install -q -y python34-devel
217     else
218     echo '---> Installing python-devel'
219         yum install -q -y python-devel
220     fi
221
222     echo '---> Configuring EPEL'
223     # Install EPEL
224     OUTPUT=$(rpm -qa epel-release)
225     if [ -z "$OUTPUT" ]
226     then
227         yum install -q -y /vagrant/epel-release-latest-7.noarch.rpm
228     fi
229
230     # Install components to build Ganglia modules
231     yum install -q -y --enablerepo=epel {libconfuse,ganglia}-devel mock
232
233     # Install debuginfo packages
234     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
235 }