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"
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
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"