-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup.sh
More file actions
123 lines (105 loc) · 4.53 KB
/
Copy pathsetup.sh
File metadata and controls
123 lines (105 loc) · 4.53 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
#!/usr/bin/env bash
set -euo pipefail
export EE_ROOT_DIR="/opt/easyengine"
export EE4_BINARY="/usr/local/bin/ee"
export LOG_FILE="$EE_ROOT_DIR/logs/install.log"
# Ensure EE_QUIET_OUTPUT is always defined so that set -u does not cause
# "unbound variable" errors when the sourced functions file checks it.
export EE_QUIET_OUTPUT="${EE_QUIET_OUTPUT:-}"
export EE_APT_LOCK_WAIT="${EE_APT_LOCK_WAIT:-}"
# When EE_APT_LOCK_WAIT is set, wait for the dpkg/apt lock instead of
# failing immediately. Tier variables are left empty (no-op) when unset.
if [ -n "$EE_APT_LOCK_WAIT" ]; then
_EE_APT_LOCK_LIGHT_INSTALL="-o DPkg::Lock::Timeout=900"
_EE_APT_LOCK_INSTALL="-o DPkg::Lock::Timeout=1800"
else
_EE_APT_LOCK_LIGHT_INSTALL=""
_EE_APT_LOCK_INSTALL=""
fi
# Retry-based apt-get update that tolerates a busy apt lists lock.
# Defined here for bootstrap(); the functions file overrides with its own
# copy.
ee_apt_update() {
local i err
for i in $(seq 1 30); do
if err="$(apt-get update 2>&1)"; then printf '%s\n' "$err"; return 0; fi
printf '%s\n' "$err" >&2
printf '%s' "$err" | grep -qiE "Could not get lock|Unable to lock" || return 1
echo "=====> apt lists lock busy; retrying in 10s"
sleep 10
done
apt-get update
}
# Run apt/dpkg non-interactively so package installation never blocks on a
# debconf or needrestart prompt during an unattended setup.
export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a
# Create a temp directory for downloaded helper files and clean it on exit.
TMP_WORK_DIR="$(mktemp -d /tmp/ee-installer.XXXXXX)"
export TMP_WORK_DIR
trap 'rm -rf "$TMP_WORK_DIR"' EXIT
# Remember this script's path so it can delete itself after a successful
# install (the `ee` from `wget -qO ee https://rt.cx/ee4 && bash ee`). Only when
# run directly: BASH_SOURCE[0] equals $0 when executed, differs when sourced
# (e.g. remote-migrate), and is empty when piped (`curl ... | bash`). Resolve
# to an absolute path so a later `cd` can't strand it. EE_KEEP_INSTALLER=1 opts out.
INSTALLER_SELF=""
if [ -z "${EE_KEEP_INSTALLER:-}" ] && [ "${BASH_SOURCE[0]:-}" = "$0" ] && [ -f "${BASH_SOURCE[0]}" ]; then
INSTALLER_SELF="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/$(basename -- "${BASH_SOURCE[0]}")"
fi
function bootstrap() {
if ! command -v curl > /dev/null 2>&1; then
packages="curl"
if ! command -v wget > /dev/null 2>&1; then
packages="${packages} wget"
fi
ee_apt_update && apt-get $_EE_APT_LOCK_LIGHT_INSTALL install $packages -y
fi
# Use the locally patched functions file when present (set via EE_LOCAL_FUNCTIONS),
# otherwise fall back to downloading the upstream copy.
if [ -n "${EE_LOCAL_FUNCTIONS:-}" ] && [ -s "${EE_LOCAL_FUNCTIONS}" ]; then
cp "${EE_LOCAL_FUNCTIONS}" "$TMP_WORK_DIR/helper-functions"
return 0
fi
local functions_url="https://raw.githubusercontent.com/EasyEngine/installer/master/functions"
if ! curl --fail --silent --show-error --output "$TMP_WORK_DIR/helper-functions" "$functions_url"; then
echo "ERROR: Failed to download EasyEngine installer functions from $functions_url. Check your network and try again." >&2
exit 1
fi
if [ ! -s "$TMP_WORK_DIR/helper-functions" ]; then
echo "ERROR: Downloaded installer functions file is empty. Aborting." >&2
exit 1
fi
}
# Main installation function, to setup and run once the installer script is loaded.
function do_install() {
mkdir -p /opt/easyengine/logs
touch "$LOG_FILE"
# Open standard out at `$LOG_FILE` for write.
# Write to file as well as terminal
exec 1> >(tee -a "$LOG_FILE")
# Redirect standard error to standard out such that
# standard error ends up going to wherever standard
# out goes (the file and terminal).
exec 2>&1
# Detect Linux distro here (after log setup) so any failure is caught and logged.
EE_LINUX_DISTRO=$(lsb_release -i 2>/dev/null | awk '{print $3}' || true)
export EE_LINUX_DISTRO
# Creating EasyEngine parent directory for log file.
bootstrap
source "$TMP_WORK_DIR/helper-functions"
check_dependencies
ee_log_info1 "Setting up EasyEngine"
download_and_install_easyengine
ee_log_info1 "Pulling EasyEngine docker images"
pull_easyengine_images
add_ssl_renew_cron
ee_log_info1 "Run \"ee help site\" for more information on how to create a site."
}
# Invoking the main installation function.
do_install
# Reached only on success (set -e exits earlier on failure, leaving the file
# for a retry). Remove the downloaded installer so it doesn't linger.
if [ -n "$INSTALLER_SELF" ] && [ -f "$INSTALLER_SELF" ]; then
rm -f "$INSTALLER_SELF" || true
fi