apply_update_popufare.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  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 /hom/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. fi
  69. exit 0
  70. else
  71. echo "Update $update_file failed"
  72. rm -f $update_file
  73. exit 1
  74. fi
  75. else
  76. echo "Update $update_file appears to be BOGUS: Server MD5=$update_checksum Local MD5=$local_checksum"
  77. rm -f $update_file
  78. exit 1
  79. fi
  80. exit 1