-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·113 lines (95 loc) · 3.39 KB
/
install
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
#!/usr/bin/env bash
set -e;
# If the script runs as root, assume this is a bare OS.
# shellcheck disable=SC2046
if [ $(id -u) = 0 ]; then
apt update -y;
DEBIAN_FRONTEND=noninteractive apt install sudo build-essential tzdata keyboard-configuration -y;
fi
# If the make package cannot be satisfied, assume the apt repositories need to
# be updated.
echo "[Prime APT repositories]";
if ! sudo apt satisfy make &> /dev/null; then sudo apt update -y; fi
# Ensure `make` is available.
echo "[Ensure installation of GNU Make]";
command -v make &> /dev/null || sudo apt install build-essential -y;
# If the Makefile is missing, assume this script is invoked directly and the
# repo itself needs to be downloaded.
echo "[Prepare installation files]";
if ! [ -f Makefile ]; then
# Install curl and unzip, if required.
(command -v curl &> /dev/null \
&& command -v unzip &> /dev/null \
&& (dpkg -l | tail -n+6 | awk '{ print "~"$2"~" }' | grep -q '~ca-certificates~') \
) || sudo apt install curl ca-certificates zip -y;
# Download the archive of the main branch.
curl -L https://github.com/elgentos/setup/archive/main.zip \
--output /tmp/elgentos-setup.zip;
# Empty the directory stack and remove the setup files when the script exits.
trap 'while popd 2>/dev/null; do echo -n ""; done; rm -rf /tmp/setup-main' EXIT;
# Extract the archive and push its output directory to the top of the stack.
# This makes the Makefile and template files available for the rest of the
# installation.
pushd /tmp;
unzip elgentos-setup.zip;
rm -f elgentos-setup.zip;
pushd setup-main;
fi
MAKE_OPTIONS=(
--no-builtin-rules
--no-builtin-variables
"CI=${CI}"
)
# First test if we need to make the SSH key.
echo "[Ensure SSH key exists]";
if ! 2>/dev/null make ssh-key --quiet; then
# shellcheck disable=SC2086
make ssh-key ${MAKE_OPTIONS[*]};
echo "";
echo "Make sure your key is registered to your GitHub and GitLab accounts before proceeding.";
echo " https://github.com/settings/keys";
echo " https://gitlab.elgentos.nl/-/profile/keys";
echo "";
# shellcheck disable=SC2162
cut -d: -f3 < /proc/1/cgroup | grep -q '/docker/' \
|| read -p "Press enter to continue, after installing the SSH key. . .";
fi
# Once the SSH key is installed, proceed with the rest of the installation.
TARGETS=(install)
OPTIONS="$*"
# If no targets are provided, ask for them.
if [ $# -lt 1 ]; then
# Ask for installation targets.
echo "[Prepare optional software dialog]";
if ! 2>/dev/null make dialog --quiet; then
# shellcheck disable=SC2086
make dialog ${MAKE_OPTIONS[*]};
fi
options=()
for option in $(make -qp | grep 'optional:: |' | cut -d'|' -f2- | sort -u); do
if ! 2>/dev/null make -q "$option"; then
options+=("$option $option off")
fi
done
# shellcheck disable=SC2046
# shellcheck disable=SC2086
[ ${#options[@]} -gt 0 ] && OPTIONS=$(dialog \
--title 'Select software' \
--backtitle 'Optional workstation software' \
--separate-output \
--stdout \
--checklist 'Select optional software' \
0 0 0 ${options[*]} \
);
fi
for target in $(echo "$OPTIONS" | tr ' ' '\n' | sort -u | uniq); do
if 2>/dev/null make -q "$target"; then
echo "[Skip $target] Already installed";
else
TARGETS+=("$target");
fi
done
echo "[Make ${TARGETS[*]}]";
# shellcheck disable=SC2086
make -q ${TARGETS[*]} || make ${MAKE_OPTIONS[*]} ${TARGETS[*]};
echo "Finished";