Fixed up the script a bit, and the installer to remove cruff
This commit is contained in:
@@ -3,15 +3,12 @@
|
|||||||
ENDPOINT="https://git.sassysalamander.net/wytch/recalbox-savesync/archive/main.tar.gz"
|
ENDPOINT="https://git.sassysalamander.net/wytch/recalbox-savesync/archive/main.tar.gz"
|
||||||
cd /recalbox/share/system
|
cd /recalbox/share/system
|
||||||
curl -L -o savesync.tar.gz "$ENDPOINT"
|
curl -L -o savesync.tar.gz "$ENDPOINT"
|
||||||
|
|
||||||
tar -xvf savesync.tar.gz
|
tar -xvf savesync.tar.gz
|
||||||
|
|
||||||
rm savesync.tar.gz
|
rm savesync.tar.gz
|
||||||
cd recalbox-savesync
|
cd recalbox-savesync
|
||||||
cp *.ash /recalbox/share/userscripts/
|
cp *.ash /recalbox/share/userscripts/
|
||||||
mkdir -p /recalbox/share/system/configs/savesync
|
mkdir -p /recalbox/share/system/configs/savesync
|
||||||
cp *.conf /recalbox/share/system/configs/savesync/
|
cp *.conf /recalbox/share/system/configs/savesync/
|
||||||
|
cd ..
|
||||||
mount -o remount,rw / >/dev/null
|
rm -rf recalbox-savesync
|
||||||
curl -L -o /usr/bin/nc https://github.com/therealsaumil/static-arm-bins/raw/refs/heads/master/nc-arm-static
|
|
||||||
chmod 755 /usr/bin/nc
|
|
||||||
mount -o remount >/dev/null
|
|
||||||
|
|||||||
@@ -10,68 +10,68 @@ LOG_FILE="/recalbox/share/system/logs/savesync.log"
|
|||||||
chmod 666 "$PIPE"
|
chmod 666 "$PIPE"
|
||||||
|
|
||||||
write_log() {
|
write_log() {
|
||||||
printf "[%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" >> "$LOG_FILE"
|
printf "[%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" >>"$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
write_log "--- Daemon Started ---"
|
write_log "--- Daemon Started ---"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
# Read one line from the pipe
|
# Read one line from the pipe
|
||||||
if read -r line < "$PIPE"; then
|
if read -r line <"$PIPE"; then
|
||||||
case "$line" in
|
case "$line" in
|
||||||
LOG:*)
|
LOG:*)
|
||||||
write_log "${line#LOG:}"
|
write_log "${line#LOG:}"
|
||||||
;;
|
;;
|
||||||
EVENT:*)
|
EVENT:*)
|
||||||
# Fork the event handling
|
# Fork the event handling
|
||||||
(
|
(
|
||||||
event_data="${line#EVENT:}"
|
event_data="${line#EVENT:}"
|
||||||
|
|
||||||
# Process the multi-line event data
|
|
||||||
# We use echo and a pipe to feed the while loop
|
|
||||||
echo "$event_data" | tr -d '\r' | while IFS="=" read -r key val; do
|
|
||||||
case "$key" in
|
|
||||||
"SystemId") sid="$val" ;;
|
|
||||||
"GamePath")
|
|
||||||
gp="$val"
|
|
||||||
sp=$(echo "$val" | sed 's|roms|saves|; s|\.[^.]*$|.srm|')
|
|
||||||
bp=$(echo "$sp" | sed 's|saves|archives|')
|
|
||||||
;;
|
|
||||||
"Action") act="$val" ;;
|
|
||||||
"State")
|
|
||||||
st="$val"
|
|
||||||
|
|
||||||
if [ "$st" = "playing" ] && [ "$act" = "rungame" ]; then
|
# Process the multi-line event data
|
||||||
write_log "Sync START: $(basename "$gp")"
|
# We use echo and a pipe to feed the while loop
|
||||||
|
echo "$event_data" | tr -d '\r' | while IFS="=" read -r key val; do
|
||||||
remote_f="$REMOTE_BASE/$sid/$(basename "$sp")"
|
case "$key" in
|
||||||
loc_sz=$(stat -c %s "$sp" 2>/dev/null || echo 0)
|
"SystemId") sid="$val" ;;
|
||||||
rem_sz=$(rclone lsjson "$remote_f" 2>/dev/null | grep -o '"Size":[0-9]*' | cut -d: -f2)
|
"GamePath")
|
||||||
: "${rem_sz:=0}"
|
gp="$val"
|
||||||
|
sp=$(echo "$val" | sed 's|roms|saves|; s|\.[^.]*$|.srm|')
|
||||||
|
bp=$(echo "$sp" | sed 's|saves|archives|')
|
||||||
|
;;
|
||||||
|
"Action") act="$val" ;;
|
||||||
|
"State")
|
||||||
|
st="$val"
|
||||||
|
|
||||||
if [ "$loc_sz" -lt "$rem_sz" ]; then
|
if [ "$st" = "playing" ] && [ "$act" = "rungame" ]; then
|
||||||
write_log "Cloud save larger ($rem_sz). Restoring..."
|
write_log "Sync START: $(basename "$gp")"
|
||||||
mkdir -p "$(dirname "$bp")"
|
|
||||||
rclone copyto "$remote_f" "$sp" --backup-dir "$(dirname "$bp")"
|
|
||||||
else
|
|
||||||
write_log "Local save current. Updating..."
|
|
||||||
rclone update "$remote_f" "$sp"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Signal back to the publisher via MQTT or a second Response Pipe
|
|
||||||
#mosquitto_pub -t "$RESPONSE_TOPIC" -m "SaveSync=0" 2>/dev/null
|
|
||||||
|
|
||||||
elif [ "$st" = "endgame" ]; then
|
remote_f="$REMOTE_BASE/$sid/$(basename "$sp")"
|
||||||
write_log "Sync END: $(basename "$sp")"
|
loc_sz=$(stat -c %s "$sp" 2>/dev/null || echo 0)
|
||||||
rclone update "$sp" "$REMOTE_BASE/$sid/"
|
rem_sz=$(rclone lsjson "$remote_f" 2>/dev/null | grep -o '"Size":[0-9]*' | cut -d: -f2)
|
||||||
write_log "Final Sync Done."
|
: "${rem_sz:=0}"
|
||||||
#mosquitto_pub -t "$RESPONSE_TOPIC" -m "SaveSync=0" 2>/dev/null
|
|
||||||
fi
|
if [ "$loc_sz" -lt "$rem_sz" ]; then
|
||||||
;;
|
write_log "Cloud save larger ($rem_sz). Restoring..."
|
||||||
esac
|
mkdir -p "$(dirname "$bp")"
|
||||||
done
|
rclone copyto "$remote_f" "$sp" --backup-dir "$(dirname "$bp")"
|
||||||
) &
|
else
|
||||||
;;
|
write_log "Local save current. Updating..."
|
||||||
esac
|
rclone update "$remote_f" "$sp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Signal back to the publisher via MQTT or a second Response Pipe
|
||||||
|
#mosquitto_pub -t "$RESPONSE_TOPIC" -m "SaveSync=0" 2>/dev/null
|
||||||
|
|
||||||
|
elif [ "$st" = "endgame" ]; then
|
||||||
|
write_log "Sync END: $(basename "$sp")"
|
||||||
|
rclone update "$sp" "$REMOTE_BASE/$sid/"
|
||||||
|
write_log "Final Sync Done."
|
||||||
|
#mosquitto_pub -t "$RESPONSE_TOPIC" -m "SaveSync=0" 2>/dev/null
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
) &
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user