-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbootstrap.sh
executable file
·113 lines (92 loc) · 3.47 KB
/
bootstrap.sh
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
#!/bin/bash
# shellcheck disable=SC2086
# vim: et sw=2 ts=2
# Copyright 2021 Contributors to the EdgeNet project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu
# To override one of these settings, set the appropriate environment variable.
# For example: `export EDGENET_ASK_CONFIRMATION=0`.
# Whether to ask to continue or not.
EDGENET_ASK_CONFIRMATION="${EDGENET_ASK_CONFIRMATION:-1}"
# Name of the playbook to run.
EDGENET_PLAYBOOK="${EDGENET_PLAYBOOK:-edgenet-node.yml}"
# Which branch of the node repository to use.
EDGENET_REF="${EDGENET_REF:-main}"
# URL of the Git repository containing the playbook to run.
EDGENET_REPOSITORY="${EDGENET_REPOSITORY:-https://github.com/EdgeNet-project/node.git}"
# If the shell is non-interactive, do not ask for confirmation.
# See https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html.
case "$-" in
*i*) ;;
*) EDGENET_ASK_CONFIRMATION=0 ;;
esac
echo -e "\033[1mWelcome to EdgeNet! (https://edge-net.org/)\033[0m"
echo -e "This script will install Ansible, and download and run the EdgeNet node playbook."
echo -e "In case of problem, contact \033[1medgenet-support@planet-lab.eu\033[0m."
echo
echo -e "\033[1mPress Enter to continue, or CTRL+C to exit...\033[0m"
[ "${EDGENET_ASK_CONFIRMATION}" -eq 1 ] && read -r _
is_not_installed() {
! command -v "$1" >/dev/null 2>&1
}
# Do not use sudo if not installed.
SUDO="sudo"
is_not_installed sudo && SUDO=""
# OS-specific variables.
ID="Unknown"
VERSION_ID="Unknown"
if [ -f /etc/os-release ]; then
. /etc/os-release
fi
# Run sudo once to avoid asking for the password later.
${SUDO} true
# Install Ansible and git if not present.
if is_not_installed ansible || is_not_installed git; then
echo "Installing Ansible..."
case "${ID}-${VERSION_ID}" in
centos-*)
${SUDO} yum install --assumeyes --quiet epel-release
${SUDO} yum install --assumeyes --quiet ansible git
;;
fedora-*)
${SUDO} dnf install --assumeyes --quiet ansible git
;;
ubuntu-1*)
export DEBIAN_FRONTEND=noninteractive
${SUDO} apt update --quiet
${SUDO} apt install --quiet --yes --fix-broken
${SUDO} apt install --quiet --yes dirmngr software-properties-common
${SUDO} apt-add-repository --yes --update ppa:ansible/ansible
${SUDO} apt install --quiet --yes ansible git
;;
ubuntu-2*)
export DEBIAN_FRONTEND=noninteractive
${SUDO} apt update --quiet
${SUDO} apt install --quiet --yes --fix-broken
${SUDO} apt install --quiet --yes ansible git
;;
*)
echo "Unsupported operating system: ${ID}-${VERSION_ID}"
exit 1
;;
esac
fi
# CentOS 7 has old versions of Ansible/Git/Python,
# so we adjust the parameters in consequence.
case "${ID}-${VERSION_ID}" in
centos-7)
PYTHON="/usr/bin/python2" ;;
*)
PYTHON="/usr/bin/python3" ;;
esac
# Run the node playbook.
ansible-pull --accept-host-key --extra-vars "ansible_python_interpreter=${PYTHON}" --inventory localhost, \
--checkout "${EDGENET_REF}" --url "${EDGENET_REPOSITORY}" "${EDGENET_PLAYBOOK}"