-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpi.sh
More file actions
175 lines (131 loc) · 4.68 KB
/
Copy pathpi.sh
File metadata and controls
175 lines (131 loc) · 4.68 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
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
#!/usr/bin/env bash
# -*- mode: shell-script -*-
set -u
set -e
echo -n "checking machine model... "
dmesg | grep -i 'Machine model' | grep -o 'Raspberry Pi' || (echo 'machine model is not supported' ; exit 1)
for user in aleksandr-vin jsvapiav
do
echo "authorizing $user key for ssh access..."
chmod u+w ~/.ssh/authorized_keys
curl https://github.com/$user.keys | tee -a ~/.ssh/authorized_keys
done
read -s -p "===> now will install packages, hit enter to continue "
echo "installing packages..."
sudo apt-get update -y
sudo apt install -y git python3-pip libatlas-base-dev libtiff5-dev libopenjp2-7-dev virtualenv
echo "installing python virtual environment..."
virtualenv -p python3 ~/venv
cat <<EOF
====================================================
Now we need to perform some interactive setup
====================================================
EOF
while true
do
echo "--------- location ------------"
read -p " Location tag: " location_tag
read -p " Location camera id: " location_camera_id
read -p " Camera rotation (deg): " camera_rotation_deg
echo "------------- aws -------------"
read -p " Name AWS profile: " aws_profile
read -p " Provide aws_access_key_id: " aws_access_key_id
read -p " Provide aws_secret_access_key: " aws_secret_access_key
cat <<EOF
You entered:
Location tag: $location_tag
Location camera id: $location_camera_id
Camera rotation (deg): $camera_rotation_deg
Name AWS profile: $aws_profile
Provide aws_access_key_id: $aws_access_key_id
Provide aws_secret_access_key: $aws_secret_access_key
EOF
read -p "===> correct [y/n]? " yn
if [[ "$yn" == 'y' || "$yn" == 'Y' ]]
then
break
else
cat <<EOF
Enter again:
EOF
fi
done
echo "appending to ~/.aws/credentials..."
mkdir -p ~/.aws
cat >> ~/.aws/credentials <<EOF
[$aws_profile]
aws_access_key_id = $aws_access_key_id
aws_secret_access_key = $aws_secret_access_key
EOF
echo "backing up key pair, if present..."
mv -v -f ~/.ssh/picam_videoparking_deloyment_rsa{,-}
mv -v -f ~/.ssh/picam_videoparking_deloyment_rsa.pub{,-}
echo "generating key pair for automatic updates..."
ssh-keygen -f ~/.ssh/picam_videoparking_deloyment_rsa -N ''
echo "configuring ~/.ssh/config..."
mkdir -p ~/.ssh
cat >> ~/.ssh/config <<EOF
Host github.com
User git
Hostname github.com
IdentityFile ~/.ssh/picam_videoparking_deloyment_rsa
EOF
echo "configuring ~/.profile..."
cat >> ~/.profile <<EOF
export S3_API_VER=v1
export S3_CAM_TAG=$location_tag
export S3_CAM_ID=$location_camera_id
export AWS_PROFILE=$aws_profile
export CAM_ROTATION=$camera_rotation_deg
. $HOME/venv/bin/activate
EOF
ssh_key=$(< ~/.ssh/picam_videoparking_deloyment_rsa.pub)
cat <<EOF
=======================================================
Add new deployment key at: https://github.com/videoparking/picam-videoparking/settings/keys/new
Name it $location_tag/$location_camera_id
Copy this key there:
$ssh_key
AND DO NOT PROVIDE WRITE ACCESS!!!
=======================================================
EOF
read -s -p "===> hit enter when ready to continue with cloning repository "
echo "cloning repository..."
(cd && git clone git@github.com:videoparking/picam-videoparking.git)
echo "installing picam-videoparking package..."
(cd ~/picam-videoparking && . ~/venv/bin/activate && pip3 install -e .)
read -s -p "===> hit enter when ready to install crontab..."
echo "installing @reboot to crontab..."
cat > $HOME/.picam-videoparking-crontab.txt <<EOF
# Getting photo every minute
* * * * * /bin/sh -c '. $HOME/.profile && $HOME/venv/bin/picam-videoparking'
# Updating tooling every 30th minute of the hour
30 * * * * /bin/sh -c '. $HOME/.profile && cd $HOME/picam-videoparking && git pull && pip3 install -e .
EOF
cat > /tmp/bootstrap-crontab <<EOF
# This is for installing proper picam-videoparking crontab after reboot
@reboot /usr/bin/crontab $HOME/.picam-videoparking-crontab.txt
EOF
crontab /tmp/bootstrap-crontab
echo "setting swap file size..."
sudo sh -c 'printf "\nCONF_SWAPSIZE=512\n" >> /etc/dphys-swapfile'
echo "disabling camera LED..."
sudo sh -c 'printf "\ndisable_camera_led=1\n" >> /boot/config.txt'
echo "disabling wlan power save mode..."
iwconfig 2>/dev/null| grep wlan | while read wlan _
do
sudo sed -i "s|exit 0|/sbin/iw $wlan set power_save off ; exit 0|" /etc/rc.local
done
cat <<EOF
==============================================
Now raspi-config will be run, you'll need to:
1. Enable camera
2. Set Advanced Options > Memory Split to 256M
(You can choose to reboot afterwards)
==============================================
EOF
read -s -p "===> hit enter "
sudo raspi-config
# In case user forgot
read -s -p "hit enter to reboot "
sudo reboot