ls-code-server/root/etc/cont-init.d/30-config
2021-07-14 10:08:05 +02:00

38 lines
1.3 KiB
Plaintext

#!/usr/bin/with-contenv bash
mkdir -p /config/{extensions,data,workspace,.ssh}
if [ -n "${SUDO_PASSWORD}" ] || [ -n "${SUDO_PASSWORD_HASH}" ]; then
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
fi
# permissions
if [ -f "/usr/bin/find" ] && [ -f "/usr/bin/xargs" ]; then
# Split workload between config and workspace
echo "setting permissions::configuration"
CORES=$(nproc --all)
find /config -maxdepth 4 -mindepth 1 -path /config/workspace -prune -false -o -type d -print0 | \
xargs -r --max-args=1 --max-procs=$((CORES*2*8)) \
chown -R abc:abc
echo "setting permissions::workspace"
chown abc:abc /config/workspace
find /config/workspace -maxdepth 4 -mindepth 1 -type d -print0 | \
xargs -r --max-args=1 --max-procs=$((CORES*2*16)) \
chown -R abc:abc
else
chown -R abc:abc \
/config
fi