Skip to content

Instantly share code, notes, and snippets.

@xyb994
Last active November 9, 2017 00:00
Show Gist options
  • Save xyb994/9adc73c1c7b810a86cd9cd24da3ed508 to your computer and use it in GitHub Desktop.
Save xyb994/9adc73c1c7b810a86cd9cd24da3ed508 to your computer and use it in GitHub Desktop.
#!/bin/bash
# real time clock
# RasClock https://afterthoughtsoftware.com/products/rasclock
# https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time
cd /boot/overlays
if [ -e i2c-rtc-overlay.dtb ] || [ -e i2c-rtc.dtbo ]; then
echo >> /boot/config.txt
echo 'dtoverlay=i2c-rtc,pcf2127' >> /boot/config.txt
elif [ -e pcf2127-rtc-overlay.dtb ]; then
echo >> /boot/config.txt
echo 'dtoverlay=pcf2127-rtc' >> /boot/config.txt
fi
cp /lib/udev/hwclock-set /lib/udev/hwclock-set.old
sed -e '/run\/systemd\/system/,+2 s/^#*/#/' -i /lib/udev/hwclock-set
sed -e '/--systz/ s/^#*/#/' -i /lib/udev/hwclock-set
# disable fake-hwclock
# remove package
apt-get remove fake-hwclock
# remove cronjob
rm /etc/cron.hourly/fake-hwclock
# disable and remove init script
update-rc.d -f fake-hwclock remove
rm /etc/init.d/fake-hwclock
# second autorunonce
mv /boot/autoranonce* /boot/autoranonce.sh.first
sync
cat <<EOF > /boot/autorunonce.sh
#!/bin/sh
sleep 10
while ! curl -X GET https://google.com ; do
sleep 1
done
sudo service ntp restart
sudo date > /boot/time
sudo hwclock -w
sudo hwclock -r >> /boot/time
sudo hwclock -s
sudo date >> /boot/time
echo "server 127.127.1.0" >> /etc/ntp.conf
echo "fudge 127.127.1.0 stratum 10" >> /etc/ntp.conf
echo "restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap" >> /etc/ntp.conf
sync;sync;sync;reboot
EOF
sync
sync
sync
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment