mirror of
https://github.com/femtofox/femtofox.git
synced 2026-10-26 10:51:57 -04:00
67 lines
2 KiB
Bash
67 lines
2 KiB
Bash
#!/bin/bash
|
|
|
|
#not really needed after first boot
|
|
#/usr/bin/filesystem_resize.sh
|
|
|
|
#supposedly needed for usb storage, but works anyway
|
|
#/etc/init.d/S50usbdevice start
|
|
|
|
luckfox-config load
|
|
|
|
#try enable RTC
|
|
echo 'ds1307 0x68' | sudo tee /sys/class/i2c-adapter/i2c-3/new_device > /dev/null 2>&1
|
|
|
|
# activating USER LED
|
|
echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction &
|
|
|
|
#if RTC recognized
|
|
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."
|
|
else
|
|
hwclock -s > /dev/null 2>&1 &
|
|
echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")."
|
|
fi
|
|
else
|
|
echo "RTC not found."
|
|
sudo date -s "1 JAN 2024 00:00:00" > /dev/null 2>&1 &
|
|
fi
|
|
|
|
#try get network time
|
|
date_str=$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')
|
|
if [ -n "$date_str" ]; then
|
|
sudo date -s "$date_str" > /dev/null 2>&1
|
|
sudo echo "Got network time: $(date +"%Y-%m-%d %H:%M:%S %Z")."
|
|
if [ "$rtc" = "true" ]; then
|
|
echo "Setting RTC to network time."
|
|
sudo hwclock -w &
|
|
fi
|
|
else
|
|
echo "Failed to fetch network time, using $(date +"%Y-%m-%d %H:%M:%S %Z") instead."
|
|
fi
|
|
|
|
# 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
|
|
|
|
#does not appear to lower power consumption, but needs more testing
|
|
#(sleep 5 && cpufreq-set -u 408000 && echo "Boot complete, setting CPU frequency to 408mhz.") &
|
|
|
|
# run USB automount and config tool
|
|
/usr/local/bin/usbconfig.sh
|
|
|
|
echo "Disabling ACT LED..."
|
|
echo "none" > /sys/class/leds/work/trigger &
|
|
|
|
#boot complete, blink USER LED 5 times in background
|
|
(
|
|
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
|
|
) &
|
|
|
|
exit 0
|