60 lines
1.4 KiB
Plaintext
60 lines
1.4 KiB
Plaintext
#!/bin/ash
|
|
#shellcheck shell=dash
|
|
#
|
|
|
|
event_data=$(cat /tmp/es_state.inf | tr -d '\r' )
|
|
|
|
REMOTE_BASE="saves:gamepi-tv"
|
|
PIPE="/tmp/savesync_pipe"
|
|
#DEBUG=1
|
|
|
|
log() {
|
|
# $1 = level
|
|
# $2 = message
|
|
printf "LOG:[%s] %s\n" "$1" "$2" >"$PIPE"
|
|
}
|
|
|
|
#log "DEBUG" "Starting based on event: $(echo "$event_data" | tr '\n' ',')"
|
|
|
|
## Iterate over the data
|
|
echo "$event_data" | while IFS='=' read -r k v; do
|
|
key=$(echo "$k" | tr -d '\n')
|
|
val=$(echo "$v" | tr -d '\n')
|
|
|
|
# set variables and run functions based on the pairs
|
|
case "$key" in
|
|
"SystemId")
|
|
sid="$val"
|
|
#log "DEBUG" "Setting sid=$sid"
|
|
;;
|
|
"GamePath")
|
|
gp="$val"
|
|
sp=$(echo "$val" | sed 's|roms|saves|; s|\.[^.]*$|.srm|')
|
|
bp=$(echo "$sp" | sed 's|saves|archives|')
|
|
#log "DEBUG" "Setting values {gp=$gp, sp=$sp, bp=$bp}"
|
|
;;
|
|
"Action")
|
|
act="$val"
|
|
#log "DEBUG" "Setting act=$act"
|
|
;;
|
|
"State")
|
|
st="$val"
|
|
#log "DEBUG" "Setting st=$st"
|
|
#log "DEBUG" "Starting logic tree"
|
|
if [ "$st" = "playing" ] && [ "$act" = "rungame" ]; then
|
|
log "INFO" "Sync START: $(basename "$gp")"
|
|
remote_f="$REMOTE_BASE/$sid/$(basename "$sp")"
|
|
#log "DEBUG" "rclone update $remote_f $sp"
|
|
find "$sp" -size -256 -delete
|
|
rclone update "$remote_f" "$sp"
|
|
log "INFO" "Start sync done"
|
|
elif [ "$st" = "endgame" ]; then
|
|
log "INFO" "Sync END: $(basename "$sp")"
|
|
#log "DEBUG" "rclone update $sp $REMOTE_BASE/$sid/"
|
|
rclone update "$sp" "$REMOTE_BASE/$sid/"
|
|
log "INFO" "Final Sync Done."
|
|
fi
|
|
;;
|
|
esac
|
|
done
|