upgrade 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # LOAD SETTINGS
  11. #=================================================
  12. app=$YNH_APP_INSTANCE_NAME
  13. domain=$(ynh_app_setting_get $app domain)
  14. path_url=$(ynh_app_setting_get $app path)
  15. admin=$(ynh_app_setting_get $app admin)
  16. query_logging=$(ynh_app_setting_get $app query_logging)
  17. final_path=$(ynh_app_setting_get $app final_path)
  18. port=$(ynh_app_setting_get $app port)
  19. #=================================================
  20. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  21. #=================================================
  22. BACKUP_BEFORE_UPGRADE # Backup the current version of the app
  23. ynh_clean_setup () {
  24. BACKUP_FAIL_UPGRADE # restore it if the upgrade fails
  25. }
  26. ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
  27. #=================================================
  28. # CHECK THE PATH
  29. #=================================================
  30. path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
  31. #=================================================
  32. # STANDARD UPGRADE STEPS
  33. #=================================================
  34. # DOWNLOAD, CHECK AND UNPACK SOURCE
  35. #=================================================
  36. # Update la copie du repo de pihole (nécessaire pour Gravity)
  37. pihole_local_repo="/etc/.pihole"
  38. ynh_setup_source "$pihole_local_repo"
  39. # Update le dashboard admin
  40. ynh_setup_source "$final_path" admin_dashboard
  41. #=================================================
  42. # NGINX CONFIGURATION
  43. #=================================================
  44. ynh_add_nginx_config
  45. #=================================================
  46. # CREATE DEDICATED USER
  47. #=================================================
  48. ynh_system_user_create $app # Create the dedicated user, if not exist
  49. #=================================================
  50. # PHP-FPM CONFIGURATION
  51. #=================================================
  52. ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
  53. #=================================================
  54. # SPECIFIC UPGRADE
  55. #=================================================
  56. # UPDATE PI-HOLE SCRIPTS
  57. #=================================================
  58. # Update les scripts de Pi-hole
  59. pihole_dir="/opt/pihole"
  60. cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
  61. cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
  62. #=================================================
  63. # Copy the Pi-hole main script
  64. #=================================================
  65. cp -a "$pihole_local_repo/pihole" /usr/local/bin/
  66. cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
  67. #=================================================
  68. # CREATE SUDOER FILE
  69. #=================================================
  70. # Cette configuration sudoers autorise pihole à exécuter /usr/local/bin/pihole en root sans mot de passe. Pas plus.
  71. cp "$pihole_local_repo/advanced/pihole.sudo" /etc/sudoers.d/pihole
  72. echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
  73. chmod 0440 /etc/sudoers.d/pihole
  74. #=================================================
  75. # UPDATE LOGROTATE SCRIPT FOR PI-HOLE
  76. #=================================================
  77. pihole_storage="/etc/pihole"
  78. cp "$pihole_local_repo/advanced/logrotate" "$pihole_storage/logrotate"
  79. dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2)
  80. sed -i "s/# su #/su $dnsmasq_user/g;" "$pihole_storage/logrotate"
  81. #=================================================
  82. # UPDATE OF PIHOLE-FTL
  83. #=================================================
  84. systemctl stop pihole-FTL
  85. git clone https://github.com/pi-hole/FTL
  86. # Plutôt que télécharger le binaire C, on le compile nous-même.
  87. ( cd FTL
  88. SUPPRESS_WARNING make
  89. SUPPRESS_WARNING make install )
  90. cp -a $pihole_local_repo/advanced/pihole-FTL.service /etc/init.d/pihole-FTL
  91. chmod +x /etc/init.d/pihole-FTL
  92. SUPPRESS_WARNING systemctl enable pihole-FTL
  93. #=================================================
  94. # BUILD THE VARIABLES FILE
  95. #=================================================
  96. setupVars="$pihole_storage/setupVars.conf"
  97. ynh_backup_if_checksum_is_different "$setupVars" # Créé un backup du fichier de config si il a été modifié.
  98. # Trouve l'interface réseau par défaut
  99. main_iface=$(route | grep default | awk '{print $8;}' | head -n1)
  100. echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
  101. # Trouve l'ipv4 associée à l'interface trouvée
  102. localipv4=$(ifconfig | grep -A 1 "$main_iface" | tail -1 | awk '{print $2;}' | cut -d: -f2)
  103. echo "IPV4_ADDRESS=$localipv4" >> $setupVars
  104. echo "IPV6_ADDRESS=::/0" >> $setupVars
  105. echo "PIHOLE_DNS_1=" >> $setupVars
  106. echo "PIHOLE_DNS_2=" >> $setupVars
  107. if [ $query_logging -eq 1 ]; then
  108. query_logging=true
  109. else
  110. query_logging=false
  111. fi
  112. echo "QUERY_LOGGING=$query_logging" >> $setupVars
  113. echo "INSTALL_WEB=true" >> $setupVars
  114. ynh_store_file_checksum "$setupVars" # Enregistre la somme de contrôle du fichier de config
  115. #=================================================
  116. # UPDATE THE CRON JOB
  117. #=================================================
  118. cp $pihole_local_repo/advanced/pihole.cron /etc/cron.d/pihole
  119. #=================================================
  120. # START PIHOLE-FTL
  121. #=================================================
  122. systemctl start pihole-FTL
  123. #=================================================
  124. # SETUP LOGROTATE
  125. #=================================================
  126. ynh_use_logrotate /var/log/pihole.log --non-append
  127. ynh_use_logrotate /var/log/pihole-FTL.log
  128. #=================================================
  129. # START PIHOLE-FTL
  130. #=================================================
  131. systemctl start pihole-FTL
  132. #=================================================
  133. # RELOAD NGINX
  134. #=================================================
  135. sudo systemctl reload nginx