mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-25 17:36:29 -05:00
moved user led activation to rc.local, added windows carriage return removal to usbconfig, removed reboot from usbconfig, changed led boot code for successful usb config.
This commit is contained in:
parent
d0fa5bfaa9
commit
1498015dbf
2 changed files with 51 additions and 43 deletions
|
|
@ -15,10 +15,10 @@ echo 'ds1307 0x68' | sudo tee /sys/class/i2c-adapter/i2c-3/new_device > /dev/nul
|
|||
if ls /dev/rtc* 1> /dev/null 2>&1; then
|
||||
rtc="true"
|
||||
if sudo hwclock -s 2>&1 | grep -a failed > /dev/null 2>&1; then
|
||||
echo "RTC device found but failed to get time."
|
||||
echo "RTC device found but failed to get time."
|
||||
else
|
||||
hwclock -s > /dev/null 2>&1 &
|
||||
echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")."
|
||||
hwclock -s > /dev/null 2>&1 &
|
||||
echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")."
|
||||
fi
|
||||
else
|
||||
echo "RTC not found."
|
||||
|
|
@ -41,6 +41,8 @@ fi
|
|||
echo "Disabling LED..."
|
||||
echo "none" > /sys/class/leds/work/trigger &
|
||||
|
||||
echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction
|
||||
|
||||
# necessary for internet over usb in otg mode (see https://web.archive.org/web/20241006173648/https://wiki.luckfox.com/Luckfox-Pico/Luckfox-Pico-Network-Sharing-1/)
|
||||
# sleep 5 && route add default gw 172.32.0.100 && echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
||||
|
||||
|
|
@ -50,11 +52,14 @@ echo "none" > /sys/class/leds/work/trigger &
|
|||
/usr/local/bin/usbconfig.sh
|
||||
|
||||
#boot complete, blink USER LED 5 times in background
|
||||
echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction && (
|
||||
(
|
||||
sleep 1
|
||||
for i in $(seq 1 5); do
|
||||
echo 1 > /sys/class/gpio/gpio34/value;
|
||||
sleep 0.5;
|
||||
echo 0 > /sys/class/gpio/gpio34/value; sleep 0.5; done
|
||||
echo 1 > /sys/class/gpio/gpio34/value;
|
||||
sleep 0.5;
|
||||
echo 0 > /sys/class/gpio/gpio34/value;
|
||||
sleep 0.5;
|
||||
done
|
||||
) &
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -1,40 +1,37 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set the mount point for the USB drive
|
||||
# Set the mount point
|
||||
MOUNT_POINT="/mnt/usb"
|
||||
|
||||
# Export GPIO pin 34 and set its direction to output
|
||||
echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction
|
||||
|
||||
# Function to log messages both to the screen and the system log
|
||||
# Function to log both to the screen and syslog
|
||||
log_message() {
|
||||
local msg="USB automount: $1"
|
||||
local msg="USB config: $1"
|
||||
echo "$msg" # Echo to the screen
|
||||
logger "USB automount: $msg" # Log to the system log
|
||||
logger "USB config: $msg" # Log to the system log
|
||||
}
|
||||
|
||||
# Function to blink the LED connected to GPIO pin 34
|
||||
#Blink
|
||||
blink() {
|
||||
echo 1 > /sys/class/gpio/gpio34/value # Turn on the LED
|
||||
sleep "$1" # Sleep for the specified duration
|
||||
echo 0 > /sys/class/gpio/gpio34/value # Turn off the LED
|
||||
echo 1 > /sys/class/gpio/gpio34/value;
|
||||
sleep "$1";
|
||||
echo 0 > /sys/class/gpio/gpio34/value;
|
||||
}
|
||||
|
||||
# Function to escape special characters for use with sed
|
||||
escape_sed() {
|
||||
echo "$1" | sed -e 's/[]\/$*.^[]/\\&/g'
|
||||
echo "$1" | sed -e 's/[]\/$*.^[]/\\&/g'
|
||||
}
|
||||
|
||||
# Check if the mount point exists and delete it if it does
|
||||
# Check if the mount point exists and if a USB drive is plugged in
|
||||
USB_DEVICE=$(lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep -E "vfat|ext4|ntfs|exfat" | grep -E "sd[a-z][0-9]" | awk '{print $1}' | sed 's/[^a-zA-Z0-9]//g' | head -n 1)
|
||||
|
||||
if [ -d "$MOUNT_POINT" ]; then
|
||||
sudo rmdir "$MOUNT_POINT"
|
||||
log_message "/mnt/usb deleted."
|
||||
fi
|
||||
|
||||
# Find a USB device that has a recognized filesystem (vfat, ext4, ntfs, exfat)
|
||||
USB_DEVICE=$(lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep -E "vfat|ext4|ntfs|exfat" | grep -E "sd[a-z][0-9]" | awk '{print $1}' | sed 's/[^a-zA-Z0-9]//g' | head -n 1)
|
||||
|
||||
# If no USB device is found, log a message and exit
|
||||
# If no USB device is found, exit
|
||||
if [ -z "$USB_DEVICE" ]; then
|
||||
log_message "No USB drive found."
|
||||
exit 0
|
||||
|
|
@ -48,7 +45,8 @@ fi
|
|||
# Construct the full device path
|
||||
USB_DEVICE="/dev/$USB_DEVICE"
|
||||
|
||||
# Debugging: Log the extracted device name
|
||||
|
||||
# Debugging: Log and echo the extracted device name
|
||||
log_message "Extracted device name: $USB_DEVICE"
|
||||
|
||||
# Check if the USB drive is already mounted
|
||||
|
|
@ -66,15 +64,18 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
# Check if the mounted USB drive contains a file named femtofox-config.txt
|
||||
# Check if the mounted USB drive contains a file femtofox-config.txt
|
||||
if [ -f "$MOUNT_POINT/femtofox-config.txt" ]; then
|
||||
log_message "femtofox-config.txt found on USB drive."
|
||||
|
||||
# Set paths for configuration files
|
||||
# Remove Windows-style carriage returns
|
||||
tr -d '\r' < "$MOUNT_POINT/femtofox-config.txt" > "$MOUNT_POINT/femtofox-config.txt.tmp"
|
||||
mv "$MOUNT_POINT/femtofox-config.txt.tmp" "$MOUNT_POINT/femtofox-config.txt"
|
||||
|
||||
WPA_SUPPLICANT_CONF="/etc/wpa_supplicant/wpa_supplicant.conf"
|
||||
USB_CONFIG="$MOUNT_POINT/femtofox-config.txt"
|
||||
|
||||
# Initialize variables for configuration fields
|
||||
# Initialize variables
|
||||
SSID=""
|
||||
PSK=""
|
||||
COUNTRY=""
|
||||
|
|
@ -82,13 +83,13 @@ if [ -f "$MOUNT_POINT/femtofox-config.txt" ]; then
|
|||
|
||||
# Read the fields from the USB config file if they exist
|
||||
if grep -q 'ssid=' "$USB_CONFIG"; then
|
||||
SSID=$(grep 'ssid=' "$USB_CONFIG" | sed 's/ssid=//' | tr -d '"')
|
||||
SSID=$(grep 'ssid=' "$USB_CONFIG" | sed 's/ssid=//' | tr -d '"')
|
||||
fi
|
||||
if grep -q 'psk=' "$USB_CONFIG"; then
|
||||
PSK=$(grep 'psk=' "$USB_CONFIG" | sed 's/psk=//' | tr -d '"')
|
||||
PSK=$(grep 'psk=' "$USB_CONFIG" | sed 's/psk=//' | tr -d '"')
|
||||
fi
|
||||
if grep -q 'country=' "$USB_CONFIG"; then
|
||||
COUNTRY=$(grep 'country=' "$USB_CONFIG" | sed 's/country=//' | tr -d '"')
|
||||
COUNTRY=$(grep 'country=' "$USB_CONFIG" | sed 's/country=//' | tr -d '"')
|
||||
fi
|
||||
|
||||
# Escape special characters for sed
|
||||
|
|
@ -98,34 +99,36 @@ if [ -f "$MOUNT_POINT/femtofox-config.txt" ]; then
|
|||
|
||||
# Update wpa_supplicant.conf with the new values if they exist
|
||||
if [[ -n "$COUNTRY" ]]; then
|
||||
sed -i "s/^\(country=\).*/\1$ESCAPED_COUNTRY/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated country in wpa_supplicant.conf from femtofox-config.txt to $COUNTRY."
|
||||
FOUNDCONFIG="true"
|
||||
sed -i "s/^\(country=\).*/\1$ESCAPED_COUNTRY/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated country in wpa_supplicant.conf from femtofox-config.txt to $COUNTRY."
|
||||
FOUNDCONFIG="true"
|
||||
fi
|
||||
if [[ -n "$SSID" ]]; then
|
||||
sed -i "/ssid=/s/\".*\"/\"$ESCAPED_SSID\"/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated SSID in wpa_supplicant.conf from femtofox-config.txt to $SSID."
|
||||
FOUNDCONFIG="true"
|
||||
sed -i "/ssid=/s/\".*\"/\"$ESCAPED_SSID\"/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated SSID in wpa_supplicant.conf from femtofox-config.txt to $SSID."
|
||||
FOUNDCONFIG="true"
|
||||
fi
|
||||
if [[ -n "$PSK" ]]; then
|
||||
sed -i "/psk=/s/\".*\"/\"$ESCAPED_PSK\"/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated PSK in wpa_supplicant.conf from femtofox-config.txt."
|
||||
FOUNDCONFIG="true"
|
||||
sed -i "/psk=/s/\".*\"/\"$ESCAPED_PSK\"/" "$WPA_SUPPLICANT_CONF"
|
||||
log_message "Updated PSK in wpa_supplicant.conf from femtofox-config.txt."
|
||||
FOUNDCONFIG="true"
|
||||
fi
|
||||
|
||||
# If any configuration was updated, blink the LED and reboot the system
|
||||
if [ "$FOUNDCONFIG" = true ]; then
|
||||
for _ in {1..5}; do
|
||||
for _ in {1..10}; do
|
||||
blink "0.125" && sleep 0.125
|
||||
done
|
||||
log_message "wpa_supplicant.conf updated, rebooting."
|
||||
sleep 2 && reboot
|
||||
log_message "wpa_supplicant.conf updated and restarted, proceeding with boot."
|
||||
sudo systemctl restart wpa_supplicant
|
||||
sudo wpa_cli -i wlan0 reconfigure
|
||||
|
||||
else
|
||||
log_message "femtofox-config.txt does not contain valid configuration info, ignoring."
|
||||
for _ in {1..5}; do
|
||||
blink "1.5" && sleep 0.5
|
||||
done
|
||||
fi
|
||||
|
||||
else
|
||||
log_message "USB drive mounted but femtofox-config.txt not found, ignoring."
|
||||
for _ in {1..3}; do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue