You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
3.5 KiB

  1. #!/bin/bash
  2. set -e
  3. ### Run as a normal user
  4. if [ $EUID -eq 0 ]; then
  5. echo "This script shouldn't be run as root."
  6. exit 1
  7. fi
  8. ## import common lib
  9. . "$HOME/.noaa.conf"
  10. . "$NOAA_HOME/common.sh"
  11. WEB_DIR=/var/www/wx
  12. STEPS=9
  13. echo "
  14. This script is used to sync webpanel updates and provide an easy
  15. way for users to keep their webpanel up to date with new features
  16. that are released - note that the first time you use this to migrate
  17. to the new webpanel contents, your Config.php file (containing locale
  18. settings) will be backed up to the $NOAA_HOME/bak/ directory and a
  19. replacement config.php put in its place. You can reference values you
  20. might have configured in the backup file to update $WEB_DIR/config.php
  21. to your liking.
  22. If you have made significant changes to any of the contents in the webpanel
  23. deployment, they likely WILL be destroyed by running this script as all
  24. files in $WEB_DIR are replaced with the exception of the following, which are
  25. moved to the public/ directory as part of this upgrade:
  26. * audio/
  27. * images/
  28. * meteor/
  29. "
  30. read -rp "Are you sure you wish to proceed? (y/N) "
  31. if [[ $REPLY =~ ^[Nn]$ ]]; then
  32. log "Aborting webpanel sync" "ERROR"
  33. exit 0
  34. elif [[ $REPLY =~ ^[Yy]$ ]]; then
  35. log "Webpanel sync proceeding!" "INFO"
  36. else
  37. log "Aborting webpanel sync - unknown option '$REPLY'" "ERROR"
  38. exit 1
  39. fi
  40. log "1/$STEPS: Checking for composer..." "INFO"
  41. which composer
  42. if [ $? -ne 0 ]; then
  43. sudo apt-get -y install composer
  44. fi
  45. log "1/$STEPS: Composer install/check done" "INFO"
  46. log "2/$STEPS: Backing up PHP config file..." "INFO"
  47. if [ -f "$WEB_DIR/config.php" ]; then
  48. log " Found newer-style config file - backing up." "INFO"
  49. cp $WEB_DIR/config.php $NOAA_HOME/bak/config.php.backup
  50. elif [ -f "$WEB_DIR/Config.php" ]; then
  51. log " Found older-style config file - backing up." "INFO"
  52. cp $WEB_DIR/Config.php $NOAA_HOME/bak/Config.php.backup
  53. else
  54. log " Did not find any existing config file - proceeding." "INFO"
  55. fi
  56. log "2/$STEPS: Done backing up PHP config file" "INFO"
  57. log "3/$STEPS: Removing old PHP files (excluding images/audio)..." "INFO"
  58. find $WEB_DIR/ -mindepth 1 -type d -name "images" -prune -o -type d -name "audio" -prune -o -type d -name "meteor" -prune -o -print | xargs rm -rf
  59. log "3/$STEPS: Old PHP files removed" "INFO"
  60. log "4/$STEPS: Copying new PHP files..." "INFO"
  61. sudo cp -rp $NOAA_HOME/templates/webpanel/* $WEB_DIR/
  62. log "4/$STEPS: Done copying new PHP files" "INFO"
  63. log "5/$STEPS: Moving audio, images, and meteor directories (if required/detected)..." "INFO"
  64. echo "FILLMEIN"
  65. log "5/$STEPS: Done moving audio, images, and meteor directories" "INFO"
  66. log "6/$STEPS: Running composer to install dependencies..." "INFO"
  67. composer install -d /var/www/wx/
  68. log "6/$STEPS: Done running composer install" "INFO"
  69. log "7/$STEPS: Aligning permissions..." "INFO"
  70. chown -R pi:pi /var/www/wx/
  71. echo "FILLMEIN"
  72. log "8/$STEPS: Done aligning permissions" "INFO"
  73. log "8/$STEPS: Updating nginx configuration (if required)..." "INFO"
  74. echo "FILLMEIN - MOVE TO public/ AS ROOT DIR WITH REWRITES FOR index.php"
  75. log "8/$STEPS: Done updating nginx configuration" "INFO"
  76. log "9/$STEPS: Restarting nginx (if required)..." "INFO"
  77. echo "FILLMEIN: RESTART NGINX ONLY IF REQUIRED"
  78. log "9/$STEPS: Done restarting nginx" "INFO"
  79. log "Your old PHP config file has been copied to the bak/ directory" "INFO"
  80. log "Please update any settings you wish to preserve in $WEB_DIR/config.php" "INFO"
  81. log " including 'lang' and 'timezone' settings for display" "INFO"