Replace echo with printf to account for environment inconsistencies.

Echo was being weird, some environments it was not escaping colour codes,
tried adding the '-e' flag, but this was printed weirdly in compose.
This commit is contained in:
Zedifus 2023-10-08 18:29:28 +01:00
parent 706c30775a
commit 0255d17707

View File

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