| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #!/bin/bash
- #=================================================
- # IMPORT GENERIC HELPERS
- #=================================================
- source _common.sh
- source /usr/share/yunohost/helpers
- #=================================================
- # ACTIVATE MAINTENANCE MODE
- #=================================================
- ynh_script_progression --message="Activating maintenance mode..." --weight=1
- ynh_maintenance_mode_ON
- #=================================================
- # STOP SYSTEMD SERVICE
- #=================================================
- ynh_script_progression --message="Stopping a systemd service..." --weight=1
- ynh_systemd_action --service_name="pihole-FTL" --action="stop" --log_path="/var/log/pihole/FTL.log"
- #=================================================
- # ENSURE DOWNWARD COMPATIBILITY
- #=================================================
- ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
- # Before version 6.x pihole could be installed under a path,
- # this functionnality has been deprecated since version 6.0.0 and pihole
- # now need to be installed under its own domain.
- # If the app is currently installed under a path, we warn the admin
- # that he should move the app under its own domain
- if [ "$path" != "/" ]; then
- ynh_die --message="Since version 6.0.0, $app need to be installed under its own domain. \
- Before upgrading, change $app URL: delete the path and switch to a new domain if needed."
- fi
- # If overwrite_setupvars doesn't exist, create it
- if [ -z "${overwrite_setupvars:-}" ]; then
- overwrite_setupvars=1
- ynh_app_setting_set --app="$app" --key="overwrite_setupvars" --value="$overwrite_setupvars"
- fi
- # If overwrite_ftl doesn't exist, create it
- if [ -z "${overwrite_ftl:-}" ]; then
- overwrite_ftl=1
- ynh_app_setting_set --app="$app" --key="overwrite_ftl" --value="$overwrite_ftl"
- fi
- # If pihole_version doesn't exist, create it
- if [ -z "${pihole_version:-}" ]; then
- pihole_version="Last 3.X"
- ynh_app_setting_set --app="$app" --key="pihole_version" --value=""$pihole_version""
- fi
- ynh_remove_fpm_config
- #=================================================
- # DOWNLOAD, CHECK AND UNPACK SOURCE
- #=================================================
- ynh_script_progression --message="Upgrading source files..." --weight=4
- # Download, check integrity, uncompress and patch the source from app.src
- ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO"
- ynh_setup_source --source_id="pi-hole_web" --dest_dir="$install_dir/web"
- ynh_setup_source --source_id="pi-hole_ftl" --dest_dir="/usr/bin"
- chmod +x "/usr/bin/pihole-FTL"
- chmod -R o-rwx "$install_dir"
- chown -R "$app:www-data" "$install_dir"
- #=================================================
- # UPDATE THE SCRIPTS
- #=================================================
- ynh_script_progression --message="Upgrading Pihole..." --weight=1
- install -o "$app" -Dm755 -d "$PI_HOLE_INSTALL_DIR"
- install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/gravity.sh"
- install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts"/*.sh
- install -o "$app" -Dm755 -t "$PI_HOLE_INSTALL_DIR" "$PI_HOLE_LOCAL_REPO/advanced/Scripts/COL_TABLE"
- install -Dm644 -t /etc/bash_completion.d/ "$PI_HOLE_LOCAL_REPO/advanced/bash-completion/pihole"
- install -o "$app" -Dm755 -t "$PI_HOLE_BIN_DIR" "$PI_HOLE_LOCAL_REPO/pihole"
- #=================================================
- # UPDATE THE CONFIGS
- #=================================================
- ynh_script_progression --message="Updating $app's configuration files..." --weight=1
- install -d -m 0755 "$PI_HOLE_CONFIG_DIR"
- ynh_add_config --template="dns-servers.conf" --destination="$PI_HOLE_CONFIG_DIR/dns-servers.conf"
- # Overwrite pihole-FTL config file only if it's allowed
- if [ "$overwrite_ftl" -eq 1 ]; then
- ynh_add_config --template="pihole.toml" --destination="$PI_HOLE_CONFIG_DIR/pihole.toml"
- fi
- # Overwrite the setupVars config file only if it's allowed
- if [ "$overwrite_setupvars" -eq 1 ]; then
- ynh_add_config --template="setupVars.conf" --destination="$PI_HOLE_CONFIG_DIR/setupVars.conf"
- fi
- chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf"
- #=================================================
- # SET VERSIONS FOR THE FOOTER OF THE WEB INTERFACE
- #=================================================
- ynh_script_progression --message="Setting versions for the footer of the web interface..." --weight=1
- echo "master master master" > "$PI_HOLE_CONFIG_DIR/localbranches"
- echo "$(ynh_app_upstream_version) $pihole_adminlte_version $pihole_flt_version" \
- | tee "$PI_HOLE_CONFIG_DIR/"{GitHubVersions,localversions} > /dev/null
- #=================================================
- # BUILD THE LISTS WITH GRAVITY
- #=================================================
- ynh_script_progression --message="Building the lists with Gravity..." --weight=7
- ynh_add_config --template="adlists.default" --destination="$PI_HOLE_CONFIG_DIR/adlists.list"
- ynh_exec_warn_less "$PI_HOLE_INSTALL_DIR/gravity.sh" --force
- #=================================================
- # CONFIGURE DNS FOR THE LOCAL DOMAINS
- #=================================================
- ynh_script_progression --message="Configuring DNS for the local domains..." --weight=7
- # List all YunoHost domains
- while read -r perdomain; do
- # Comment domain resolution in /etc/hosts on 127.0.0.1, because they can interfere with the local network resolution.
- ynh_replace_string --match_string="^127.0.0.1.*$perdomain" --replace_string="#Commented by pihole# &" --target_file=/etc/hosts
- # And add a resolution on the local IP instead
- grep -q "^$localipv4.*$perdomain" /etc/hosts || \
- echo "$localipv4 $perdomain #Added by pihole#" >> /etc/hosts
- done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
- #=================================================
- # DISABLING DNSMASQ
- #=================================================
- ynh_script_progression --message="Disabling Dnsmasq in system and yunohost..." --weight=1
- # Stop dnsmasq to replace it by pihole-FTL
- ynh_systemd_action --service_name=dnsmasq --action=stop
- # Disable the real dnsmasq service
- #ynh_exec_warn_less systemctl disable dnsmasq --quiet
- # Replace the service dnsmasq by pihole-FTL
- # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
- #ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
- systemctl mask dnsmasq.service
- # Reload systemd config
- systemctl daemon-reload
- # Workaround for strings to not be replaced
- a_range="__A_RANGE__"
- b_range="__B_RANGE__"
- gateway="__GATEWAY__"
- ynh_add_config --template="dnsmasq_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
- ynh_exec_warn_less yunohost tools regen-conf dnsmasq
- #=================================================
- # REAPPLY SYSTEM CONFIGURATIONS
- #=================================================
- ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
- # Create a dedicated NGINX config
- ynh_add_nginx_config
- _add_sudoers_config
- _add_cron_jobs
- _add_logrotate_config
- install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
- install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-prestart.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-prestart.sh"
- install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh"
- ynh_exec_warn_less systemctl enable pihole-FTL --quiet
- yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole/FTL.log" --needs_exposed_ports 53 67
- #=================================================
- # START SYSTEMD SERVICE
- #=================================================
- ynh_script_progression --message="Starting $app's systemd service..." --weight=2
- ynh_systemd_action --service_name="pihole-FTL" --action="start" --line_match="Web server ports" --log_path="/var/log/pihole/FTL.log"
- #=================================================
- # DEACTIVE MAINTENANCE MODE
- #=================================================
- ynh_script_progression --message="Disabling maintenance mode..." --weight=5
- ynh_maintenance_mode_OFF
- #=================================================
- # END OF SCRIPT
- #=================================================
- ynh_script_progression --message="Upgrade of $app completed" --last
|