Merge "Convert tldk to be Packer compliant"
[ci-management.git] / packer / provision / basebuild.sh
1 #!/bin/bash
2
3 # vim: ts=4 sw=4 sts=4 et tw=72 :
4
5 rh_systems() {
6
7     # RH Install build tools
8     echo "---> Installing RH build tools $(date +'%Y%m%dT%H%M%S')"
9     RH_TOOLS_PKGS="@development redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils openssl-devel apr-devel indent"
10     yum install -y ${RH_TOOLS_PKGS}
11
12     # Memory leakage checks
13     yum install -y valgrind
14
15     # RH Install Python dependencies
16     ###REMOVED mysql-devel
17     echo "---> Installing RH Python dependencies $(date +'%Y%m%dT%H%M%S')"
18     RH_PYTHON_PKGS="python-devel python-virtualenv python-setuptools python-pip openssl-devel"
19     yum install -y ${RH_PYTHON_PKGS}
20
21     # RH Install Documentation packages
22     ###Removed python-pyparsing
23     echo "---> Installing RH documentation packages $(date +'%Y%m%dT%H%M%S')"
24     RH_DOC_PKGS="doxygen graphviz python-jinja2 asciidoc dblatex source-highlight python-sphinx"
25     yum install -y install ${RH_DOC_PKGS}
26
27     # RH Install GCC packages
28     echo "---> Installing RH GCC packages $(date +'%Y%m%dT%H%M%S')"
29     RH_GCC_PKGS="cpp gcc c++ cmake"
30     yum install -y ${RH_GCC_PKGS}
31
32     # RH Install components to build Ganglia modules
33     echo "---> Installing RH components $(date +'%Y%m%dT%H%M%S')"
34     RH_GANGLIA_MODS="libconfuse-devel ganglia-devel mock"
35     yum install -y --enablerepo=epel ${RH_GANGLIA_MODS}
36
37     # RH Install module for VPP project
38     echo uio_pci_generic >> /etc/modules
39
40     # RH Install VPP packages to shorten build times
41     echo "---> Installing VPP dependencies $(date +'%Y%m%dT%H%M%S')"
42     RH_VPP_PKGS="curl autoconf automake bison ccache dkms git libtool libconfuse-dev git-review cscope"
43     yum install -y ${RH_VPP_PKGS}
44
45     yum groupinstall "Development Tools"
46     # RH Install TLDK dependencies
47     RH_TLKD_PKGS="libpcap-devel libcap-devel"
48     yum install -y ${RH_TLKD_PKGS}
49
50     # RH Install debuginfo packages
51     #echo "---> Installing debug packages $(date +'%Y%m%dT%H%M%S')"
52     #RH_DEBUG_PKGS="glibc openssl-libs zlib"
53     #debuginfo-install -y ${RH_DEBUG_PKGS}
54
55     # # RH Packer builds happen from the centos flavor images
56     # PACKERDIR=$(mktemp -d)
57     # # disable double quote checking
58     # # shellcheck disable=SC2086
59     # cd $PACKERDIR
60     # wget https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip
61     # unzip packer_0.10.1_linux_amd64.zip -d /usr/local/bin/
62     # # rename packer to avoid conflicts with cracklib
63     # mv /usr/local/bin/packer /usr/local/bin/packer.io
64
65     # # cleanup from the installation
66     # # disable double quote checking
67     # # shellcheck disable=SC2086
68     # rm -rf $PACKERDIR
69     # # cleanup from previous install process
70     # if [ -d /tmp/packer ]
71     # then
72     #     rm -rf /tmp/packer
73     # fi
74 }
75
76 ubuntu_systems() {
77
78     # DEB cloud packages
79     echo "---> Installing cloud packages $(date +'%Y%m%dT%H%M%S')"
80     CLOUD_PKGS="cloud-initramfs-dyn-netconf cloud-initramfs-growroot cloud-initramfs-rescuevol"
81     apt install -y ${CLOUD_PKGS}
82
83     # DEB Install Python dependencies
84     echo "---> Installing Python dependencies $(date +'%Y%m%dT%H%M%S')"
85     PYTHON_PKGS="python-dev python-virtualenv python-setuptools python-pip libssl-dev libmysqlclient-dev python2.7"
86     apt install -y ${PYTHON_PKGS}
87
88     # Memory leakage checks
89     apt install -y valgrind
90
91     # DEB Install Documentation packages
92     echo "---> Installing documentation packages $(date +'%Y%m%dT%H%M%S')"
93     DOC_PKGS="doxygen graphviz python-pyparsing python-jinja2 asciidoc dblatex source-highlight"
94     apt install -y ${DOC_PKGS}
95
96     # DEB Install the correct version of toolchain packages
97     echo "---> Installing latest toolchain packages from PPA $(date +'%Y%m%dT%H%M%S')"
98
99     # DEB Install PPA packages
100     echo "---> Adding '$1' PPA $(date +'%Y%m%dT%H%M%S')"
101     dpkg -l software-properties-common > /dev/null 2>&1 || software-properties-common
102
103     listfile=$(perl -e "print(q{$1} =~ m{^ppa:(.+)/ppa})")-ppa-${CODENAME}.list
104       if [ ! -f /etc/apt/sources.list.d/${listfile} ]
105       then
106         do_retry sudo apt-add-repository -y $1
107       fi
108
109     #Retry to prevent timeout failure
110     echo "---> Updating package index $(date +'%Y%m%dT%H%M%S')"
111     do_retry sudo apt-get update
112     echo "<--- Updating package index $(date +'%Y%m%dT%H%M%S')"
113     echo "<--- Adding '$1' PPA $(date +'%Y%m%dT%H%M%S')"
114
115     # DEB Install GCC packages
116     echo "---> Installing GCC-5 packages $(date +'%Y%m%dT%H%M%S')"
117     GCC_PKGS="cpp gcc g++ cmake"
118     sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
119     sudo apt-get update
120     apt install -y ${GCC_PKGS}
121
122     # DEB Install VPP packages to shorten build times
123     echo "---> Installing VPP DEB_DEPENDS packages $(date +'%Y%m%dT%H%M%S')"
124     VPP_PKGS="curl build-essential autoconf automake bison libssl-dev ccache debhelper dkms git libtool libganglia1-dev libapr1-dev dh-systemd libconfuse-dev git-review exuberant-ctags cscope indent"
125     apt install -y ${VPP_PKGS}
126
127     # DEB Install latest kernel and uio
128     echo "---> Installing kernel image and header packages $(date +'%Y%m%dT%H%M%S')"
129     DEB_PKGS="linux-image-extra-virtual linux-headers-virtual linux-headers-`uname -r`"
130     apt install -y ${DEB_PKGS}
131
132     #Configuring thirdparty Nexus repo
133     echo "deb [trusted=yes] https://nexus.fd.io/content/repositories/thirdparty ./" > /etc/apt/sources.list.d/FD.io.thirdparty.list
134     apt-get update
135
136     # DEB Install deb_dpdk packages to shorten build times
137     ###REMOVED sphinx-rtd-theme
138     echo "---> Installing deb_dpdk packages $(date +'%Y%m%dT%H%M%S')"
139     DEB_DPDK_PKGS="google-mock lsb-release dpkg-dev debian-xcontrol devscripts pristine-tar dh-python python-sphinx libpcap0.8-dev libstdc++5 python-scapy inkscape libxen-dev libxenstore3.0 python-sphinx-rtd-theme"
140     apt install -y ${DEB_DPDK_PKGS}
141
142     sudo apt install -y libcap-dev libpcap-dev
143
144     TEXLIVE_PKGS="texlive-fonts-recommended tex-common texlive-base texlive-binaries texlive-pictures texlive-latex-recommended preview-latex-style texlive-latex-extra"
145     apt install -y ${TEXLIVE_PKGS}
146     echo "<--- Installing deb_dpdk packages $(date +'%Y%m%dT%H%M%S')"
147
148     # DEB Manipulation tools, edits debugger, and LSB
149     echo "---> Installing tools packages $(date +'%Y%m%dT%H%M%S')"
150     TOOL_PKGS="iproute2 ethtool vlan bridge-utils vim gdb lsb-release"
151     apt install -y ${TOOL_PKGS}
152
153     # DEB Clean up packages for a smaller image
154     apt-get update
155
156     # DEB Updating CA certificates
157     echo "---> Forcing CA certificate update $(date +'%Y%m%dT%H%M%S')"
158       sudo update-ca-certificates -f > /dev/null 2>&1
159     echo "<--- Forcing CA certificate update $(date +'%Y%m%dT%H%M%S')"
160 }
161
162 all_systems() {
163
164     echo 'Configure keep alive to prevent timeout during testing'
165     local SSH_CFG=/etc/ssh/ssh_config
166     echo "TCPKeepAlive        true" | sudo tee -a ${SSH_CFG} >/dev/null 2>&1
167     echo "ServerAliveCountMax 30"   | sudo tee -a ${SSH_CFG} >/dev/null 2>&1
168     echo "ServerAliveInterval 10"   | sudo tee -a ${SSH_CFG} >/dev/null 2>&1
169
170 }
171
172 echo "---> Detecting OS"
173 ORIGIN=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
174
175 case "${ORIGIN}" in
176     fedora|centos|redhat)
177         echo "---> RH type system detected"
178         rh_systems
179     ;;
180     ubuntu)
181         echo "---> Ubuntu system detected"
182         ubuntu_systems
183     ;;
184     *)
185         echo "---> Unknown operating system"
186     ;;
187 esac
188
189 # execute steps for all systems
190 all_systems