-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·134 lines (115 loc) · 4.33 KB
/
update.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
#!/bin/bash
# This script is the update script which will be run on the Pi after the update
# package is extracted. This script should compile all the items, and copy the
# files into their correct locations. Additionally, this script can communicate
# with the other Pi to copy files to it over SFTP.
echo "Running update script"
# "Update light" -- Set GPIO 4 to output and turn on
echo "4" | sudo tee /sys/class/gpio/export
echo "out" | sudo tee /sys/class/gpio/gpio4/direction
echo "1" | sudo tee /sys/class/gpio/gpio4/value
# Build all necessary files
echo "Building and copying library"
cd ./libs/
bash ./build-lib.sh >> /tmp/update-log 2>&1
# Copy these files first, as they're necessary for later builds
sudo cp ./libptp++.so /usr/lib/
sudo mkdir -p /usr/include/libptp++/
sudo cp ./*.hpp /usr/include/libptp++/
sudo mkdir -p /usr/include/libptp++/chdk/
sudo cp ./chdk/*.h /usr/include/libptp++/chdk/
echo "Building submarine executable"
cd ../sd-submarine/
bash ./build-submarine.sh >> /tmp/update-log 2>&1
echo "Building surface executable"
cd ../sd-surface/
bash ./build-surface.sh >> /tmp/update-log 2>&1
cd ../
echo "Stopping UI locally"
sudo /etc/init.d/sd-startup update
sleep 2
# Copy files to correct locations
echo "Copying files locally"
# Submarine file
sudo cp ./sd-submarine/sd-submarine /usr/bin/
# Surface file
sudo cp ./sd-surface/sd-surface /usr/bin/
# util files
sudo cp ./utils/90-senior-design.rules /etc/udev/rules.d/
sudo cp ./utils/sd-start /usr/sbin/
sudo cp ./utils/sd-stop /usr/sbin/
sudo cp ./utils/sd-stop-update /usr/sbin/
sudo cp ./utils/sd-update /usr/sbin/
sudo cp ./utils/sd-startup /etc/init.d/
# Image files
sudo mkdir -p /usr/share/sd-surface/
sudo cp ./images/*.bmp /usr/share/sd-surface/
# Update init.d files
echo "Reloading init.d rules"
sudo update-rc.d sd-startup defaults
# Restart udev to pickup new rules
echo "Reloading udev"
#sudo /etc/init.d/udev restart
sudo udevadm control --reload-rules
# Restart the UI
echo "Restarting UI"
sudo /etc/init.d/sd-startup start
MY_HOSTNAME=`hostname -s`
if [ "${MY_HOSTNAME}" = "pi-surface" ]; then
OTHER_HOSTNAME="pi-submarine"
else
OTHER_HOSTNAME="pi-surface"
fi
echo "Detected that I am: ${MY_HOSTNAME}, other Pi is: ${OTHER_HOSTNAME}"
echo "SSHing to make directories"
ssh pi@$OTHER_HOSTNAME << EOF1
rm -Rf /tmp/update/
mkdir -p /tmp/update/usr/lib/
mkdir -p /tmp/update/usr/include/libptp++/chdk/
mkdir -p /tmp/update/usr/bin/
mkdir -p /tmp/update/etc/udev/rules.d/
mkdir -p /tmp/update/usr/sbin/
mkdir -p /tmp/update/etc/init.d/
mkdir -p /tmp/update/usr/share/sd-surface/
EOF1
# TODO: Set up public key authentication so that we can SFTP/SSH
# without providing credentials
# TODO: I'll need to SFTP into root to have permissions to copy into the right
# locations, won't I?
# Alternatively, let's copy these to /tmp, then run a script to move them
# to the right place :/
echo "Copying files"
sftp pi@$OTHER_HOSTNAME << EOF2
put /usr/lib/libptp++.so /tmp/update/usr/lib/
put /usr/include/libptp++/* /tmp/update/usr/include/libptp++/
put /usr/include/libptp++/chdk/* /tmp/update/usr/include/libptp++/chdk/
put /usr/bin/sd-submarine /tmp/update/usr/bin/
put /usr/bin/sd-surface /tmp/update/usr/bin/
put /etc/udev/rules.d/90-senior-design.rules /tmp/update/etc/udev/rules.d/
put /usr/sbin/sd-start /tmp/update/usr/sbin/
put /usr/sbin/sd-stop /tmp/update/usr/sbin/
put /usr/sbin/sd-stop-update /tmp/update/usr/sbin/
put /usr/sbin/sd-update /tmp/update/usr/sbin/
put /etc/init.d/sd-startup /tmp/update/etc/init.d/
put /usr/share/sd-surface/* /tmp/update/usr/share/sd-surface/
EOF2
# User pi will need sudo access with NOPASSWD, which is a security risk.
# We're OK with this because neither pi is connected to the Internet, and anyone
# with access has physical access anyway.
# This copy line might not be ideal, but it's fine as long as we set things up
# correctly above. We can always reimage the SD card if something goes wrong.
echo "SSH to move files and restart UI"
ssh pi@$OTHER_HOSTNAME << EOF3
sudo /etc/init.d/sd-startup update
sleep 2
sudo mkdir -p /usr/include/libptp++/chdk/
sudo mkdir -p /usr/share/sd-surface/
sudo cp -r /tmp/update/* /
sudo update-rc.d sd-startup defaults
sudo udevadm control --reload-rules
sudo /etc/init.d/sd-startup start &
EOF3
# "Update light" -- turn off and clean up
echo "0" | sudo tee /sys/class/gpio/gpio4/value
echo "4" | sudo tee /sys/class/gpio/unexport
#exit 0