Massive updates, added install for nc binary
This commit is contained in:
@@ -10,3 +10,8 @@ cd recalbox-savesync
|
|||||||
cp *.ash /recalbox/share/userscripts/
|
cp *.ash /recalbox/share/userscripts/
|
||||||
mkdir -p /recalbox/share/system/config/savesync
|
mkdir -p /recalbox/share/system/config/savesync
|
||||||
cp *.conf /recalbox/share/system/config/savesync/
|
cp *.conf /recalbox/share/system/config/savesync/
|
||||||
|
|
||||||
|
mount -o remount,rw /
|
||||||
|
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,ro
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#!/bin/ash
|
#!/bin/ash
|
||||||
# shellcheck shell=ash
|
# shellcheck shell=ash
|
||||||
#
|
|
||||||
ERROR_LOG="/recalbox/share/system/logs/savesync-error.log"
|
# -- Load Configs ---
|
||||||
|
. /recalbox/share/system/config/savesync/savesync.conf
|
||||||
|
|
||||||
# --- Logger Function ---
|
# --- Logger Function ---
|
||||||
log() {
|
log() {
|
||||||
local timestamp
|
local timestamp
|
||||||
local level="$1"
|
local level="$1"
|
||||||
local msg="$2"
|
local msg="$2"
|
||||||
mkdir -p "$(dirname \"$ERROR_LOG\")"
|
mkdir -p "$(dirname "$ERROR_LOG")"
|
||||||
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
local log_line="[$timestamp] [$level] $msg"
|
local log_line="[$timestamp] [$level] $msg"
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ log() {
|
|||||||
printf "%s\n" "$log_line" >> "$ERROR_LOG"
|
printf "%s\n" "$log_line" >> "$ERROR_LOG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "SaveLog=${log_line}"
|
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "SaveLog=${log_line}"
|
||||||
|
|
||||||
# printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
|
# printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
|
||||||
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
||||||
@@ -33,20 +34,31 @@ fi
|
|||||||
# 2. Read the payload safely
|
# 2. Read the payload safely
|
||||||
PAYLOAD=$(cat "$eventfile")
|
PAYLOAD=$(cat "$eventfile")
|
||||||
|
|
||||||
# 3. Publish (using double quotes to handle spaces/newlines in the file)
|
connect_success=0
|
||||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "$PAYLOAD"
|
for i in $(seq 10); do
|
||||||
|
if [ nc -z "$RCLONE_ENDPOINT" "$RCLONE_PORT" -eq 0 ] {
|
||||||
|
connect_success=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
# 4. Optional: check if the publish succeeded
|
# 3. Publish and log success/failure
|
||||||
if [ $? -eq 0 ]; then
|
if [ mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "$PAYLOAD" -eq 0 ]; then
|
||||||
log "INFO" "Successfully published event."
|
log "INFO" "Successfully published event."
|
||||||
else
|
else
|
||||||
log "ERROR" "Failed to connect to mosquitto broker."
|
log "ERROR" "Failed to connect to mosquitto broker."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mosquitto_sub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event | while IFS="=" read -r key value
|
# 4. Wait for response from daemon
|
||||||
|
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$TOPIC" | while IFS="=" read -r key value
|
||||||
do
|
do
|
||||||
case "$key" in
|
case "$key" in
|
||||||
"SaveSync") exit "$value" ;;
|
"SaveSync") break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$value" -eq 0 ]; then
|
||||||
|
log "WARN" "pub_event exited normally"
|
||||||
|
else
|
||||||
|
log "INFO" "pub_event exited with warnings"
|
||||||
|
fi
|
||||||
|
|||||||
11
savesync-logger[start](permanent).ash
Normal file
11
savesync-logger[start](permanent).ash
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/ash
|
||||||
|
#shellcheck shell=dash
|
||||||
|
#
|
||||||
|
. /recalbox/share/system/configs/savesync/savesync.conf
|
||||||
|
|
||||||
|
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$TOPIC" | while IFS="=" read -r key value
|
||||||
|
do
|
||||||
|
case "$key" in
|
||||||
|
"SaveLog") printf "%s\n" "$value" >> "$LOG_FILE" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
LOG_FILE="/recalbox/share/system/logs/savesync_monitor.log"
|
export LOG_FILE="/recalbox/share/system/logs/savesync_monitor.log"
|
||||||
DEBUG_MODE=1
|
export ERROR_FILE="/recalbox/share/system/logs/savesync_error.log"
|
||||||
REMOTE_BASE="saves:gamepi-tv"
|
export DEBUG_MODE=1
|
||||||
|
export REMOTE_BASE="saves:gamepi-tv"
|
||||||
|
export TOPIC="/Recalbox/SaveSync/Event"
|
||||||
|
|||||||
@@ -5,14 +5,6 @@
|
|||||||
. /recalbox/share/system/config/savesync/savesync.conf
|
. /recalbox/share/system/config/savesync/savesync.conf
|
||||||
|
|
||||||
|
|
||||||
# --- MQTT Publish Function ---
|
|
||||||
mqtt_publish() {
|
|
||||||
|
|
||||||
local msg="$1"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# --- Logger Function ---
|
# --- Logger Function ---
|
||||||
log() {
|
log() {
|
||||||
local timestamp
|
local timestamp
|
||||||
@@ -22,20 +14,24 @@ log() {
|
|||||||
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
local log_line="[$timestamp] [$level] $msg"
|
local log_line="[$timestamp] [$level] $msg"
|
||||||
|
|
||||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "SaveLog=${log_line}"
|
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "SaveLog=${log_line}"
|
||||||
|
|
||||||
# printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
|
# printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
|
||||||
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Continue message function ---
|
||||||
send_continue() {
|
send_continue() {
|
||||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "SaveContinue=1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Sleep to ensure that the logger daemon has started ---
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
log "INFO" "--- ES Event Daemon Started ---"
|
log "INFO" "--- ES Event Daemon Started ---"
|
||||||
|
|
||||||
# --- Main Listener Loop ---
|
# --- Main Listener Loop ---
|
||||||
mosquitto_sub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event | while IFS="=" read -r key value
|
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$TOPIC" | while IFS="=" read -r key value
|
||||||
do
|
do
|
||||||
# 1. Clean Carriage Returns from Windows-style line endings
|
# 1. Clean Carriage Returns from Windows-style line endings
|
||||||
value=$(echo "$value" | tr -d '\r')
|
value=$(echo "$value" | tr -d '\r')
|
||||||
@@ -74,6 +70,7 @@ do
|
|||||||
rclone update "$remote_full" "$this_save_path"
|
rclone update "$remote_full" "$this_save_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "SaveContinue=0"
|
||||||
elif [ "$this_state" = "endgame" ]; then
|
elif [ "$this_state" = "endgame" ]; then
|
||||||
log "INFO" "Game Ended. Backing up save..."
|
log "INFO" "Game Ended. Backing up save..."
|
||||||
filename=$(basename "$this_save_path")
|
filename=$(basename "$this_save_path")
|
||||||
@@ -82,6 +79,8 @@ do
|
|||||||
# Push the local save to the cloud if it's newer
|
# Push the local save to the cloud if it's newer
|
||||||
rclone update "$this_save_path" "$REMOTE_BASE/$this_system_id/"
|
rclone update "$this_save_path" "$REMOTE_BASE/$this_system_id/"
|
||||||
log "INFO" "Sync Complete."
|
log "INFO" "Sync Complete."
|
||||||
|
|
||||||
|
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "SaveContinue=0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reset variables for the next event block
|
# Reset variables for the next event block
|
||||||
|
|||||||
Reference in New Issue
Block a user