Massive updates, added install for nc binary

This commit is contained in:
2026-02-27 19:09:47 -06:00
parent 031ad72f59
commit 7cbcf806e4
5 changed files with 53 additions and 24 deletions

View File

@@ -1,14 +1,15 @@
#!/bin/ash
# shellcheck shell=ash
#
ERROR_LOG="/recalbox/share/system/logs/savesync-error.log"
# -- Load Configs ---
. /recalbox/share/system/config/savesync/savesync.conf
# --- Logger Function ---
log() {
local timestamp
local level="$1"
local msg="$2"
mkdir -p "$(dirname \"$ERROR_LOG\")"
mkdir -p "$(dirname "$ERROR_LOG")"
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local log_line="[$timestamp] [$level] $msg"
@@ -16,7 +17,7 @@ log() {
printf "%s\n" "$log_line" >> "$ERROR_LOG"
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
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
@@ -33,20 +34,31 @@ fi
# 2. Read the payload safely
PAYLOAD=$(cat "$eventfile")
# 3. Publish (using double quotes to handle spaces/newlines in the file)
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "$PAYLOAD"
connect_success=0
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
if [ $? -eq 0 ]; then
# 3. Publish and log success/failure
if [ mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "$PAYLOAD" -eq 0 ]; then
log "INFO" "Successfully published event."
else
log "ERROR" "Failed to connect to mosquitto broker."
exit 1
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
case "$key" in
"SaveSync") exit "$value" ;;
"SaveSync") break;;
esac
done
if [ "$value" -eq 0 ]; then
log "WARN" "pub_event exited normally"
else
log "INFO" "pub_event exited with warnings"
fi