adding inital packages for bootstrap cluster
[icn.git] / env / ubuntu / bootloader-env / 01_bootloader_package_req.sh
1 #!/usr/bin/env bash
2 set -ex
3 shopt -s extglob
4
5 source $(dirname $PWD)/../lib/common.sh
6 source $(dirname $PWD)/../lib/logging.sh
7
8 if [[ $EUID -ne 0 ]]; then
9     echo "This script must be run as root"
10     exit 1
11 fi
12
13 if [[ $(lsb_release -d | cut -f2) != $UBUNTU_BIONIC ]]; then
14     echo "Currently Ubuntu 18.04.2 LTS is only supported"
15     exit 1
16 fi
17
18 function download_essential_packages() {
19     apt-get update
20         for package in crudini curl dnsmasq figlet golang nmap patch psmisc \
21                         python-pip python-requests python-setuptools vim wget; do
22         apt-get -d install $package -y
23         done
24 }
25
26 function build_baremetal_operator_images() {
27         if [ ! -d "$BUILD_DIR/baremetal-operator"]; then
28                 return
29         fi
30
31         pushd $BUILD_DIR/baremetal-operator
32         docker build -t $IRONIC_BAREMETAL_IMAGE . -f build/Dockerfile
33         docker save --output \
34                 $CONTAINER_IMAGES_DIR/baremetal-operator.tar $IRONIC_BAREMETAL_IMAGE
35         popd
36
37         docker pull $IRONIC_BAREMETAL_SOCAT_IMAGE
38         docker save --output $CONTAINER_IMAGES_DIR/socat.tar $IRONIC_BAREMETAL_SOCAT_IMAGE
39 }
40
41 function build_ironic_images() {
42         for images in ironic-image ironic-inspector-image; do
43                 if [ -d "$BUILD_DIR/$images" ]; then
44                         pushd $BUILD_DIR/$images
45                         podman build -t $images .
46                         popd
47                 fi
48         done
49
50         if podman images -q localhost/ironic-inspector-image ; then
51                 podman tag localhost/ironic-inspector-image $IRONIC_INSPECTOR_IMAGE
52                 podman save --output \
53                         $CONTAINER_IMAGES_DIR/ironic-inspector-image.tar \
54                         $IRONIC_INSPECTOR_IMAGE
55         fi
56
57         if podman images -q localhost/ironic-image ; then
58         podman tag localhost/ironic-inspector-image $IRONIC_IMAGE
59                 podman save --output $CONTAINER_IMAGES_DIR/ironic-image.tar \
60                         $IRONIC_IMAGE
61     fi
62         
63         podman pull k8s.gcr.io/pause:3.1
64         podman save --output $CONTAINER_IMAGES_DIR/podman-pause.tar \
65                 k8s.gcr.io/pause:3.1
66
67         #build_baremetal_operator_images
68 }
69
70
71 function download_container_images() {
72         check_docker
73         pushd $CONTAINER_IMAGES_DIR
74         #docker images for Kubernetes
75         for images in kube-apiserver kube-controller-manager kube-scheduler kube-proxy; do
76                 docker pull k8s.gcr.io/$images:v1.15.0; 
77                 docker save --output $images.tar k8s.gcr.io/$images;
78         done
79
80         docker pull k8s.gcr.io/pause:3.1
81         docker save --output pause.tar k8s.gcr.io/pause
82
83         docker pull k8s.gcr.io/etcd:3.3.10
84         docker save --output etcd.tar k8s.gcr.io/etcd
85
86         docker pull k8s.gcr.io/coredns:1.3.1
87         docker save --output coredns.tar k8s.gcr.io/coredns
88
89         #podman images for Ironic
90         check_podman
91         build_ironic_images
92         #podman pull $IRONIC_IMAGE 
93         #podman save --output ironic.tar $IRONIC_IMAGE
94         #podman pull $IRONIC_INSPECTOR_IMAGE 
95         #podman save --output ironic-inspector.tar $IRONIC_INSPECTOR_IMAGE
96         popd
97 }
98
99 function download_build_packages() {
100         check_curl
101         pushd $BUILD_DIR
102         if [ ! -f ironic-python-agent.initramfs ]; then
103                 curl --insecure --compressed \
104                         -L https://images.rdoproject.org/master/rdo_trunk/current-tripleo-rdo/ironic-python-agent.tar | tar -xf -
105         fi
106
107         if [[ "$BM_IMAGE_URL" && "$BM_IMAGE" ]]; then
108                 curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
109                 md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum
110     fi
111
112         if [ ! -f 87-podman-bridge.conflist ]; then
113                 curl --insecure --compressed -O -L $PODMAN_CNI_CONFLIST
114         fi
115
116         if [ ! -d baremetal-operator ]; then
117                 git clone https://github.com/metal3-io/baremetal-operator.git
118                 pushd ./baremetal-operator
119                 git checkout -b icn_baremetal_operator 11ea02ab5cab8b3ab14972ae7c0e70206bba00b5
120                 popd
121         fi
122
123         if [ ! -d ironic-inspector-image ]; then
124                 git clone https://github.com/metal3-io/ironic-inspector-image.git
125                 pushd ./ironic-inspector-image
126                 git checkout -b icn_ironic_inspector_image 25431bd5b7fc87c6f3cfb8b0431fe66b86bbab0e
127                 popd
128         fi
129
130         if [ ! -d ironic-image ]; then
131                 git clone https://github.com/metal3-io/ironic-image.git
132                 pushd ./ironic-image
133                 git checkout -b icn_ironic_image 329eb4542f0d8d0f0e9cf0d7e550e33b07efe7fb
134                 popd
135         fi
136 }
137
138 function check_pip() {
139         if ! which pip ; then
140                 apt-get install python-pip -y
141         fi
142 }
143
144 function check_curl() {
145         if ! which curl ; then
146         apt-get install curl -y
147     fi
148 }
149
150 function check_apt_tools() {
151         if ! which add-apt-repository ; then
152                 apt-get install software-properties-common -y
153         fi
154 }
155
156 function download_ironic_packages() {
157         for package in jq nodejs python-ironicclient \
158                         python-ironic-inspector-client python-lxml python-netaddr \
159                         python-openstackclient unzip genisoimage; do
160         apt-get -d install $package -y
161         done
162         
163         check_pip    
164     pip download lolcat yq -d $PIP_CACHE_DIR
165 }
166
167 function check_docker() {
168         if which docker ; then
169                 return
170         fi
171
172     apt-get remove -y docker \
173         docker-engine \
174         docker.io \
175         containerd \
176         runc \
177         docker-ce
178     apt-get update
179     for package in apt-transport-https ca-certificates gnupg-agent \
180             software-properties-common; do
181         apt-get -d install $package -y
182     done
183
184     check_curl
185     check_apt_tools
186     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
187     add-apt-repository \
188         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
189         $(lsb_release -cs) \
190         stable"
191     apt-get update
192     apt-get install docker-ce=18.06.0~ce~3-0~ubuntu -y
193 }
194
195 function check_podman() {
196         if which podman; then
197                 return
198         fi
199
200     add-apt-repository -y ppa:projectatomic/ppa
201         apt-get update
202     apt-get install podman -y
203 }
204
205 function download_docker_packages() {
206     apt-get remove -y docker \
207         docker-engine \
208         docker.io \
209         containerd \
210         runc \
211                 docker-ce
212     apt-get update
213         for package in apt-transport-https ca-certificates gnupg-agent \
214                         software-properties-common; do
215         apt-get -d install $package -y
216         done
217
218         check_curl
219         check_apt_tools
220     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
221     add-apt-repository \
222         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
223         $(lsb_release -cs) \
224         stable"
225     apt-get update
226     apt-get -d install docker-ce=18.06.0~ce~3-0~ubuntu -y
227 }
228
229 function download_podman_packages() {
230     apt-get update
231     add-apt-repository -y ppa:projectatomic/ppa
232     apt-get -d install podman -y
233 }
234
235 function download_kubernetes_packages() {
236    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
237    bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
238 deb https://apt.kubernetes.io/ kubernetes-xenial main
239 EOF'
240    apt-get update
241    apt-get install -d kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00 -y
242 }
243
244 function clean_apt_cache() {
245         pushd /var/cache/apt/archives
246
247         if [ $(ls -1q . | wc -l ) -ge 3 ]; then
248         $(rm !("lock"|"partial"))
249         fi
250         popd
251         
252 }
253
254 function mv_apt_cache() {
255     pushd /var/cache/apt/archives
256
257     if [ $(ls -1q . | wc -l ) -gt 2 ]; then
258         $(mv !("lock"|"partial") $LOCAL_APT_REPO)
259     fi
260     popd
261 }
262
263 function check_dir() {
264     if [ ! -d $1 ]; then
265         mkdir -p $1
266     fi
267 }
268
269 function clean_dir() {
270     pushd $1
271
272     if [ $(ls -1q . | wc -l ) -ne 0 ]; then
273         $(rm -r ./*)
274     fi
275     popd
276 }
277
278 clean_apt_cache
279 check_dir $LOCAL_APT_REPO 
280 clean_dir $LOCAL_APT_REPO 
281 check_dir $PIP_CACHE_DIR
282 clean_dir $PIP_CACHE_DIR
283 check_dir $BUILD_DIR
284 clean_dir $BUILD_DIR
285 check_dir $CONTAINER_IMAGES_DIR
286 clean_dir $CONTAINER_IMAGES_DIR
287 download_essential_packages
288 download_ironic_packages
289 download_docker_packages
290 download_podman_packages
291 download_kubernetes_packages
292 download_build_packages
293 download_container_images
294 mv_apt_cache