-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
181 lines (134 loc) · 5.68 KB
/
install.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# Ask user if we have a waveshare modem
read -p "Does this camera have a waveshare SIM7600X modem? (y/n)" waveshare
read -p "Would you like to update the operating system software using apt-get update/upgrade? (y/n)" updateApt
if [ $updateApt == "y" ]; then
echo Updating....
sudo apt-get update
echo Upgrading...
sudo apt-get upgrade -y
fi
echo Installing packages...
sudo apt-get install -y git pijuice-base python3-pip
sudo apt-get install -y python3-picamera2 --no-install-recommends
sudo apt-get install -y vim\
byobu\
python3-pil\
python3-RPi.GPIO\
python3-serial\
# Enable wakeup logging.
python3 /usr/bin/pijuice_log.py --enable WAKEUP_EVT
# If not bookworm - install waveshare-epaper library with pip3
# sudo pip3 install waveshare-epaper
# sudo apt-get install python3-waveshare-epaper -y
if ! grep -q "bookworm" /etc/os-release; then
pip3 install waveshare-epaper
fi
byobu-enable
# sudo apt-get install locales
# sudo locale-gen en_NZ.UTF-8
# sudo update-locale LANG=en
sudo dpkg-reconfigure locales
echo Setting timezone...
sudo timedatectl set-timezone Pacific/Auckland
if [ $waveshare == "y" ]; then
echo "Installing waveshare modem"
# Waveshare stuff
# Enable Serial Communication
sudo raspi-config nonint do_serial 2 # Disable serial login shell and enable serial port hardware
# Check if folder SIM7600X-4G-HAT-Demo exists:
if [ ! -d "/home/pi/SIM7600X-4G-HAT-Demo" ]; then
#https://core-electronics.com.au/guides/raspberry-pi/raspberry-pi-4g-gps-hat/
wget https://www.waveshare.com/w/upload/2/29/SIM7600X-4G-HAT-Demo.7z
sudo apt-get install p7zip-full
7z x SIM7600X-4G-HAT-Demo.7z -r -o/home/pi
sudo chmod 777 -R /home/pi/SIM7600X-4G-HAT-Demo
cd /home/pi/SIM7600X-4G-HAT-Demo/Raspberry/c/bcm2835
chmod +x configure && ./configure && sudo make && sudo make install
fi
# sed -e '$i \sh /home/pi/SIM7600X-4G-HAT-Demo/Raspberry/c/sim7600_4G_hat_init\n' /etc/rc.local
grep -qxF 'sh /home/pi/SIM7600X-4G-HAT-Demo/Raspberry/c/sim7600_4G_hat_init' /etc/rc.local || sudo sed -i -e '$i \sh /home/pi/SIM7600X-4G-HAT-Demo/Raspberry/c/sim7600_4G_hat_init\n' /etc/rc.local
###################
fi
cd /home/pi
# Check if dev folder exists
if [ ! -d "/home/pi/dev/timelapse" ]; then
echo Cloning repo...
mkdir -p dev
cd dev
git clone https://github.com/venari/timelapse.git
cd timelapse
git config pull.rebase false
# git checkout development
git checkout main
else
echo Updating repo...
cd dev/timelapse
# git checkout development
git fetch
git stash
git checkout main
git pull
git stash pop
fi
# If using thumbdrive, not waveshare modem, update 'modem.type' in dev/timelapse/scripts/config.json to 'thumb'
if [ $waveshare == "n" ]; then
sed -i 's/"modem.type": "SIM7600X"/"modem.type": "thumb"/g' /home/pi/dev/timelapse/scripts/config.json
else
sed -i 's/"modem.type": "thumb"/"modem.type": "SIM7600X"/g' /home/pi/dev/timelapse/scripts/config.json
fi
echo Checking RTC module is enabled in config.txt
if [ -e /boot/firmware/config.txt ] ; then
FIRMWARE=/firmware
else
FIRMWARE=
fi
CONFIG=/boot${FIRMWARE}/config.txt
grep -qxF 'dtoverlay=i2c-rtc,ds1307=1' $CONFIG || echo 'dtoverlay=i2c-rtc,ds1307=1' | sudo tee -a $CONFIG
grep -qxF 'dtparam=i2c_arm=on' $CONFIG || echo 'dtparam=i2c_arm=on' | sudo tee -a $CONFIG
echo Checking static domain_name_servers entry etc/dhcpcd.conf
grep -qxF 'static domain_name_servers=8.8.4.4 8.8.8.8' /etc/dhcpcd.conf || echo 'static domain_name_servers=8.8.4.4 8.8.8.8' | sudo tee -a /etc/dhcpcd.conf
# Clear out any old crontab entries
crontab -r
echo Installing systemd services...
sudo cp /home/pi/dev/timelapse/systemd/system/*.* /etc/systemd/system/
sudo chmod u+x /etc/systemd/system/enviro*.*
sudo systemctl enable envirocam-logging.service
sudo systemctl enable envirocam-telemetry.service
sudo systemctl enable envirocam-photos.timer
sudo systemctl enable envirocam-upload.timer
sudo systemctl enable envirocam-detect-hang.timer
# If not bookworm - don't have epaper library yet
if ! grep -q "bookworm" /etc/os-release; then
sudo cp /home/pi/dev/timelapse/systemd/system/envirocam-status.timer /etc/systemd/system/
sudo systemctl enable envirocam-status.timer
fi
# If not waveshare, we can't access SMS messages
if [ $waveshare == "y" ]; then
sudo cp /home/pi/dev/timelapse/systemd/system/envirocam-sms.timer /etc/systemd/system/
sudo systemctl enable envirocam-sms.timer
fi
echo Overwriting pijuice config...
sudo mv /var/lib/pijuice/pijuice_config.JSON /var/lib/pijuice/pijuice_config.JSON.bak
sudo curl -fsSL -o /var/lib/pijuice/pijuice_config.JSON https://raw.githubusercontent.com/venari/timelapse/main/pijuice_config.JSON
sudo chown pijuice:pijuice /var/lib/pijuice/pijuice_config.JSON
echo Installing Tailscale...
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
# Query user for hostname, provide a default value
read -p "Current hostname is $(hostname) - would you like to change it?" yn
case $yn in
[Yy]* ) echo "Changing hostname";
read -p "Enter new hostname if desired: " -i sediment-pi- -e hostname
echo Setting hostname to $hostname
sudo hostnamectl set-hostname $hostname;;
[Nn]* ) echo "Skipping hostname change";;
* ) echo "Please answer yes or no.";;
esac
echo We need to reboot to clear out cron jobs and kick off systemd jobs
echo "Press any key to reboot"
echo ===========================================
echo Please check battery profile in pijuice_cli
echo ===========================================
read -n 1 -s
sudo reboot