forked from sensorgnome-org/sensorgnome-support
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboottime.sh
More file actions
executable file
·83 lines (72 loc) · 3 KB
/
boottime.sh
File metadata and controls
executable file
·83 lines (72 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash
#
# boot-time tasks for Sensor Gnome (for debian 7.0 armhf)
# These must be run before network interfaces are brought up!
# Capture the hostname entered by the user in raspi-imager
[[ -f /etc/sensorgnome/hostname-init ]] || cp /etc/hostname /etc/sensorgnome/hostname-init
# Generate the sensorgnome unique system ID into /etc/sensorgnome/id
# This ID is associated with the CPU chip, thus if the hardware is swapped out due to a failure
# the station will get a new ID...
./gen_id.sh
# Make sure serial number-hostname for local host is in /etc/hosts
sed -i /etc/hosts \
-e "/127.0.0.1[ \t]\+localhost/s/^.*$/127.0.0.1\tlocalhost `hostname`/" \
-e "s/raspberrypi/`hostname`/"
# Increment the persistent bootcount in /etc/bootcount
BOOT_COUNT_FILE="/etc/sensorgnome/bootcount"
if [[ -f $BOOT_COUNT_FILE ]]; then
COUNT=`cat $BOOT_COUNT_FILE`;
if [[ "$COUNT" == "" ]]; then
COUNT=0;
fi
echo $(( 1 + $COUNT )) > $BOOT_COUNT_FILE
else
echo 1 > $BOOT_COUNT_FILE
fi
echo "The boot count is $(cat $BOOT_COUNT_FILE)"
sync
# Create /data partition if we don't have one yet
./create_data_part.sh
# The "Datasaver" in sensorgnome expects to write data to /media/SD_card and
# /media/diskNportM, so ensure /media/SD_card is a symlink to /data
[[ -e /media/SD_card ]] || ln -s /data /media/SD_card
# mount and move specific files from /boot into /etc/sensorgnome, the reason for this is that
# boot is a fat32 filesystem where the user can edit some config files before first boot
echo "Moving data from /boot to /etc/sensorngome"
shopt -s nullglob
if [[ -n $(echo /boot/*tag*.sqlite) ]]; then
mv /boot/*tag*.sqlite /etc/sensorgnome/SG_tag_database.sqlite
fi
if [[ -f /boot/usb-port-map.txt ]]; then
mv /boot/usb-port-map.txt /etc/sensorgnome/
fi
if [[ -n $(echo /boot/*.pub) ]]; then
username=`getent passwd 1000 | cut -d: -f1`
mkdir -p "/home/${username}/.ssh"
cat /boot/*.pub >>"/home/${username}/.ssh/authorized_keys"
chown -R "${username}" "/home/${username}/.ssh"
chmod 644 /home/${username}/.ssh/*
rm /boot/*.pub
fi
# Detect any HAT with the ability to explicitly override for HATs that don't detect properly,
# for example when stacking two HATs, which is something the rpi cannot detect.
mkdir -p /dev/sensorgnome
if [[ -f /proc/device-tree/hat/product ]]; then
cp /proc/device-tree/hat/product /dev/sensorgnome/hat
fi
if [[ -f /etc/sensorgnome/force-hat ]]; then
cp /etc/sensorgnome/force-hat /dev/sensorgnome/hat
fi
# ensure we're running in UTC
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
# starting with 2023-106 we store an image creation timestamp in /etc/sensorgnome/image-stamp
# but when upgrading that's missing... make one up using /opt/sensorgnome
if ! [[ -f /etc/sensorgnome/image-stamp ]]; then
stat -c %Y /opt/sensorgnome > /etc/sensorgnome/image-stamp
fi
# ensure we're close enough to a current date that chrony will sync (10 years)
if [[ $(date +%Y) -lt 2020 ]]; then
echo "Setting date to 2020-01-01"
date -s 2020-01-01
fi