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