upgrade 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. upgrade_type=$(ynh_check_app_version_changed)
  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. if [ "$upgrade_type" == "UPGRADE_APP" ]
  54. then
  55. # Update la copie du repo de pihole (nécessaire pour Gravity)
  56. pihole_local_repo="/etc/.pihole"
  57. ynh_setup_source "$pihole_local_repo"
  58. # Update le dashboard admin
  59. ynh_setup_source "$final_path" admin_dashboard
  60. fi
  61. #=================================================
  62. # NGINX CONFIGURATION
  63. #=================================================
  64. ynh_add_nginx_config
  65. #=================================================
  66. # CREATE DEDICATED USER
  67. #=================================================
  68. ynh_system_user_create $app # Create the dedicated user, if not exist
  69. #=================================================
  70. # PHP-FPM CONFIGURATION
  71. #=================================================
  72. ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
  73. #=================================================
  74. # SPECIFIC UPGRADE
  75. #=================================================
  76. # UPDATE PI-HOLE SCRIPTS
  77. #=================================================
  78. # Update les scripts de Pi-hole
  79. pihole_dir="/opt/pihole"
  80. cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
  81. cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
  82. # And copy this fucking COL_TABLE file...
  83. cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
  84. #=================================================
  85. # Copy the Pi-hole main script
  86. #=================================================
  87. cp -a "$pihole_local_repo/pihole" /usr/local/bin/
  88. cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
  89. #=================================================
  90. # CREATE SUDOER FILE
  91. #=================================================
  92. # Cette configuration sudoers autorise pihole à exécuter /usr/local/bin/pihole en root sans mot de passe. Pas plus.
  93. cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
  94. echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
  95. chmod 0440 /etc/sudoers.d/pihole
  96. #=================================================
  97. # UPDATE LOGROTATE SCRIPT FOR PI-HOLE
  98. #=================================================
  99. pihole_storage="/etc/pihole"
  100. cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
  101. dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
  102. sed -i "/# su #/d;" "$pihole_storage/logrotate"
  103. #=================================================
  104. # UPDATE OF PIHOLE-FTL
  105. #=================================================
  106. ynh_system_reload --service_name=pihole-FTL --action=stop
  107. if [ "$upgrade_type" == "UPGRADE_APP" ]
  108. then
  109. # Get the source of Pi-Hole-FTL
  110. FTL_temp_path=$(mktemp -d)
  111. ynh_setup_source "$FTL_temp_path" FTL
  112. # Plutôt que télécharger le binaire C, on le compile nous-même.
  113. ( cd "$FTL_temp_path"
  114. ynh_exec_warn_less make
  115. ynh_exec_warn_less make install )
  116. ynh_secure_remove "$FTL_temp_path"
  117. fi
  118. cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
  119. chmod +x /etc/init.d/pihole-FTL
  120. ynh_exec_warn_less systemctl enable pihole-FTL
  121. #=================================================
  122. # BUILD THE VARIABLES FILE
  123. #=================================================
  124. setupVars="$pihole_storage/setupVars.conf"
  125. ynh_backup_if_checksum_is_different "$setupVars" # Créé un backup du fichier de config si il a été modifié.
  126. # Trouve l'interface réseau par défaut
  127. main_iface=$(ip route | grep default | awk '{print $5;}')
  128. echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
  129. echo "IPV4_ADDRESS=127.0.0.1" >> $setupVars
  130. echo "IPV6_ADDRESS=" >> $setupVars
  131. echo "PIHOLE_DNS_1=" >> $setupVars
  132. echo "PIHOLE_DNS_2=" >> $setupVars
  133. if [ $query_logging -eq 1 ]; then
  134. query_logging=true
  135. else
  136. query_logging=false
  137. fi
  138. echo "QUERY_LOGGING=$query_logging" >> $setupVars
  139. echo "INSTALL_WEB=true" >> $setupVars
  140. ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config
  141. #=================================================
  142. # UPDATE THE CRON JOB
  143. #=================================================
  144. cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
  145. # Remove git usage for version. Which fails because we use here a release instead of master.
  146. ynh_replace_string ".*updatechecker.*" "#&" /etc/cron.d/pihole
  147. #=================================================
  148. # START PIHOLE-FTL
  149. #=================================================
  150. ynh_system_reload --service_name=pihole-FTL --action=restart
  151. #=================================================
  152. # UPDATE THE CONF_REGEN HOOK
  153. #=================================================
  154. cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
  155. #=================================================
  156. # RELOAD NGINX
  157. #=================================================
  158. ynh_system_reload --service_name=nginx
  159. #=================================================
  160. # DEACTIVE MAINTENANCE MODE
  161. #=================================================
  162. ynh_maintenance_mode_OFF