Add bashate verification and fix shell errors
[icn.git] / env / metal3 / 01_install_package.sh
1 #!/usr/bin/env bash
2 set -ex
3
4 LIBDIR="$(dirname "$PWD")"
5
6 source $LIBDIR/lib/common.sh
7 source $LIBDIR/lib/logging.sh
8
9 if [[ $EUID -ne 0 ]]; then
10     echo "This script must be run as root"
11     exit 1
12 fi
13
14 function install_essential_packages {
15     apt-get update
16     apt-get -y install \
17     crudini \
18     curl \
19     dnsmasq \
20     figlet \
21     nmap \
22     patch \
23     psmisc \
24     python-pip \
25     python-requests \
26     python-setuptools \
27     vim \
28     wget \
29     git \
30     software-properties-common
31
32     add-apt-repository ppa:longsleep/golang-backports
33     apt-get update
34     apt-get install golang-go
35 }
36
37 function install_ironic_packages {
38     apt-get update
39     apt-get -y install \
40     jq \
41     nodejs \
42     python-ironicclient \
43     python-ironic-inspector-client \
44     python-lxml \
45     python-netaddr \
46     python-openstackclient \
47     unzip \
48     genisoimage
49
50     if [ "$1" == "offline" ]; then
51     pip install --no-index
52         --find-links=file:$PIP_CACHE_DIR locat yq
53     return
54     fi
55
56     pip install \
57     lolcat \
58     yq
59 }
60
61 function install_docker_packages {
62     apt-get remove docker \
63     docker-engine \
64     docker.io \
65     containerd \
66     runc
67     apt-get update
68     apt-get -y install \
69     apt-transport-https \
70     ca-certificates \
71     curl \
72     gnupg-agent \
73     software-properties-common
74     if [ "$1" != "offline" ]; then
75     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
76     add-apt-repository \
77         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
78         $(lsb_release -cs) \
79         stable"
80     apt-get update
81     fi
82     apt-get -y install docker-ce=18.06.0~ce~3-0~ubuntu
83 }
84
85 function install_podman_packages {
86     if [ "$1" != "offline" ]; then
87         add-apt-repository -y ppa:projectatomic/ppa
88     apt-get update
89     fi
90     apt-get -y install podman
91 }
92
93 function install_kubernetes_packages {
94     if [ "$1" != "offline" ]; then
95     curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
96     bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
97 deb https://apt.kubernetes.io/ kubernetes-xenial main
98 EOF'
99     apt-get update
100     fi
101     apt-get install -y kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00
102     apt-mark hold kubelet kubeadm kubectl
103 }
104
105 install() {
106     install_essential_packages
107     install_ironic_packages $1
108     install_docker_packages $1
109     install_podman_packages $1
110     install_kubernetes_packages $1
111 }
112
113 if ["$1" == "-o"]; then
114     install offline
115     exit 0
116 fi
117
118 install