mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-22 17:04:03 +02:00
Updated entrypoint to properly asses and fix permissions.
This commit is contained in:
parent
4e01e6ac26
commit
b6b5f2c2b0
1 changed files with 37 additions and 12 deletions
|
@ -3,28 +3,53 @@
|
||||||
# set -e Exit the script if an error happens
|
# set -e Exit the script if an error happens
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
#Setting the PUID and PGID variable to the ID's we've actually launched as, instead of some passed environment variable.
|
|
||||||
PUID=$(id -u)
|
|
||||||
PGID=$(id -g)
|
|
||||||
|
|
||||||
files_ownership () {
|
files_ownership () {
|
||||||
# -h Changes the ownership of an encountered symbolic link and not that of the file or directory pointed to by the symbolic link.
|
# Check if the /app/data folder is owned by the user invoking the container
|
||||||
# -R Recursively descends the specified directories
|
if [ $(stat -c%u /app/data) != $(id -u) ]; then
|
||||||
# -c Like verbose but report only when a change is made
|
echo "File ownership incorrect, attempting to fix."
|
||||||
chown -hRc "$PUID":"$PGID" /app/data
|
chown -hRc "$(id -u)":"$(id -g)" /app/data || echo "ERROR: Failed to set file ownership. Please run 'sudo chown -R $(id -u):$(id -g) /path/to/container/volume' to resolve."; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Checks for R/W permissions
|
||||||
|
if [ $(stat -c%a /app/data) -ne 770 ]; then
|
||||||
|
echo "Directory permissions incorrect, attempting to fix."
|
||||||
|
find /app/data -type d -exec chmod 770 {} \;
|
||||||
|
|
||||||
|
#Re-run the check
|
||||||
|
if [ $(stat -c%a /app/data) -ne 770 ]; then
|
||||||
|
echo "ERROR: Failed to set file permissions. Please run 'sudo find /path/to/container/volume -type d chmod 770 {} \;' to resolve."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Directory permission fix succesful! Continuing."
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Check the R/W permissions on the files
|
||||||
|
if [ $(stat -c%a /app/data/* | head -n 1) != 640 ]; then
|
||||||
|
echo "File permissions incorrect. Attempting to fix."
|
||||||
|
find /app/data -type f -exec chmod 640 {} \;
|
||||||
|
|
||||||
|
#Re-run the check
|
||||||
|
if [ $(stat -c%a /app/data/* | head -n 1) != 640 ]; then
|
||||||
|
echo "ERROR: Failed to set file permissions. Please run 'sudo find /path/to/container/volume -type f chmod 640 {} \;' to resolve."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "File permission fix succesful! Continuing."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "==> Performing startup jobs and maintenance tasks"
|
echo "==> Performing startup jobs and maintenance tasks"
|
||||||
|
echo "==> Checking file permissions"
|
||||||
files_ownership
|
files_ownership
|
||||||
|
|
||||||
echo "==> Starting application with user $PUID group $PGID"
|
echo "==> Starting application as user: $(id -u) ($USER) and group $(id -g)"
|
||||||
|
|
||||||
# --clear-groups Clear supplementary groups.
|
# --clear-groups Clear supplementary groups.
|
||||||
if [ $(id -u) -eq 0 ];
|
if [ $(id -u) -eq 0 ];
|
||||||
then
|
then
|
||||||
#We're running as root, so we can use setpriv without problems.
|
#We're running as root, so we can use setpriv without problems.
|
||||||
exec setpriv --reuid "$PUID" --regid "$PGID" --clear-groups "$@"
|
exec setpriv --reuid "$PUID" --regid "$PGID" --clear-groups "$@"
|
||||||
else
|
else
|
||||||
#We're running as a regular user, so we'll launch the app as one.
|
#We're running as a regular user, so we'll launch the app as one.
|
||||||
exec "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue