Update pulse width to 100ms
[hdmi-switcher.git] / update.sh
1 #!/bin/bash
2
3 if [[ ! -e "/dev/sda1" ]]; then
4 exit 1
5 fi
6
7 printf "Found USB... "
8
9 umount /dev/sda1 > /dev/null 2>&1
10 # The {} does NOT spawn a new subshell, so the exit kills this script.
11 mount /dev/sda1 > /dev/null 2>&1 || { printf "Mount failure\n"; exit 1; }
12
13 printf "\t\tMount OK\n"
14
15 if [[ -e "/mnt/usb-update/config.ini" ]]; then
16 printf "Found config.ini... "
17 (cp /mnt/usb-update/config.ini /home/pi/hdmi-switcher > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
18 fi
19
20 if [[ -e "/mnt/usb-update/video.mp4" ]]; then
21 printf "Found video.mp4... "
22 (cp /mnt/usb-update/video.mp4 /home/pi/hdmi-switcher > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
23 fi
24
25 if [[ -e "/mnt/usb-update/update.zip" ]] && [[ -e "/mnt/usb-update/update.sig" ]]; then
26 current_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
27 printf "Updating software... "
28 openssl dgst -sha256 -verify /home/pi/hdmi-switcher/public.pem -signature /mnt/usb-update/update.sig /mnt/usb-update/update.zip > /dev/null 2>&1
29 if [[ $? = 0 ]]; then
30 (unzip -o /mnt/usb-update/update.zip -d /home/pi > /dev/null 2>&1 && printf "\tOK\n") || printf "\tExtract failure\n"
31 chmod +x /home/pi/hdmi-switcher/start.sh
32 chmod +x /home/pi/hdmi-switcher/update.sh
33 chmod +x /home/pi/hdmi-switcher/hdmi-switcher
34 new_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
35 if [[ "$current_version" != "$new_version" ]]; then
36 printf "Restart required...\n"
37 reboot
38 fi
39 else
40 printf "\tSignature failure\n"
41 fi
42 fi
43
44 umount /dev/sda1 > /dev/null 2>&1