added reasonable debug logging

This commit is contained in:
Cere 2024-07-08 05:12:28 -04:00
parent ae33901201
commit adb298c2c9

View file

@ -4,20 +4,20 @@
STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh" STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh"
if [ -z ${STCS_GAME_CONFIG+x} ]; then 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" STCS_GAME_CONFIG="./stcs-config.sh"
else else
echo "[CereSaves] Game config is set to '$STCS_GAME_CONFIG'"; logfunny "[CereSaves] Game config is set to '$STCS_GAME_CONFIG'";
fi fi
if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then
echo "[CereSaves] Global config not found!" logfunny "[CereSaves] Global config not found!"
exit 1 exit 1
fi fi
# TODO - find a way to make this not a static filename, for multiple games in one folder. # TODO - find a way to make this not a static filename, for multiple games in one folder.
if [ ! -f "$STCS_GAME_CONFIG" ]; then if [ ! -f "$STCS_GAME_CONFIG" ]; then
echo "[CereSaves] Game config not found!" logfunny "[CereSaves] Game config not found!"
exit 1 exit 1
fi fi
@ -29,24 +29,25 @@ STCS_SYNCED_TIMESTAMP_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}.timestamp"
STCS_SYNCED_SAVADATA_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}" STCS_SYNCED_SAVADATA_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}"
prelaunch () { prelaunch () {
echo "[CereSaves] prelaunch start" logfunny "[CereSaves] prelaunch start"
if checkpretimestamps; then if checkpretimestamps; then
# Assume Save Data needs to be restored! # Assume Save Data needs to be restored!
logfunny "[CereSaves] Update to local savedata detected!"
if [ -f "$STCS_SAVEPATH" ]; then if [ -f "$STCS_SAVEPATH" ]; then
#echo "Savedata $STCS_SAVEPATH is a file!" #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 fi
if [ -d "$STCS_SAVEPATH" ]; then if [ -d "$STCS_SAVEPATH" ]; then
#echo "Savedata $STCS_SAVEPATH is a folder!" #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 fi
rsync -az "$STCS_SYNCED_TIMESTAMP_PATH" "$STCS_CACHED_TIMESTAMP_PATH" rsync -az --ignore-times "$STCS_SYNCED_TIMESTAMP_PATH" "$STCS_CACHED_TIMESTAMP_PATH"
fi fi
echo "[CereSaves] prelaunch complete" logfunny "[CereSaves] prelaunch complete"
} }
postlaunch () { postlaunch () {
echo "[CereSaves] postlaunch start" logfunny "[CereSaves] postlaunch start"
# Create Backup Dir if it doesn't exist. # Create Backup Dir if it doesn't exist.
if [ ! -d "$STCS_SYNCED_SAVADATA_PATH" ]; then if [ ! -d "$STCS_SYNCED_SAVADATA_PATH" ]; then
mkdir "$STCS_SYNCED_SAVADATA_PATH" mkdir "$STCS_SYNCED_SAVADATA_PATH"
@ -54,17 +55,19 @@ postlaunch () {
# Back up Save Data # Back up Save Data
if [ -f "$STCS_SAVEPATH" ]; then if [ -f "$STCS_SAVEPATH" ]; then
#echo "Savedata $STCS_SAVEPATH is a file!" #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 fi
if [ -d "$STCS_SAVEPATH" ]; then if [ -d "$STCS_SAVEPATH" ]; then
#echo "Savedata $STCS_SAVEPATH is a folder!" #echo "Savedata $STCS_SAVEPATH is a folder!"
if [ -d "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" ]; then if [ -d "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" ]; then
mkdir "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" mkdir "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/"
fi 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 fi
date +%s | tee "$STCS_SYNCED_TIMESTAMP_PATH" local TIMESTAMP=$(date +%s)
echo "[CereSaves] postlaunch complete" echo "$TIMESTAMP" | tee "$STCS_SYNCED_TIMESTAMP_PATH"
logfunny "[CereSaves] New sync timestamp is $TIMESTAMP"
logfunny "[CereSaves] postlaunch complete"
} }
checkpretimestamps () { checkpretimestamps () {
@ -84,6 +87,19 @@ checkpretimestamps () {
fi fi
} }
prelaunch logfunny () {
"$@" if [ -z ${STCS_DEBUG_LOG_FILE+x} ]; then
postlaunch 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"