Update readme
[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 mount /dev/sda1 > /dev/null 2>&1 || { printf "Mount failure\n"; exit 1; }
11
12 printf "\t\tMount OK\n"
13
14 if [[ -e "/mnt/usb-update/config.ini" ]]; then
15 printf "Found config.ini... "
16 (cp /mnt/usb-update/config.ini /home/pi/hdmi-switcher > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
17 fi
18
19 if [[ -e "/mnt/usb-update/video.mp4" ]]; then
20 printf "Found video.mp4... "
21 (cp /mnt/usb-update/video.mp4 /home/pi/hdmi-switcher > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
22 fi
23
24 if [[ -e "/mnt/usb-update/update.zip" ]] && [[ -e "/mnt/usb-update/update.sig" ]]; then
25 current_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
26 printf "Updating software... "
27 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
28 if [[ $? = 0 ]]; then
29 (unzip -o /mnt/usb-update/update.zip -d /home/pi > /dev/null 2>&1 && printf "\tOK\n") || printf "\tExtract failure\n"
30 chmod +x /home/pi/hdmi-switcher/start.sh
31 chmod +x /home/pi/hdmi-switcher/update.sh
32 chmod +x /home/pi/hdmi-switcher/hdmi-switcher
33 new_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
34 if [[ "$current_version" != "$new_version" ]]; then
35 printf "Restart required...\n"
36 #reboot
37 fi
38 else
39 printf "\tSignature failure\n"
40 fi
41 fi
42
43 umount /dev/sda1 > /dev/null 2>&1