Updated functions for better error handling and logging feedback
This commit is contained in:
@@ -11,7 +11,7 @@ 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 / 2>/dev/null
|
mount -o remount,rw / >/dev/null
|
||||||
curl -L -o /usr/bin/nc https://github.com/therealsaumil/static-arm-bins/raw/refs/heads/master/nc-arm-static
|
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
|
chmod 755 /usr/bin/nc
|
||||||
mount -o remount,ro >/dev/null
|
mount -o remount >/dev/null
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ log() {
|
|||||||
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Exit function ---
|
||||||
|
call_exit() {
|
||||||
|
value="$1"
|
||||||
|
if [ "$value" -eq 0 ]; then
|
||||||
|
log "WARN" "pub_event exited normally"
|
||||||
|
else
|
||||||
|
log "INFO" "pub_event exited with warnings"
|
||||||
|
fi
|
||||||
|
exit "$value"
|
||||||
|
}
|
||||||
|
|
||||||
eventfile="/tmp/es_state.inf"
|
eventfile="/tmp/es_state.inf"
|
||||||
|
|
||||||
# 1. Check if the file exists and is not empty
|
# 1. Check if the file exists and is not empty
|
||||||
@@ -34,31 +45,30 @@ fi
|
|||||||
# 2. Read the payload safely
|
# 2. Read the payload safely
|
||||||
PAYLOAD=$(cat "$eventfile")
|
PAYLOAD=$(cat "$eventfile")
|
||||||
|
|
||||||
|
# 3. Wait for connection to rclone endpoint
|
||||||
connect_success=0
|
connect_success=0
|
||||||
for i in $(seq 10); do
|
for i in $(seq 5); do
|
||||||
if [ nc -z "$RCLONE_ENDPOINT" "$RCLONE_PORT" -eq 0 ] {
|
log "INFO" "Waiting on rclone endpoint... $i"
|
||||||
connect_success=1
|
[ "$(nc -z "$RCLONE_ENDPOINT" "$RCLONE_PORT")" ] || connect_success=1
|
||||||
break
|
[ "$connect_success" ] && break
|
||||||
fi
|
sleep 0.5
|
||||||
|
done
|
||||||
|
|
||||||
# 3. Publish and log success/failure
|
[ "$connect_success" ] || ( log "ERROR" "Remote repository not accessable" && exit 1 )
|
||||||
if [ mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "$PAYLOAD" -eq 0 ]; then
|
|
||||||
log "INFO" "Successfully published event."
|
# 4. Publish and log success/failure
|
||||||
else
|
if [ "$(mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "$PAYLOAD")" ]; then
|
||||||
log "ERROR" "Failed to connect to mosquitto broker."
|
log "ERROR" "Failed to connect to mosquitto broker."
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
log "INFO" "Successfully published event."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 4. Wait for response from daemon
|
# 5. Wait for response from daemon
|
||||||
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$TOPIC" | 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
|
||||||
case "$key" in
|
case "$key" in
|
||||||
"SaveSync") break;;
|
"SaveSync") call_exit "$value";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$value" -eq 0 ]; then
|
|
||||||
log "WARN" "pub_event exited normally"
|
|
||||||
else
|
|
||||||
log "INFO" "pub_event exited with warnings"
|
|
||||||
fi
|
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ log() {
|
|||||||
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Continue message function ---
|
|
||||||
send_continue() {
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Sleep to ensure that the logger daemon has started ---
|
# --- Sleep to ensure that the logger daemon has started ---
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user