Skip to content

Commit

Permalink
Explicitly set directory and file permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
lloesche committed Feb 8, 2021
1 parent 569c3c9 commit aa7eed8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions valheim-backup
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
BACKUPS_INTERVAL=${BACKUPS_INTERVAL:-3600}
BACKUPS_DIRECTORY=${BACKUPS_DIRECTORY:-/config/backups}
BACKUPS_MAX_AGE=${BACKUPS_MAX_AGE:-3}
BACKUPS_DIRECTORY_PERMISSIONS=${BACKUPS_DIRECTORY_PERMISSIONS:-755}
BACKUPS_FILE_PERMISSIONS=${BACKUPS_FILE_PERMISSIONS:-644}

# Remove trailing slash if any
BACKUPS_DIRECTORY=${BACKUPS_DIRECTORY%/}
Expand All @@ -21,7 +23,9 @@ backup() {
local backup_file="$BACKUPS_DIRECTORY/worlds-$(date +%Y%m%d-%H%M%S).zip"
echo "Backing up Valheim Server Worlds to $backup_file"
mkdir -p "$BACKUPS_DIRECTORY"
chmod $BACKUPS_DIRECTORY_PERMISSIONS "$BACKUPS_DIRECTORY"
zip -r "$backup_file" "worlds/"
chmod $BACKUPS_FILE_PERMISSIONS "$backup_file"
}

flush_old() {
Expand Down
15 changes: 14 additions & 1 deletion valheim-updater
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/bash
# Fix permissions in case they were altered externaly
echo "Running Valheim Server updater as user $USER uid $UID"
chown -R steam:steam /config
CONFIG_DIRECTORY_PERMISSIONS=${CONFIG_DIRECTORY_PERMISSIONS:-755}
WORLDS_DIRECTORY_PERMISSIONS=${WORLDS_DIRECTORY_PERMISSIONS:-755}
WORLDS_FILE_PERMISSIONS=${WORLDS_FILE_PERMISSIONS:-644}

just_started=true

cd /opt/steamcmd
main() {
while :; do
update_permissions
update
sleep 900
done
Expand Down Expand Up @@ -36,4 +40,13 @@ update() {
rm -f "$logfile"
}

update_permissions() {
chown -R steam:steam /config
chmod $CONFIG_DIRECTORY_PERMISSIONS /config
if [ -d /config/worlds ]; then
chmod $WORLDS_DIRECTORY_PERMISSIONS /config/worlds
chmod $WORLDS_FILE_PERMISSIONS /config/worlds/*
fi
}

main

0 comments on commit aa7eed8

Please sign in to comment.