-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprepare.sh
More file actions
executable file
·126 lines (93 loc) · 3.28 KB
/
prepare.sh
File metadata and controls
executable file
·126 lines (93 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
[ "$(whoami)" != "root" ] && echo Please run script as root user && exit
# prepare ssh key authorization
[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod 0700 /root/.ssh
[ ! -f /root/.ssh/id_rsa ] && ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -N ''
[ ! -f /root/.ssh/authorized_keys ] && touch /root/.ssh/authorized_keys && chmod 0600 /root/.ssh/authorized_keys
grep "$(</root/.ssh/id_rsa.pub)" /root/.ssh/authorized_keys -q || cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
# linux version
distro=$(cat /etc/*release | egrep '^ID=' | awk -F= '{print $2}' | tr -d \")
echo $distro detected.
# check python
if [ "$distro" == "centos" ]; then
test -e /usr/bin/python || yum install -y python-minimal
elif [ "$distro" == "ubuntu" ]; then
test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
fi
# docker installation
if [ "$distro" == "centos" ]; then
cat << EOF > /etc/yum.repos.d/docker-ce.repo
[docker-ce-18.03.1.ce]
name=docker-ce-18.03.1.ce repository
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable
enabled=1
EOF
rpm --import https://download.docker.com/linux/centos/gpg
yum install docker-ce-18.03.1.ce -y
elif [ "$distro" == "ubuntu" ]; then
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
wget -qO - https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
codename=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d '=' -f 2)
cat << EOF > /etc/apt/sources.list.d/docker-ce.list
deb https://download.docker.com/linux/ubuntu $codename stable
EOF
apt-get update
apt-get install -y docker-ce=18.03.1~ce-0~ubuntu
else
echo "Unsupported OS version" && exit
fi
# docker launch
function wait_docker () {
# wait docker service is up
for i in {1..10}; do
systemctl status docker > /dev/null
[ $? == 0 ]; break
sleep 2
done
}
[ ! -d /etc/docker ] && mkdir /etc/docker
cat << EOF > /etc/docker/daemon.json
{
"insecure-registries": [
"opencontrailnightly"
]
}
EOF
systemctl enable docker
systemctl start docker
wait_docker
# fix docker configuration for build step
if [ "$DEV_ENV" == "true" ]; then
# detect docker gateway IP
container_registry_ip=$(docker inspect --format "{{(index .IPAM.Config 0).Gateway}}" bridge)
[ "$container_registry_ip" == "" ] && container_registry_ip="172.17.0.1"
cat << EOF > /etc/docker/daemon.json
{
"insecure-registries": [
"$container_registry_ip:6666"
]
}
EOF
cat << EOF > /etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS="--storage-opt dm.basesize=20G"
EOF
systemctl restart docker
wait_docker
fi
# control node image preparation
function is_builded () {
local container=$1
docker image ls -a --format '{{.Repository}}' | grep "$container" > /dev/null
return $?
}
if ! is_builded "contrail-dev-control"; then
docker build -t contrail-dev-control ./container
echo contrail-dev-control created.
fi
# show current node configuration
echo
PHYSICAL_INTERFACE=$(ip route get 1 | grep -o 'dev.*' | awk '{print($2)}')
DEFAULT_NODE_IP=$(ip addr show dev $PHYSICAL_INTERFACE | grep 'inet ' | awk '{print $2}' | head -n 1 | cut -d '/' -f 1)
echo "NODE IP $DEFAULT_NODE_IP"
[ "$DEV_ENV" == "true" ] && echo "BUILD STEP WILL BE INCLUDED"