-
Notifications
You must be signed in to change notification settings - Fork 10
/
postinstall.sh
61 lines (49 loc) · 1.75 KB
/
postinstall.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
#!/bin/bash
## CONFIGURATION ###
ADM_NAME='admin'
ADM_GID=997
ADM_HOME='/home/admin'
ADM_USERS=()
### END of CONFIGURATION ###
# require root privileges
if [[ $(/usr/bin/id -u) != "0" ]]; then
echo "Please run the script as root!"
exit 1
fi
echo ">>> Installing Software"
apt-get update
apt-get install sudo curl wget dnsutils mtr tcpdump ncdu jq iptables iptables-persistent borgbackup
# install docker if not already installed
if [[ -z $(which docker) ]]; then
curl -fsSL https://get.docker.com | bash
fi
# remove trailing slash from ADM_HOME
[[ "${ADM_HOME}" == */ ]] && ADM_HOME="${ADM_HOME::-1}"
# create admin group, add members to group and set permissions
echo ">>> Creating admin structure"
groupadd -g ${ADM_GID} ${ADM_NAME}
mkdir -p -m 775 ${ADM_HOME}
chown -R root:${ADM_NAME} ${ADM_HOME}
# add dc alias to skel
echo -e '\nalias dc="sudo docker compose"' | tee -a "/etc/skel/.bashrc" > /dev/null
# shellcheck disable=SC2068
# usernames can't have spaces -> can be interpreted as two usernames
for user in ${ADM_USERS[@]}; do
# check if user exists
if ! id "${user}"; then
useradd --create-home --shell=/bin/bash "${user}"
fi
usermod --append --groups=sudo,${ADM_NAME} "${user}"
# add aliases
if ! grep 'alias dc' .bashrc; then
echo -e '\nalias dc="sudo docker compose"' | tee -a "/home/${user}/.bashrc" > /dev/null
fi
# check if exist
[ ! -h "/home/{user}/admin" ] && ln -s ${ADM_HOME} /home/${user}/admin
done
# adjust permission of admin directory
chown -R root:admin ${ADM_HOME}
find ${ADM_HOME} -type d -exec chmod 0775 {} \;
find ${ADM_HOME} -type f -exec chmod 0664 {} \;
wget -q https://raw.githubusercontent.com/felbinger/scripts/master/genpw.sh -O /usr/local/bin/genpw
chmod +x /usr/local/bin/genpw