From adb298c2c93c51cb7409b6b25c33bbccc92ae6b9 Mon Sep 17 00:00:00 2001 From: Cere Date: Mon, 8 Jul 2024 05:12:28 -0400 Subject: [PATCH] added reasonable debug logging --- stcs-wrapper.sh | 50 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/stcs-wrapper.sh b/stcs-wrapper.sh index 0e8e7b3..2c6f527 100755 --- a/stcs-wrapper.sh +++ b/stcs-wrapper.sh @@ -4,20 +4,20 @@ STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh" if [ -z ${STCS_GAME_CONFIG+x} ]; then - echo "[CereSaves] Game config not defined, trying default!"; + logfunny "[CereSaves] Game config not defined, trying default!"; STCS_GAME_CONFIG="./stcs-config.sh" else - echo "[CereSaves] Game config is set to '$STCS_GAME_CONFIG'"; + logfunny "[CereSaves] Game config is set to '$STCS_GAME_CONFIG'"; fi if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then - echo "[CereSaves] Global config not found!" + logfunny "[CereSaves] Global config not found!" exit 1 fi # TODO - find a way to make this not a static filename, for multiple games in one folder. if [ ! -f "$STCS_GAME_CONFIG" ]; then - echo "[CereSaves] Game config not found!" + logfunny "[CereSaves] Game config not found!" exit 1 fi @@ -29,24 +29,25 @@ STCS_SYNCED_TIMESTAMP_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}.timestamp" STCS_SYNCED_SAVADATA_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}" prelaunch () { - echo "[CereSaves] prelaunch start" + logfunny "[CereSaves] prelaunch start" if checkpretimestamps; then # Assume Save Data needs to be restored! + logfunny "[CereSaves] Update to local savedata detected!" if [ -f "$STCS_SAVEPATH" ]; then #echo "Savedata $STCS_SAVEPATH is a file!" - rsync -az "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)" "$STCS_SAVEPATH" + rsync -az --ignore-times "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)" "$STCS_SAVEPATH" fi if [ -d "$STCS_SAVEPATH" ]; then #echo "Savedata $STCS_SAVEPATH is a folder!" - rsync -az "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" "$STCS_SAVEPATH/" + rsync -az --ignore-times "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" "$STCS_SAVEPATH/" fi - rsync -az "$STCS_SYNCED_TIMESTAMP_PATH" "$STCS_CACHED_TIMESTAMP_PATH" + rsync -az --ignore-times "$STCS_SYNCED_TIMESTAMP_PATH" "$STCS_CACHED_TIMESTAMP_PATH" fi - echo "[CereSaves] prelaunch complete" + logfunny "[CereSaves] prelaunch complete" } postlaunch () { - echo "[CereSaves] postlaunch start" + logfunny "[CereSaves] postlaunch start" # Create Backup Dir if it doesn't exist. if [ ! -d "$STCS_SYNCED_SAVADATA_PATH" ]; then mkdir "$STCS_SYNCED_SAVADATA_PATH" @@ -54,17 +55,19 @@ postlaunch () { # Back up Save Data if [ -f "$STCS_SAVEPATH" ]; then #echo "Savedata $STCS_SAVEPATH is a file!" - rsync -az "$STCS_SAVEPATH" "$STCS_SYNCED_SAVADATA_PATH/" + rsync --ignore-times -az "$STCS_SAVEPATH" "$STCS_SYNCED_SAVADATA_PATH/" fi if [ -d "$STCS_SAVEPATH" ]; then #echo "Savedata $STCS_SAVEPATH is a folder!" if [ -d "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" ]; then mkdir "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" fi - rsync -az "$STCS_SAVEPATH/" "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" + rsync --ignore-times -az "$STCS_SAVEPATH/" "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" fi - date +%s | tee "$STCS_SYNCED_TIMESTAMP_PATH" - echo "[CereSaves] postlaunch complete" + local TIMESTAMP=$(date +%s) + echo "$TIMESTAMP" | tee "$STCS_SYNCED_TIMESTAMP_PATH" + logfunny "[CereSaves] New sync timestamp is $TIMESTAMP" + logfunny "[CereSaves] postlaunch complete" } checkpretimestamps () { @@ -84,6 +87,19 @@ checkpretimestamps () { fi } -prelaunch -"$@" -postlaunch \ No newline at end of file +logfunny () { + if [ -z ${STCS_DEBUG_LOG_FILE+x} ]; then + STCS_DEBUG_LOG_FILE="./stcs-log.log" + fi + + if [ ${STCS_DEBUG_LOG} -eq "1" ]; then + echo "$@" | tee -a "$STCS_DEBUG_LOG_FILE" + else + echo "$@" + fi +} + +prelaunch; +"$@"; +postlaunch; +logfunny "[CereSaves] script complete" \ No newline at end of file