apply_update_popufare.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2019 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. update_file="$1"
  21. update_checksum="$2"
  22. file_size="$3"
  23. server_path="$4"
  24. file_version="$5"
  25. . /home/bus/bin/common_values.sh
  26. # Confirm we have a checksum that differs from our existing checksum
  27. #
  28. if [[ -f /home/bus/config/$update_file.checksum ]] ; then
  29. existing_checksum=`cat /home/bus/config/$update_file.checksum`
  30. if [[ "$update_checksum" == "$existing_checksum" ]] ; then
  31. echo "We already HAVE an update $update_file with checksum $update_checksum, aborting install"
  32. exit 1
  33. fi
  34. fi
  35. local_checksum=`md5sum $update_file | cut -d' ' -f1`
  36. # We are doing a 'legacy' install, so unpack the package locally and only
  37. # check for appropriate files in the 'config' directory.
  38. #
  39. if [[ "$update_checksum" == "$local_checksum" ]] ; then
  40. tar -zxf $update_file install.sh
  41. if [ -n "$PACKAGE_OWNER_STRING" ]; then
  42. chown $PACKAGE_OWNER_STRING install.sh
  43. fi
  44. chmod $PACKAGE_BIN_PERMISSIONS install.sh
  45. if (./install.sh); then
  46. echo "$local_checksum" > /home/bus/config/$update_file.checksum
  47. echo "$file_version" > /home/bus/config/$update_file.version
  48. if [ "$FIX_PACKAGE_PERMS" -ne "0" ]; then
  49. if [ -f $EXTRACT_PATH_FILE ]; then
  50. pkg_path="`cat $EXTRACT_PATH_FILE`"
  51. echo "Fixing permissions from package specified path $pkg_path";
  52. else
  53. pkg_path="$DEFAULT_EXTRACT_PATH"
  54. echo "Fixing permissions from default path $pkg_path";
  55. fi
  56. /home/bus/bin/fix_pkg_perm.sh $update_file $pkg_path
  57. fi
  58. echo "Update $update_file successfully installed"
  59. rm -f $update_file
  60. rm -f $EXTRACT_PATH_FILE
  61. if [ -f /tmp/reboot_flag ]; then
  62. killall diu_minder
  63. echo "Tearing down network connection"
  64. if [ -f $SSH_TUNNEL_PIDFILE ]; then kill `cat $SSH_TUNNEL_PIDFILE`; sleep 30; fi
  65. /usr/bin/poff gprs
  66. shutdown -r now;
  67. #sleep 1000;
  68. sleep 60;
  69. fi
  70. exit 0
  71. else
  72. echo "Update $update_file failed"
  73. rm -f $update_file
  74. exit 1
  75. fi
  76. else
  77. echo "Update $update_file appears to be BOGUS: Server MD5=$update_checksum Local MD5=$local_checksum"
  78. rm -f $update_file
  79. exit 1
  80. fi
  81. exit 1