2021-08-26 02:47:56 +00:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2023-10-08 17:11:00 +00:00
|
|
|
|
repair_permissions () {
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[35m📋 (1/3) Ensuring root group ownership...\033[0m\n"
|
|
|
|
|
find . ! -group root -print0 | xargs -0 -r chgrp root
|
|
|
|
|
printf "\033[36mWrapper | \033[35m📋 (2/3) Ensuring group read-write is present on files...\033[0m\n"
|
|
|
|
|
find . ! -perm g+rw -print0 | xargs -0 -r chmod g+rw
|
|
|
|
|
printf "\033[36mWrapper | \033[35m📋 (3/3) Ensuring sticky bit is present on directories...\033[0m\n"
|
|
|
|
|
find . -type d ! -perm g+s -print0 | xargs -0 -r chmod g+s
|
2023-10-08 17:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 23:30:33 +00:00
|
|
|
|
# Check if config exists taking one from image if needed.
|
2022-03-02 13:28:36 +00:00
|
|
|
|
if [ ! "$(ls -A --ignore=.gitkeep ./app/config)" ]; then
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[33m🏗️ Config not found, pulling defaults...\033[0m\n"
|
2022-03-07 01:51:25 +00:00
|
|
|
|
mkdir ./app/config/ 2> /dev/null
|
2021-08-26 02:47:56 +00:00
|
|
|
|
cp -r ./app/config_original/* ./app/config/
|
2022-06-10 23:30:33 +00:00
|
|
|
|
|
|
|
|
|
if [ $(id -u) -eq 0 ]; then
|
|
|
|
|
# We're running as root;
|
2023-10-08 17:29:28 +00:00
|
|
|
|
|
2022-06-10 23:30:33 +00:00
|
|
|
|
# Look for files & dirs that require group permissions to be fixed
|
|
|
|
|
# This will do the full /crafty dir, so will take a miniute.
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[35m📋 Looking for problem bind mount permissions globally...\033[0m\n"
|
2023-10-08 15:15:56 +00:00
|
|
|
|
|
2023-10-08 17:11:00 +00:00
|
|
|
|
repair_permissions
|
|
|
|
|
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[32m✅ Initialization complete!\033[0m\n"
|
2022-06-10 23:30:33 +00:00
|
|
|
|
fi
|
2022-06-16 15:45:08 +00:00
|
|
|
|
else
|
|
|
|
|
# Keep version file up to date with image
|
|
|
|
|
cp -f ./app/config_original/version.json ./app/config/version.json
|
2021-08-26 02:47:56 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2022-03-07 01:51:25 +00:00
|
|
|
|
|
|
|
|
|
if [ $(id -u) -eq 0 ]; then
|
2022-06-10 23:30:33 +00:00
|
|
|
|
# We're running as root
|
2022-03-07 01:51:25 +00:00
|
|
|
|
|
2022-06-10 23:30:33 +00:00
|
|
|
|
# If we find files in import directory, we need to ensure all dirs are owned by the root group,
|
|
|
|
|
# This fixes bind mounts that may have incorrect perms.
|
2023-10-08 15:13:38 +00:00
|
|
|
|
if [ "$(find ./import -type f ! -name '.gitkeep')" ]; then
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[35m📋 Files present in import directory, checking/fixing permissions...\033[0m\n"
|
|
|
|
|
printf "\033[36mWrapper | \033[33m⏳ Please be patient for larger servers...\033[0m\n"
|
2023-10-08 15:15:56 +00:00
|
|
|
|
|
2023-10-08 17:11:00 +00:00
|
|
|
|
repair_permissions
|
2023-10-08 15:15:56 +00:00
|
|
|
|
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[32m✅ Permissions Fixed! (This will happen every boot until /import is empty!)\033[0m\n"
|
2022-06-10 23:30:33 +00:00
|
|
|
|
fi
|
2022-03-07 01:51:25 +00:00
|
|
|
|
|
2023-10-08 17:29:28 +00:00
|
|
|
|
# Switch user, activate our prepared venv and launch crafty
|
2022-03-07 01:51:25 +00:00
|
|
|
|
args="$@"
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[32m🚀 Launching crafty with [\033[34m%s\033[32m]\033[0m\n" "$args"
|
2022-03-07 01:51:25 +00:00
|
|
|
|
exec sudo -u crafty bash -c "source ./.venv/bin/activate && exec python3 main.py $args"
|
|
|
|
|
else
|
|
|
|
|
# Activate our prepared venv
|
2023-10-08 17:29:28 +00:00
|
|
|
|
printf "\033[36mWrapper | \033[32m🚀 Non-root host detected, using normal exec\033[0m\n"
|
2022-03-07 01:51:25 +00:00
|
|
|
|
. ./.venv/bin/activate
|
|
|
|
|
# Use exec as our perms are already correct
|
|
|
|
|
# This is likely if using Kubernetes/OpenShift etc
|
2023-10-08 17:29:28 +00:00
|
|
|
|
exec python3 main.py "$@"
|
2022-03-07 01:51:25 +00:00
|
|
|
|
fi
|