2019-06-24 20:03:06 +02:00
|
|
|
#!/usr/bin/with-contenv bash
|
|
|
|
|
2019-06-24 21:15:27 +02:00
|
|
|
mkdir -p /config/{extensions,data,workspace,.ssh}
|
2019-06-24 20:03:06 +02:00
|
|
|
|
2020-12-24 02:03:43 +01:00
|
|
|
if [ -n "${SUDO_PASSWORD}" ] || [ -n "${SUDO_PASSWORD_HASH}" ]; then
|
2021-05-08 16:50:21 +02:00
|
|
|
echo "setting up sudo access"
|
|
|
|
if ! grep -q 'abc' /etc/sudoers; then
|
|
|
|
echo "adding abc to sudoers"
|
|
|
|
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
|
|
|
|
fi
|
|
|
|
if [ -n "${SUDO_PASSWORD_HASH}" ]; then
|
|
|
|
echo "setting sudo password using sudo password hash"
|
|
|
|
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
|
|
|
|
else
|
|
|
|
echo "setting sudo password using SUDO_PASSWORD env var"
|
|
|
|
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
|
|
|
|
fi
|
2019-07-09 23:29:50 +02:00
|
|
|
fi
|
|
|
|
|
2019-06-24 20:03:06 +02:00
|
|
|
# permissions
|
2021-07-05 00:36:51 +02:00
|
|
|
if [ -f "/usr/bin/find" ] && [ -f "/usr/bin/xargs" ]; then
|
2021-09-16 14:51:12 +02:00
|
|
|
CORES=$(nproc --all)
|
|
|
|
|
2021-07-05 00:36:51 +02:00
|
|
|
# Split workload between config and workspace
|
|
|
|
echo "setting permissions::configuration"
|
2021-09-16 14:51:12 +02:00
|
|
|
find /config -path /config/workspace -prune -false -o -type d -print0 | \
|
|
|
|
xargs --null -r --max-args=1 --max-procs=$((CORES*2*8)) \
|
2021-07-05 00:36:51 +02:00
|
|
|
chown -R abc:abc
|
|
|
|
|
|
|
|
echo "setting permissions::workspace"
|
|
|
|
chown abc:abc /config/workspace
|
|
|
|
else
|
2021-09-16 14:51:12 +02:00
|
|
|
# Set permissions on data mount
|
|
|
|
# do not decend into the workspace
|
|
|
|
chown -R abc:abc "$(ls /config -I workspace)"
|
|
|
|
chown abc:abc /config/workspace
|
2021-07-05 00:36:51 +02:00
|
|
|
fi
|