hydrophonitor/scripts/setup-rtc-2.sh

35 lines
750 B
Bash
Raw Normal View History

2022-10-22 11:41:10 +00:00
#!/bin/bash
set -x
echo "Setting up the real time clock module, part 2"
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
2022-10-22 11:41:10 +00:00
# Load RTC clock at boot
sudo sed -i "s/^exit 0$//" /etc/rc.local
sudo cat << EOF | sudo tee -a /etc/rc.local
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
2022-10-22 11:41:10 +00:00
sudo hwclock -s
exit 0
EOF
# Set system time to Internet time
echo "Restarting systmd-timesyncd to update system time"
sudo systemctl restart systemd-timesyncd
echo "System time now:"
date
sleep 5
2022-10-22 11:41:10 +00:00
# Write system time to the RTC module
echo "Hardware clock time now:"
2022-10-23 14:04:10 +00:00
sudo hwclock -r --verbose
2022-10-22 11:41:10 +00:00
echo "Writing system time to hardware clock"
2022-10-23 14:04:10 +00:00
sudo hwclock -w --verbose
2022-10-22 11:41:10 +00:00
echo "Hardware clock time now:"
2022-10-23 14:04:10 +00:00
sudo hwclock -r --verbose