-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws-setup
116 lines (101 loc) · 2.99 KB
/
ws-setup
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
#!/bin/bash
# WildlifeSystems
#
# This script is part of the WildlifeSystems project. For further information
# please refer to https://docs.wildlife.systems, or for more information on
# the project itself, please refer to https://wildlife.systems.
ws-heartbeat setup
#Setup s3cmd if .s3cfg is present
if [[ -f /boot/.s3cfg ]] || [[ -f /home/pi/.s3cfg ]]; then
sudo apt-get install -y s3cmd
#This is required by s3cmd but not a dependency
sudo apt-get install -y python3-distutils
fi
#Set defaults
DEVNAME="raspberrypi"
SNDDEV="manual"
IMGDEV="manual"
PASSWD="manual"
FIREWALL="manual"
#Device serial
wsSERIAL=`grep Serial /proc/cpuinfo | cut -d ' ' -f 2`
#Check if device is registered or should run as standalone
URL="https://devices.wildlife.systems/info/?id=$wsSERIAL"
response=$(curl -s -w "\n%{http_code}" $URL)
http_code=$(tail -n1 <<< "$response") # get the last line
content=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
if [[ $http_code == "200" ]]; then
echo "Device found on https://devices.wildlife.systems - proceeding with automated setup"
DEVNAME=`echo $content | jq -r '."device-name"'`
SNDDEV=`echo $content | jq -r '."sound-device"'`
IMGDEV=`echo $content | jq -r '."camera-type"'`
FIREWALL=`echo $content | jq -r '."firewall"'`
else
echo "No matching device serial number found on https://devices.wildlife.systems"
echo "If you want to add it before proceeding the serial number is $wsSERIAL."
fi
#Security: Default password
PWSALT=`sudo grep pi /etc/shadow | awk -F\$ '{print $3}'`
PWPI=`sudo grep pi /etc/shadow | awk -F: '{print $2}'`
PWDFT=`mkpasswd -m sha-512 raspberry $PWSALT`
if [[ "$PASSWD" == "manual" ]]; then
if [[ "$PWPI" == "$PWDFT" ]]; then
echo "Default password (raspberry) is in use for user pi. This must be changed."
if [[ "$1" != "unattended" ]]; then
passwd
fi
fi
fi
#Security: Firewall
if [[ "$FIREWALL" == "manual" ]]; then
echo $""
echo "Allow SSH through the firewall? (y/n)"
read ALLOWSSH
if [[ "$ALLOWSSH" == "y" ]]; then
sudo ufw allow ssh
fi
echo y | sudo ufw enable
else
if [[ "$FIREWALL" == "allow-ssh-in" ]]; then
sudo ufw allow ssh
echo y | sudo ufw enable
fi
fi
#Setup hostname
if [[ "$DEVNAME" == "raspberrypi" ]]; then
DEVNAME="raspberrypi"
fi
sudo hostnamectl set-hostname $DEVNAME
#Setup sound device
if [[ "$SNDDEV" == "manual" ]]; then
sdc-inst list
echo $""
echo "Select sound device to install:"
read SNDDEV
fi
sdc-inst $SNDDEV
#Setup imaging device
if [[ "$IMGDEV" == "manual" ]]; then
idc-inst list
echo $""
echo "Select camera to install:"
read IMGDEV
fi
idc-inst $IMGDEV
#Install runtime script
grep 'ws-run' /etc/rc.local > /dev/null
if [[ $? == 1 ]]; then
sudo sed -i -e '$i \\nrunuser -l pi -c /usr/bin/ws-run > out.txt 2>&1 &\n' /etc/rc.local
fi
if [[ "$1" == "unattended" ]]; then
exit 0;
fi
#Save settings to file
#Reboot
if [[ "$1" == "unattended" ]]; then
sudo reboot
fi
echo $""
echo "Press enter to reboot"
read REBOOT
sudo reboot