-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun
More file actions
executable file
·54 lines (44 loc) · 2.08 KB
/
run
File metadata and controls
executable file
·54 lines (44 loc) · 2.08 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
#!/bin/bash -e
echo -e "\nWelcome to Engage! There are a ton of tools in this container and echo-server is running so \"curl locahost\" for some quick details. \nMore details here: https://github.com/InAnimaTe/docker-engage"
# Consume a different ssh port, or use the default.
SSHPORT=${SSHPORT:-22}
## Set up user desired timezone
if [ -n "$TZ" ] && [ -f "/usr/share/zoneinfo/$TZ" ]; then
ln -sf "/usr/share/zoneinfo/$TZ" /etc/localtime
echo "$TZ" > /etc/timezone
else
echo "Warning: Invalid or missing TZ. Defaulting to UTC."
fi
## Dropuser setup
# Check if the required environment variables are defined and the user doesn't already exist - protects against container restarts with same fs
if [ -n "${DROPUSER}" ] && [ -n "${DU_UID}" ] && [ -n "${DU_GID}" ] && ! id "${DROPUSER}" >/dev/null 2>&1; then
# Use DROPGROUP if set; otherwise, default to DROPUSER as the group name.
GROUPNAME="${DROPGROUP:-$DROPUSER}"
echo "Creating group '${GROUPNAME}' with GID ${DU_GID}..."
groupadd -g "${DU_GID}" "${GROUPNAME}"
echo "Creating user '${DROPUSER}' with UID ${DU_UID}, primary GID ${DU_GID}, setting shell to /bin/zsh and not creating a home directory..."
useradd -N -M -u "${DU_UID}" -g "${DU_GID}" -s /bin/zsh "${DROPUSER}"
echo "Setting dropuser password to ensure they are not locked.."
DROPUSERPASSWORD="${DU_PASS:-engage}"
echo -e "${DROPUSERPASSWORD}\n${DROPUSERPASSWORD}" | passwd ${DROPUSER}
# Grant the dropuser sudo privileges without a password
echo "Enabling the user to use sudo and su as root.."
echo "${DROPUSER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${DROPUSER}
chmod 0440 /etc/sudoers.d/${DROPUSER}
chmod 4755 $(which su)
fi
## Loopmode check and execute if desired
if [ "$LOOPMODE" ] && [ $LOOPINTERVAL ]; then
echo ">> Entering LoopMode with interval $LOOPINTERVAL..."
while true
do
echo ">> Running given command..."
bash -x -c "$@"
echo ">> Beginning Sleep Internval for $LOOPINTERVAL ..."
sleep $LOOPINTERVAL
done
else
echo -e "\nStarting given command $@ now!\n"
### Blast-off!
bash -x -c "$@"
fi