-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·78 lines (67 loc) · 2.3 KB
/
install.sh
File metadata and controls
executable file
·78 lines (67 loc) · 2.3 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
#!/bin/bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
set -o allexport
readonly name="run-script"
apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
apt_get_checkinstall() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
apt_get_update
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@"
fi
}
apt_get_cleanup() {
apt-get clean
rm -rf /var/lib/apt/lists/*
}
echo_banner() {
local text="$1"
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
}
install() {
# Re-read SCRIPT from the env file verbatim to prevent shell evaluation of
# backticks: the devcontainer CLI wraps option values in double quotes in the
# env file and then sources it, which causes bash to evaluate backticks.
# Reading the file directly with awk avoids this evaluation.
if [ -f ./devcontainer-features.env ]; then
SCRIPT=$(awk '/^SCRIPT="/{sub(/^SCRIPT="/,"");v=$0;f=1;next}f{v=v"\n"$0}END{if(f){sub(/"$/,"",v);printf"%s",v}}' ./devcontainer-features.env)
fi
if [ -n "${URL}" ] && [ -n "${SCRIPT}" ]; then
printf >&2 '=== [ERROR] Both "url" and "script" options are provided. Please provide only one.\n'
exit 1
fi
if [ -z "${URL}" ] && [ -z "${SCRIPT}" ]; then
echo "No script URL or inline script provided. Nothing to do."
return 0
fi
tmpScript="$(mktemp)"
trap 'rm -f "${tmpScript}"' EXIT
if [ -n "${URL}" ]; then
echo "Downloading script from: ${URL}"
if command -v wget >/dev/null 2>&1; then
wget -qO "${tmpScript}" "${URL}"
elif command -v curl >/dev/null 2>&1; then
curl -fsSL -o "${tmpScript}" "${URL}"
else
apt_get_checkinstall curl ca-certificates
apt_get_cleanup
curl -fsSL -o "${tmpScript}" "${URL}"
fi
else
echo "Writing inline script to temporary file..."
printf '%s' "${SCRIPT}" | tee "${tmpScript}" >/dev/null
fi
echo "Executing script..."
bash "${tmpScript}"
}
echo_banner "devcontainer.community"
echo "Running $name..."
install "$@"
echo "(*) Done!"