-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·95 lines (83 loc) · 2.66 KB
/
entrypoint.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
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
#!/bin/bash
set -e
hex()
{
/usr/bin/openssl rand -hex 8
}
echo "Preparing container .."
COMMAND=(/usr/bin/shellinaboxd --no-beep -u shellinabox -g shellinabox -c /var/lib/shellinabox -p "${SIAB_PORT}" --user-css "${SIAB_USERCSS}")
if [[ "$SIAB_PKGS" != "none" ]]; then
set +e
apk add --no-cache $SIAB_PKGS
rm -rf /var/cache/apk/*
set -e
fi
if [[ "$SIAB_SSL" != "true" ]]; then
COMMAND+=(-t)
fi
if [[ "$SIAB_DEBUG" == "true" ]]; then
COMMAND+=(--debug)
fi
if [[ "${SIAB_ADDUSER}" == "true" ]]; then
sudo=""
if [[ "${SIAB_SUDO}" == "true" ]]; then
sudo="-G wheel"
if [[ ! -f /etc/sudoers ]]; then
touch /etc/sudoers
fi
chmod 0660 /etc/sudoers
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
chmod 0440 /etc/sudoers
fi
/usr/sbin/addgroup -g ${SIAB_GROUPID} ${SIAB_GROUP}
if [[ -d "${SIAB_HOME}" ]]; then
/usr/sbin/adduser -u ${SIAB_USERID} -G ${SIAB_GROUP} ${sudo} -s ${SIAB_SHELL} -h ${SIAB_HOME} -H -D ${SIAB_USER}
else
/usr/sbin/adduser -u ${SIAB_USERID} -G ${SIAB_GROUP} ${sudo} -s ${SIAB_SHELL} -h ${SIAB_HOME} -D ${SIAB_USER}
fi
if [[ "${SIAB_PASSWORD}" == "putsafepasswordhere" ]]; then
SIAB_PASSWORD=$(hex)
echo "Autogenerated password for user ${SIAB_USER}: ${SIAB_PASSWORD}"
fi
echo "${SIAB_USER}:${SIAB_PASSWORD}" | /usr/sbin/chpasswd
unset SIAB_PASSWORD
fi
for service in ${SIAB_SERVICE}; do
COMMAND+=( -s "${service}" )
done
export SIAB_PORT SIAB_ADDUSER SIAB_DEBUG SIAB_USER SIAB_USERID \
SIAB_GROUP SIAB_GROUPID SIAB_SHELL SIAB_HOME SIAB_SUDO \
SIAB_SSL SIAB_SERVICE SIAB_PKGS SIAB_SCRIPT SIAB_RUN
if [[ -n "$SIAB_SCRIPT" && "$SIAB_SCRIPT" != "none" ]]; then
if [[ -f "$SIAB_SCRIPT" ]]; then
cp "$SIAB_SCRIPT" /siab-script || {
echo >&2 "Fatal: could not copy $SIAB_SCRIPT to /siab-script"
exit 1
}
else
echo "$SIAB_SCRIPT is not a file or is not accessible, trying to download ..."
/usr/bin/curl --fail -Lsk "${SIAB_SCRIPT}" > /siab-script || {
echo >&2 "Fatal: could not download $SIAB_SCRIPT to /siab-script"
exit 1
}
fi
chmod +x /siab-script || {
echo >&2 "Fatal: could not set executable flag on /siab-script"
exit 1
}
echo "Running ${SIAB_SCRIPT} .."
/siab-script
fi
if [[ -n "$SIAB_RUN" ]]; then
echo "Executing: /bin/sh -c $SIAB_RUN"
/bin/sh -c "$SIAB_RUN"
fi
echo "Starting container .."
if [[ "$*" == "shellinabox" ]]; then
echo "Executing: ${COMMAND[@]}"
exec "${COMMAND[@]}"
else
echo "Not executing: ${COMMAND[@]}"
echo "Executing: ${@}"
exec "$@"
fi