652160e06aeb6de66fa7a8ad9cf42d552dabd520
[ci-management.git] / vagrant / lib / bootstrap-functions.sh
1 #!/bin/bash
2
3 deb_enable_serial_console() {
4 # enable grub and login on serial console
5
6     echo <<EOF>> /etc/default/grub
7 GRUB_TERMINAL=serial
8 GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"
9 EOF
10     update-grub
11 }
12
13 deb_probe_modules() {
14     for mod in "$@"
15     do
16         modprobe ${mod}
17     done
18 }
19
20 deb_enable_modules() {
21     for mod in "$@"
22     do
23         echo ${mod} >> /etc/modules
24     done
25 }
26
27 deb_aptconf_batchconf() {
28     cat <<EOF >> /etc/apt/apt.conf
29 APT {
30   Get {
31     Assume-Yes "true";
32     allow-change-held-packages "true";
33     allow-downgrades "true";
34     allow-remove-essential "true";
35   };
36 };
37
38 Dpkg::Options {
39    "--force-confdef";
40    "--force-confold";
41 };
42
43 EOF
44 }
45
46 deb_sync_minor() {
47     echo '---> Updating OS'
48     # Standard update + upgrade dance
49     apt-get -qq update
50     apt-get -qq upgrade
51     apt-get -qq 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 -qq autoremove
63     apt-get -qq clean
64 }
65
66 deb_add_ppa() {
67     echo "---> Adding '$1' PPA"
68     apt-get -qq install software-properties-common
69     apt-add-repository -y $1
70     apt-get -qq update
71 }
72
73 deb_install_pkgs() {
74     LSB_PATH=$(which lsb_release)
75
76     if [ $? == 0 ]
77     then
78         VERSION=$(lsb_release -r | awk '{print $2}')
79         DIST=$(lsb_release -i | awk '{print $3}')
80         CODENAME=$(lsb_release -c | awk '{print $2}')
81     else
82         ISSUE_TXT=$(head -1 /etc/issue)
83         DIST=$(echo "${ISSUE_TXT}" | awk '{print $1}')
84         if [ "$DIST" = "Ubuntu" ]
85         then
86             VERSION=$(echo "${ISSUE_TXT}" | awk '{print $2}' | sed -e 's/^(\d+\.\d+)(\.\d+)?$/\1/')
87         elif [ "$DIST" = "Debian" ]
88         then
89             VERSION=$(echo "${ISSUE_TXT}" | awk '{print $3}')
90         else
91             echo "Unrecognized distribution: ${DIST}"
92         fi
93     fi
94
95     echo "---> Detected [${DIST} v${VERSION} (${CODENAME})]"
96
97     PACKAGES="" # initialize PACKAGES
98     if [ "$VERSION" = '14.04' ]
99     then
100         # openjdk-8-jdk is not available in 14.04 repos by default
101         deb_add_ppa ppa:openjdk-r/ppa
102
103         # Install OpenJDK v8 and v7
104         PACKAGES="$PACKAGES openjdk-8-jdk-headless openjdk-7-jdk"
105     else
106         # Install default jdk
107         PACKAGES="$PACKAGES default-jdk-headless"
108
109         # Install plymouth label and themes to get rid of initrd warnings / errors
110         apt-get -qq install plymouth-themes plymouth-label
111     fi
112
113     # Install build tools - should match vpp/Makefile DEB_DEPENDS variable
114     PACKAGES="$PACKAGES curl build-essential autoconf automake bison libssl-dev ccache"
115     PACKAGES="$PACKAGES debhelper dkms git libtool libganglia1-dev libapr1-dev dh-systemd"
116     PACKAGES="$PACKAGES libconfuse-dev git-review exuberant-ctags cscope"
117
118
119     # Install interface manipulation tools, editor, debugger and lsb
120     PACKAGES="$PACKAGES iproute2 bridge-utils vim gdb lsb-release"
121
122     # Install latest kernel and uio
123     PACKAGES="$PACKAGES linux-image-extra-virtual linux-headers-virtual"
124
125     # $$$ comment out for the moment
126     # PACKAGES="$PACKAGES maven3"
127
128     # Install virtualenv for test execution
129     PACKAGES="$PACKAGES python-virtualenv python-pip python-dev"
130
131     echo '---> Installing packages'
132     # disable double quoting check
133     # shellcheck disable=SC2086
134     apt-get -qq install ${PACKAGES}
135
136 }
137
138 deb_enable_hugepages() {
139     # Setup for hugepages using sysctl so it persists across reboots
140     sysctl -w vm.nr_hugepages=1024
141
142     mkdir -p /mnt/huge
143     echo "hugetlbfs       /mnt/huge  hugetlbfs       defaults        0 0" >> /etc/fstab
144 }
145
146 deb_mount_hugepages() {
147     mount /mnt/huge
148 }
149
150 deb_reup_certs() {
151     # update CA certificates
152     echo '---> Forcing CA certificate update'
153     update-ca-certificates -f
154 }
155
156 rh_clean_pkgs() {
157     echo '---> Cleaning caches'
158     yum clean all -q
159 }
160
161 rh_update_pkgs() {
162     echo '---> Updating OS'
163     yum upgrade -q -y
164 }
165
166 rh_install_pkgs() {
167     echo '---> Installing tools'
168
169     # Install build tools
170     yum install -q -y @development redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils \
171                       openssl-devel apr-devel
172
173     # Install python development
174     yum search python34-devel 2>&1 | grep -q 'No matches'
175     if [ $? -eq 0 ]
176     then
177         echo '---> Installing python-devel'
178         yum install -q -y python-devel
179     else
180         echo '---> Installing python34-devel'
181         yum install -q -y python34-devel
182     fi
183
184     echo '---> Configuring EPEL'
185     # Install EPEL
186     yum install -q -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
187
188     # Install components to build Ganglia modules
189     yum install -q -y --enablerepo=epel {libconfuse,ganglia}-devel mock
190
191     # Install debuginfo packages
192     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
193 }