Ok, I reduced the autostart.sh script to bare minimum. This is the debug script. I left the CIFS storage mount files in /storage/.config/system.d/. Since the storage mounts are attempted prior to the execution of autostart.sh, this enabled me to more easily see if LibreELEC was establishing a connection or the autostart.sh script was establishing the connection. If LibreELEC failed to make a connection the storage mounts would fail with pretty obnoxious error message during boot up. No error during boot meant LibreELEC made the connection.
That was my naming convention. Success or Failure zip files mean LibreELEC succeeded or failed.
However, in combination with the script below, I could not get LibreELEC to fail to establish a connection using the Nightly Build from 10.08.2024. Every. Single. Time. I tried multiple times. At least 20x reboots. Not one single failed connection. Either the script made the connection or LibreELEC did. This basically means the script never fails to establish a connection because a) there is no check for an existing connection so it can exit. b) there is no retry logic in the script (aside from the retries built into iwd and connmand).
I've attached the logs for your review. There is an 'invalid-key' in it though; so, it is indeed a workaround not a fix.
Now, I just need to append a quick test for a valid IP Address and the line of code below and I am golden. My mounts will be established as well.
for m in $(find /storage/.config/system.d/ -iname storage-*.mount -exec basename "{}" \;); do systemctl start $m; done
Here's the abridged, debug version of the script:
#!/bin/sh
# Global Variables
SSID="serendrewpity"
SECRET="BoogerA!ds"
SLEEP_TIME=3 # Time to pause between retries (in seconds)
LOGFILE="/storage/.config/autostart.log"
# Truncate the log file at the beginning of the script
> "$LOGFILE"
# Logging function to prepend timestamp to each log entry
log() {
while IFS= read -r line; do
echo "$(date '+%a %b %-d %H:%M:%S %Z %Y') - $line" >> "$LOGFILE"
done
}
# Redirect stdout and stderr to the log function
exec > >(log) 2>&1
# Start Processing of AutoStart script.
echo "AutoStart script is starting."
# Start Processing of AutoStart script.
echo "Stopping the default ConnMan and Internet Wireless Daemon services."
systemctl stop connman
systemctl stop iwd
kill -9 $(pgrep connmand) $(pgrep iwd)
# Starting IWD.
echo "Starting the Internet Wireless Daemon service."
nohup /usr/lib/iwd --debug > /storage/.config/iwd_debug.log 2>&1 &
sleep 2
# Starting ConnMan.
echo "Starting the ConnMan daemon service."
nohup /usr/sbin/connmand --debug > /storage/.config/connman_debug.log 2>&1 &
sleep 2
# Perform an initial scan
echo "Scanning for Wifi Networks."
iwctl station wlan0 scan
connmanctl scan wifi
# Attempt to connect to Wifi on wlan0
echo "Attempting to connect to Wifi SSID on wlan0."
ERROR=$(/usr/bin/iwctl station wlan0 connect $SSID --passphrase=$SECRET 2>&1)
timeout=$(($(date +%s) + 25))
until [ -n "$(ip -4 route get 8.8.8.8 2>/dev/null | awk {'print $7'} | tr -d '\n')" ] || [ $(date +%s) -gt $timeout ]; do sleep $SLEEP_TIME; done
journalctl | grep -E 'iwd\[|connmand\['
# AutoStart script finished.
echo "AutoStart script finished."
Display More
The stanza for 'journalctl' in the script is pretty slick. It captures every single command from 'iwd' or 'connmand' from the start of boot.