62 lines
1.6 KiB
Bash
Executable File
62 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Monitor progress of SWUpdate and report it
|
|
|
|
TMPDIR="/tmp"
|
|
FIFO="$TMPDIR/swupdate-progress"
|
|
|
|
# Create FIFO if it doesn't exist
|
|
if [ ! -e "$FIFO" ]; then
|
|
mkfifo "$FIFO"
|
|
fi
|
|
|
|
# If no arguments, print usage
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: $0 <command>"
|
|
echo "Commands:"
|
|
echo " monitor - Monitor progress of an update"
|
|
echo " status - Show current status"
|
|
exit 1
|
|
fi
|
|
|
|
case "$1" in
|
|
monitor)
|
|
# Start monitoring FIFO
|
|
while true; do
|
|
if read line <"$FIFO"; then
|
|
echo "$line"
|
|
# Extract progress percentage
|
|
PROGRESS=$(echo "$line" | grep -o '[0-9]*%' | grep -o '[0-9]*')
|
|
if [ -n "$PROGRESS" ] && [ "$PROGRESS" = "100" ]; then
|
|
echo "Update complete!"
|
|
break
|
|
fi
|
|
# Check for error messages
|
|
if echo "$line" | grep -q "FAILURE"; then
|
|
echo "Update failed!"
|
|
break
|
|
fi
|
|
else
|
|
# FIFO closed
|
|
echo "Connection closed"
|
|
break
|
|
fi
|
|
done
|
|
;;
|
|
status)
|
|
# Show which partition is active
|
|
ACTIVE_PART=$(fw_printenv -n active_part 2>/dev/null || echo "Unknown")
|
|
echo "Active partition: $ACTIVE_PART"
|
|
# Show update status if available
|
|
if [ -e /tmp/swupdate.done ]; then
|
|
echo "Last update: Successful"
|
|
else
|
|
echo "No recent update"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Unknown command: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0 |