upgrade 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. # Load common variables for all scripts.
  10. source _variables
  11. #=================================================
  12. # LOAD SETTINGS
  13. #=================================================
  14. app=$YNH_APP_INSTANCE_NAME
  15. domain=$(ynh_app_setting_get $app domain)
  16. path_url=$(ynh_app_setting_get $app path)
  17. admin=$(ynh_app_setting_get $app admin)
  18. query_logging=$(ynh_app_setting_get $app query_logging)
  19. final_path=$(ynh_app_setting_get $app final_path)
  20. port=$(ynh_app_setting_get $app port)
  21. #=================================================
  22. # CHECK VERSION
  23. #=================================================
  24. ynh_abort_if_up_to_date
  25. #=================================================
  26. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  27. #=================================================
  28. # Backup the current version of the app
  29. ynh_backup_before_upgrade
  30. ynh_clean_setup () {
  31. # restore it if the upgrade fails
  32. ynh_restore_upgradebackup
  33. }
  34. # Exit if an error occurs during the execution of the script
  35. ynh_abort_if_errors
  36. #=================================================
  37. # CHECK THE PATH
  38. #=================================================
  39. path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
  40. #=================================================
  41. # ACTIVATE MAINTENANCE MODE
  42. #=================================================
  43. ynh_maintenance_mode_ON
  44. #=================================================
  45. # STANDARD UPGRADE STEPS
  46. #=================================================
  47. # INSTALL DEPENDENCIES
  48. #=================================================
  49. ynh_install_app_dependencies $app_depencencies
  50. #=================================================
  51. # DOWNLOAD, CHECK AND UNPACK SOURCE
  52. #=================================================
  53. # Update la copie du repo de pihole (nécessaire pour Gravity)
  54. pihole_local_repo="/etc/.pihole"
  55. ynh_setup_source "$pihole_local_repo"
  56. # Update le dashboard admin
  57. ynh_setup_source "$final_path" admin_dashboard
  58. #=================================================
  59. # NGINX CONFIGURATION
  60. #=================================================
  61. if [ "$path_url" != "/" ]
  62. then
  63. ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
  64. fi
  65. ynh_add_nginx_config
  66. #=================================================
  67. # CREATE DEDICATED USER
  68. #=================================================
  69. ynh_system_user_create $app # Create the dedicated user, if not exist
  70. #=================================================
  71. # PHP-FPM CONFIGURATION
  72. #=================================================
  73. ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
  74. #=================================================
  75. # SPECIFIC UPGRADE
  76. #=================================================
  77. # UPDATE PI-HOLE SCRIPTS
  78. #=================================================
  79. # Update les scripts de Pi-hole
  80. pihole_dir="/opt/pihole"
  81. cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
  82. cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
  83. # And copy this fucking COL_TABLE file...
  84. cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
  85. #=================================================
  86. # Copy the Pi-hole main script
  87. #=================================================
  88. cp -a "$pihole_local_repo/pihole" /usr/local/bin/
  89. cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
  90. #=================================================
  91. # CREATE SUDOER FILE
  92. #=================================================
  93. # Cette configuration sudoers autorise pihole à exécuter /usr/local/bin/pihole en root sans mot de passe. Pas plus.
  94. cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
  95. echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
  96. chmod 0440 /etc/sudoers.d/pihole
  97. #=================================================
  98. # UPDATE LOGROTATE SCRIPT FOR PI-HOLE
  99. #=================================================
  100. pihole_storage="/etc/pihole"
  101. cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
  102. dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
  103. sed -i "/# su #/d;" "$pihole_storage/logrotate"
  104. #=================================================
  105. # UPDATE OF PIHOLE-FTL
  106. #=================================================
  107. ynh_system_reload pihole-FTL stop
  108. # Get the source of Pi-Hole-FTL
  109. FTL_temp_path=$(mktemp -d)
  110. ynh_setup_source "$FTL_temp_path" FTL
  111. # Plutôt que télécharger le binaire C, on le compile nous-même.
  112. ( cd "$FTL_temp_path"
  113. ynh_exec_warn_less make
  114. ynh_exec_warn_less make install )
  115. ynh_secure_remove "$FTL_temp_path"
  116. cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
  117. chmod +x /etc/init.d/pihole-FTL
  118. ynh_exec_warn_less systemctl enable pihole-FTL
  119. #=================================================
  120. # BUILD THE VARIABLES FILE
  121. #=================================================
  122. setupVars="$pihole_storage/setupVars.conf"
  123. ynh_backup_if_checksum_is_different "$setupVars" # Créé un backup du fichier de config si il a été modifié.
  124. # Trouve l'interface réseau par défaut
  125. main_iface=$(route | grep default | awk '{print $8;}' | head -n1)
  126. echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
  127. echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
  128. echo "IPV6_ADDRESS=" >> $setupVars
  129. echo "PIHOLE_DNS_1=" >> $setupVars
  130. echo "PIHOLE_DNS_2=" >> $setupVars
  131. if [ $query_logging -eq 1 ]; then
  132. query_logging=true
  133. else
  134. query_logging=false
  135. fi
  136. echo "QUERY_LOGGING=$query_logging" >> $setupVars
  137. echo "INSTALL_WEB=true" >> $setupVars
  138. ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config
  139. #=================================================
  140. # UPDATE THE CRON JOB
  141. #=================================================
  142. cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
  143. # Remove git usage for version. Which fails because we use here a release instead of master.
  144. ynh_replace_string ".*updatechecker.*" "#&" /etc/cron.d/pihole
  145. #=================================================
  146. # START PIHOLE-FTL
  147. #=================================================
  148. ynh_system_reload pihole-FTL restart
  149. #=================================================
  150. # UPDATE THE CONF_REGEN HOOK
  151. #=================================================
  152. cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
  153. #=================================================
  154. # RELOAD NGINX
  155. #=================================================
  156. ynh_system_reload nginx
  157. #=================================================
  158. # DEACTIVE MAINTENANCE MODE
  159. #=================================================
  160. ynh_maintenance_mode_OFF