Remove unsupported podman container runtime
[icn.git] / env / ubuntu / bootloader-env / 01_bootloader_package_req.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
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         python3-pip python3-requests python3-setuptools vim wget; do
22         apt-get -d install $package -y
23     done
24     update-alternatives --install /usr/bin/python python /usr/bin/python3 1
25     update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
26 }
27
28 function download_container_images {
29     check_docker
30     pushd $CONTAINER_IMAGES_DIR
31     #docker images for Kubernetes
32     for images in kube-apiserver kube-controller-manager kube-scheduler kube-proxy; do
33     docker pull k8s.gcr.io/$images:v1.15.0;
34     docker save --output $images.tar k8s.gcr.io/$images;
35     done
36
37     docker pull k8s.gcr.io/pause:3.1
38     docker save --output pause.tar k8s.gcr.io/pause
39
40     docker pull k8s.gcr.io/etcd:3.3.10
41     docker save --output etcd.tar k8s.gcr.io/etcd
42
43     docker pull k8s.gcr.io/coredns:1.3.1
44     docker save --output coredns.tar k8s.gcr.io/coredns
45
46     popd
47 }
48
49 function download_build_packages {
50     check_curl
51     pushd $BUILD_DIR
52     if [ ! -f ironic-python-agent.initramfs ]; then
53     curl --insecure --compressed \
54         -L https://images.rdoproject.org/train/rdo_trunk/current-tripleo/ironic-python-agent.tar | tar -xf -
55     fi
56
57     if [[ "$BM_IMAGE_URL" && "$BM_IMAGE" ]]; then
58     curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
59     md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum
60     fi
61
62     if [ ! -d baremetal-operator ]; then
63     git clone https://github.com/metal3-io/baremetal-operator.git
64     pushd ./baremetal-operator
65     git checkout -b icn_baremetal_operator 11ea02ab5cab8b3ab14972ae7c0e70206bba00b5
66     popd
67     fi
68
69     if [ ! -d ironic-inspector-image ]; then
70     git clone https://github.com/metal3-io/ironic-inspector-image.git
71     pushd ./ironic-inspector-image
72     git checkout -b icn_ironic_inspector_image 25431bd5b7fc87c6f3cfb8b0431fe66b86bbab0e
73     popd
74     fi
75
76     if [ ! -d ironic-image ]; then
77     git clone https://github.com/metal3-io/ironic-image.git
78     pushd ./ironic-image
79     git checkout -b icn_ironic_image 329eb4542f0d8d0f0e9cf0d7e550e33b07efe7fb
80     popd
81     fi
82 }
83
84 function check_pip {
85     if ! which pip ; then
86         apt-get install python3-pip -y
87     fi
88     update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
89 }
90
91 function check_curl {
92     if ! which curl ; then
93         apt-get install curl -y
94     fi
95 }
96
97 function check_apt_tools {
98     if ! which add-apt-repository ; then
99     apt-get install software-properties-common -y
100     fi
101 }
102
103 function download_ironic_packages {
104     for package in jq nodejs python3-ironicclient \
105         python3-ironic-inspector-client python3-lxml python3-netaddr \
106         python3-openstackclient unzip genisoimage; do
107         apt-get -d install $package -y
108     done
109
110     check_pip
111     pip download lolcat yq -d $PIP_CACHE_DIR
112 }
113
114 function check_docker {
115     if which docker ; then
116     return
117     fi
118
119     apt-get remove -y docker \
120         docker-engine \
121         docker.io \
122         containerd \
123         runc \
124         docker-ce
125     apt-get update
126     for package in apt-transport-https ca-certificates gnupg-agent \
127             software-properties-common; do
128         apt-get -d install $package -y
129     done
130
131     check_curl
132     check_apt_tools
133     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
134     add-apt-repository \
135         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
136         $(lsb_release -cs) \
137         stable"
138     apt-get update
139     apt-get install docker-ce=19.03.15~3-0~ubuntu-bionic -y
140 }
141
142 function download_docker_packages {
143     apt-get remove -y docker \
144         docker-engine \
145         docker.io \
146         containerd \
147         runc \
148     docker-ce
149     apt-get update
150     for package in apt-transport-https ca-certificates gnupg-agent \
151         software-properties-common; do
152         apt-get -d install $package -y
153     done
154
155     check_curl
156     check_apt_tools
157     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
158     add-apt-repository \
159         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
160         $(lsb_release -cs) \
161         stable"
162     apt-get update
163     apt-get -d install docker-ce=19.03.15~3-0~ubuntu-bionic -y
164 }
165
166 function download_kubernetes_packages {
167     curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
168     bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
169 deb https://apt.kubernetes.io/ kubernetes-xenial main
170 EOF'
171     apt-get update
172     apt-get install -d kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00 -y
173 }
174
175 function clean_apt_cache {
176     pushd /var/cache/apt/archives
177
178     if [ $(ls -1q . | wc -l ) -ge 3 ]; then
179         $(rm !("lock"|"partial"))
180     fi
181     popd
182
183 }
184
185 function mv_apt_cache {
186     pushd /var/cache/apt/archives
187
188     if [ $(ls -1q . | wc -l ) -gt 2 ]; then
189         $(mv !("lock"|"partial") $LOCAL_APT_REPO)
190     fi
191     popd
192 }
193
194 function check_dir {
195     if [ ! -d $1 ]; then
196         mkdir -p $1
197     fi
198 }
199
200 function clean_dir {
201     pushd $1
202
203     if [ $(ls -1q . | wc -l ) -ne 0 ]; then
204         $(rm -r ./*)
205     fi
206     popd
207 }
208
209 clean_apt_cache
210 check_dir $LOCAL_APT_REPO
211 clean_dir $LOCAL_APT_REPO
212 check_dir $PIP_CACHE_DIR
213 clean_dir $PIP_CACHE_DIR
214 check_dir $BUILD_DIR
215 clean_dir $BUILD_DIR
216 check_dir $CONTAINER_IMAGES_DIR
217 clean_dir $CONTAINER_IMAGES_DIR
218 download_essential_packages
219 download_ironic_packages
220 download_docker_packages
221 download_kubernetes_packages
222 download_build_packages
223 download_container_images
224 mv_apt_cache