-
Notifications
You must be signed in to change notification settings - Fork 13
/
bootstrap.sh
executable file
·124 lines (96 loc) · 3.25 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
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
set -eo pipefail
[[ $TRACE ]] && set -x
# A script to bootstrap proxeus-core.
# Based on https://github.com/dokku/dokku/blob/master/bootstrap.sh
# We encourage you to also add Dokku for managing your instance,
# however this is not done by this script.
# It expects to be run on Debian, Ubuntu, or CentOS 7 via 'sudo'
# It checks out the proxeus source code from Github into ~/proxeus and then runs 'make install'.
yapt-get() {
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get --no-install-recommends --yes --option Dpkg::Options::="--force-confold" --option Dpkg::Options::="--force-confdef" "$@"
}
log-fail() {
declare desc="log fail formatter"
echo "$@" 1>&2
exit 1
}
ensure-environment() {
local FREE_MEMORY
if [[ -z "$GIT_TAG" ]]; then
echo "Preparing to install $GIT_REPO..."
else
echo "Preparing to install $GIT_TAG from $GIT_REPO..."
fi
hostname -f >/dev/null 2>&1 || {
log-fail "This installation script requires that you have a hostname set for the instance. Please set a hostname for 127.0.0.1 in your /etc/hosts"
}
if ! command -v apt-get &>/dev/null; then
log-fail "This installation script supports Debian-based systems and expects apt-get."
fi
if ! command -v docker &> /dev/null; then
log-fail "Docker needs to be installed."
fi
FREE_MEMORY=$(grep MemTotal /proc/meminfo | awk '{print $2}')
if [[ "$FREE_MEMORY" -lt 1003600 ]]; then
echo "To build containers, it is strongly suggested that you have 1024 megabytes or more of free memory"
fi
}
install-requirements() {
echo "--> Ensuring we have the proper dependencies"
case "$SRV_DISTRO" in
debian)
if ! dpkg -l | grep -q software-properties-common; then
yapt-get update
yapt-get install software-properties-common
fi
;;
ubuntu)
if ! dpkg -l | grep -q software-properties-common; then
yapt-get update
yapt-get install software-properties-common
fi
add-apt-repository -y universe
yapt-get update
;;
esac
yapt-get install sudo git make software-properties-common
}
install-proxeus() {
echo "--> Starting Proxeus install"
if [[ -n $GIT_BRANCH ]]; then
install-proxeus-from-source "origin/$GIT_BRANCH"
elif [[ -n $GIT_TAG ]]; then
local GIT_SEMVER="${GIT_TAG//v/}"
major=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[1]}')
minor=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[2]}')
patch=$(echo "$GIT_SEMVER" | awk '{split($0,a,"."); print a[3]}')
install-proxeus-from-source "$GIT_TAG"
else
install-proxeus-from-source
fi
}
install-proxeus-from-source() {
local GIT_CHECKOUT="$1"
if [[ ! -d ./proxeus ]]; then
git clone "$GIT_REPO" ./proxeus
fi
cd ./proxeus
touch ../.env
cp ../.env .
git fetch origin
[[ -n $GIT_CHECKOUT ]] && git checkout "$GIT_CHECKOUT"
}
main() {
export SRV_DISTRO SRV_DISTRO_VERSION
# shellcheck disable=SC1091
SRV_DISTRO=$(. /etc/os-release && echo "$ID")
# shellcheck disable=SC1091
SRV_DISTRO_VERSION=$(. /etc/os-release && echo "$VERSION_ID")
export DEBIAN_FRONTEND=noninteractive
export GIT_REPO=${GIT_REPO:-"https://github.com/ProxeusApp/proxeus-core.git"}
ensure-environment
install-requirements
install-proxeus
}
main "$@"