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.
 
 
 
 
 
 

127 lines
4.6 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. new_path=/var/www/wx/public/
  65. old_audio_path=/var/www/wx/audio
  66. old_images_path=/var/www/wx/images
  67. old_meteor_path=/var/www/meteor
  68. if [ -d $old_audio_path ]; then
  69. if [ -d $new_path/audio ]; then
  70. log "Found new audio directory already exists - not moving old audio directory to avoid conflict (please handle yourself)" "ERROR"
  71. else
  72. log "Found old audio path, moving the directory to $new_path/audio" "INFO"
  73. mv $old_audio_path $new_path/audio
  74. fi
  75. fi
  76. if [ -d $old_images_path ]; then
  77. if [ -d $new_path/images ]; then
  78. log "Found new images directory already exists - not moving old images directory to avoid conflict (please handle yourself)" "ERROR"
  79. else
  80. log "Found old images path, moving the directory to $new_path/images" "INFO"
  81. mv $old_images_path $new_path/images
  82. fi
  83. fi
  84. if [ -d $old_meteor_path ]; then
  85. if [ -d $new_path/meteor ]; then
  86. log "Found new meteor directory already exists - not moving old meteor directory to avoid conflict (please handle yourself)" "ERROR"
  87. else
  88. log "Found old meteor path, moving the directory to $new_path/meteor" "INFO"
  89. mv $old_meteor_path $new_path/meteor
  90. fi
  91. fi
  92. log "5/$STEPS: Done moving audio, images, and meteor directories" "INFO"
  93. log "6/$STEPS: Running composer to install dependencies..." "INFO"
  94. composer install -d /var/www/wx/
  95. log "6/$STEPS: Done running composer install" "INFO"
  96. log "7/$STEPS: Aligning permissions..." "INFO"
  97. chown -R pi:pi /var/www/wx/
  98. log "8/$STEPS: Done aligning permissions" "INFO"
  99. log "8/$STEPS: Updating nginx configuration (if required)..." "INFO"
  100. echo "FILLMEIN - MOVE TO public/ AS ROOT DIR WITH REWRITES FOR index.php"
  101. log "8/$STEPS: Done updating nginx configuration" "INFO"
  102. log "9/$STEPS: Restarting nginx (if required)..." "INFO"
  103. echo "FILLMEIN: RESTART NGINX ONLY IF REQUIRED"
  104. log "9/$STEPS: Done restarting nginx" "INFO"
  105. log "Your old PHP config file has been copied to the bak/ directory" "INFO"
  106. log "Please update any settings you wish to preserve in $WEB_DIR/config.php" "INFO"
  107. log " including 'lang' and 'timezone' settings for display" "INFO"