Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cron' #867

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
</a>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

## Table of Contents
Expand Down
30 changes: 21 additions & 9 deletions src/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
# Exit immediately if a command exits with a non-zero status
set -e


export HOME="/home/steam"
export GAME_LOCATION=${GAME_LOCATION:-"${HOME}/valheim"}
export SAVE_LOCATION=${SAVE_LOCATION:-"${GAME_LOCATION}/saves"}
export MODS_LOCATION=${MODS_LOCATION:-"${GAME_LOCATION}/BepInEx/plugins"}
export BACKUP_LOCATION=${BACKUP_LOCATION:-"${GAME_LOCATION}/backups"}
export CRON_LOCATION="${HOME}/cron.d"
export LOG_LOCATION="${GAME_LOCATION}/logs"

# Logging function to prepend timestamps to log messages
log() {
echo "$(date) - $*"
Expand All @@ -21,9 +30,12 @@ setup_environment() {
source "/home/steam/scripts/utils.sh"
fi

export NAME=$(sed -e 's/^"//' -e 's/"$//' <<<"$NAME")
export WORLD=$(sed -e 's/^"//' -e 's/"$//' <<<"$WORLD")
export PASSWORD=$(sed -e 's/^"//' -e 's/"$//' <<<"$PASSWORD")
export NAME
NAME=$(sed -e 's/^"//' -e 's/"$//' <<<"$NAME")
export WORLD
WORLD=$(sed -e 's/^"//' -e 's/"$//' <<<"$WORLD")
export PASSWORD
PASSWORD=$(sed -e 's/^"//' -e 's/"$//' <<<"$PASSWORD")
export ODIN_CONFIG_FILE="${ODIN_CONFIG_FILE:-"${GAME_LOCATION}/config.json"}"
export ODIN_DISCORD_FILE="${ODIN_DISCORD_FILE:-"${GAME_LOCATION}/discord.json"}"

Expand Down Expand Up @@ -116,8 +128,8 @@ setup_cron() {

echo "Setting up cron job: $name"

local cron_folder="$HOME/valheim/cron.d"
local log_folder="$HOME/valheim/logs"
local cron_folder="$CRON_LOCATION"
local log_folder="$LOG_LOCATION"
local log_location="$log_folder/$name.out"

# Create necessary directories
Expand Down Expand Up @@ -145,8 +157,8 @@ create_dir_with_ownership() {
setup_filesystem() {
log "Setting up file systems"

sudo chown -R "$PUID:$PGID" /home/steam /home/steam/.*
sudo chmod -R ug+rwx /home/steam
sudo chown -R "$PUID:$PGID" "$HOME" /home/steam/.*
sudo chmod -R ug+rwx "$HOME"

create_dir_with_ownership "$PUID" "$PGID" "$SAVE_LOCATION"
create_dir_with_ownership "$PUID" "$PGID" "$MODS_LOCATION"
Expand Down Expand Up @@ -197,9 +209,9 @@ setup_cron_env
# Verify the cron directory and its contents
if [[ "$AUTO_BACKUP" -eq 1 || "$AUTO_UPDATE" -eq 1 || "$SCHEDULED_RESTART" -eq 1 ]]; then
log "Checking if cron directory and files exist..."
if [[ -d "$HOME/valheim/cron.d" && $(ls -A "$HOME/valheim/cron.d") ]]; then
if [[ -d "$CRON_LOCATION" && $(ls -A "$CRON_LOCATION") ]]; then
touch /tmp/master-cron
for file in /home/steam/valheim/cron.d/*; do
for file in "$CRON_LOCATION"/*; do
cat "$file" >> /tmp/master-cron
done
crontab /tmp/master-cron
Expand Down
Loading