36 lines
1016 B
Plaintext
36 lines
1016 B
Plaintext
#!/bin/ash
|
|
#shellcheck shell=dash
|
|
|
|
export REMOTE_BASE="RCLONE_PREFIX"
|
|
export LOG_FILE="/recalbox/share/system/logs/locksync.log"
|
|
|
|
log() {
|
|
# Ensure log directory exists
|
|
mkdir -p "$(dirname "$LOG_FILE")"
|
|
printf "[%s] [%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" "$2" >>"$LOG_FILE"
|
|
}
|
|
|
|
# Use find to pipe directly into the loop to handle spaces in filenames correctly
|
|
find /recalbox/share/saves -name "*.lock" | while read -r lockfile; do
|
|
# 1. Get the game path by removing .lock
|
|
lgame="${lockfile%.lock}"
|
|
|
|
# 2. Extract the relative path for the remote
|
|
# This removes '/recalbox/share/saves/' from the start of the path
|
|
rgame="${lgame#/recalbox/share/saves/}"
|
|
|
|
if [ -f "$lgame" ]; then
|
|
log "INFO" "Game found: $lgame"
|
|
|
|
if rclone copyto "$lgame" "${REMOTE_BASE}/${rgame}"; then
|
|
log "INFO" "Game synced: $rgame"
|
|
rm "$lockfile"
|
|
else
|
|
log "WARN" "Could not sync game $rgame"
|
|
log "INFO" "Lockfile $lockfile not removed"
|
|
fi
|
|
else
|
|
log "DEBUG" "Lock found for non-existent file: $lgame"
|
|
fi
|
|
done
|