Reboot if required after update
[hdmi-switcher.git] / update.sh
index 836b1cd..ea8eeea 100755 (executable)
--- a/update.sh
+++ b/update.sh
@@ -12,22 +12,28 @@ printf "\t\tMount OK\n"
 
 if [[ -e "/mnt/usb-update/config.ini" ]]; then
   printf "Found config.ini... "
-  (cp /mnt/usb-update/config.ini ./ > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
+  (cp /mnt/usb-update/config.ini /home/pi > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
 fi
 
 if [[ -e "/mnt/usb-update/video.mp4" ]]; then
   printf "Found video.mp4... "
-  (cp /mnt/usb-update/video.mp4 ./ > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
+  (cp /mnt/usb-update/video.mp4 /home/pi > /dev/null 2>&1 && printf "\tCopy OK\n") || printf "\tCopy failure\n"
 fi
 
 if [[ -e "/mnt/usb-update/update.zip" ]] && [[ -e "/mnt/usb-update/update.sig" ]]; then
+  current_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
   printf "Updating software... "
   openssl dgst -sha256 -verify public.pem -signature /mnt/usb-update/update.sig /mnt/usb-update/update.zip > /dev/null 2>&1
   if [[ $? = 0 ]]; then
     (unzip -o /mnt/usb-update/update.zip -d /home/pi > /dev/null 2>&1 && printf "\tOK\n") || printf "\tExtract failure\n"
-    chmod +x start.sh
-    chmod +x update.sh
-    chmod +x hdmi-switcher
+    chmod +x /home/pi/hdmi-switcher/start.sh
+    chmod +x /home/pi/hdmi-switcher/update.sh
+    chmod +x /home/pi/hdmi-switcher/hdmi-switcher
+    new_version=$(/home/pi/hdmi-switcher/hdmi-switcher version)
+    if [[ "$current_version" != "$new_version" ]]; then
+      printf "Restart required...\n"
+      #reboot
+    fi
   else
     printf "\tSignature failure\n"
   fi