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