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