Update to python3
[icn.git] / env / metal3 / 01_install_package.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
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     python3-pip \
25     python3-requests \
26     python3-setuptools \
27     vim \
28     wget \
29     git \
30     software-properties-common \
31     bridge-utils
32
33     update-alternatives --install /usr/bin/python python /usr/bin/python3 1
34     update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
35
36     add-apt-repository -y ppa:longsleep/golang-backports
37     apt-get update
38     apt-get install golang-go -y
39 }
40
41 function install_ironic_packages {
42     apt-get update
43     apt-get -y install \
44     jq \
45     nodejs \
46     python3-ironicclient \
47     python3-ironic-inspector-client \
48     python3-lxml \
49     python3-netaddr \
50     python3-openstackclient \
51     unzip \
52     genisoimage \
53     whois
54
55     if [ "$1" == "offline" ]; then
56     pip install --no-index
57         --find-links=file:$PIP_CACHE_DIR locat yq
58     return
59     fi
60
61     pip install \
62     lolcat \
63     yq
64 }
65
66 function install_docker_packages {
67     apt-get remove docker \
68     docker-engine \
69     docker.io \
70     containerd \
71     runc
72     apt-get update
73     apt-get -y install \
74     apt-transport-https \
75     ca-certificates \
76     curl \
77     gnupg-agent \
78     software-properties-common
79     if [ "$1" != "offline" ]; then
80     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
81     add-apt-repository \
82         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
83         $(lsb_release -cs) \
84         stable"
85     apt-get update
86     fi
87     apt-get -y install docker-ce=18.06.0~ce~3-0~ubuntu
88 }
89
90 function install_podman_packages {
91     if [ "$1" != "offline" ]; then
92         add-apt-repository -y ppa:projectatomic/ppa
93     apt-get update
94     fi
95     apt-get -y install podman
96 }
97
98 function install_kubernetes_packages {
99     if [ "$1" != "offline" ]; then
100     curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
101     bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
102 deb https://apt.kubernetes.io/ kubernetes-xenial main
103 EOF'
104     apt-get update
105     fi
106     apt-get install -y kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00
107     apt-mark hold kubelet kubeadm kubectl
108 }
109
110 install() {
111     install_essential_packages
112     install_ironic_packages $1
113
114     #install_docker_packages $1
115     #install_podman_packages $1
116     #install_kubernetes_packages $1
117 }
118
119 if [ "$#" -eq 0 ]; then
120     install online
121 elif [ "$1" == "-o" ]; then
122     install offline
123 else
124     exit 1
125 fi