#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= # Load common variables for all scripts. source scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { # Clean installation remaining that are not handle by the remove script. ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS #================================================= app=$YNH_APP_INSTANCE_NAME path_url=$(ynh_app_setting_get --app=$app --key=path) domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # SPECIFIC ACTION #================================================= # ACTIVATE MAINTENANCE MODE #================================================= ynh_script_progression --message="Activating maintenance mode..." --weight=1 ynh_maintenance_mode_ON #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create --username=$app #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Resetting source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ( cd scripts # Overwrite the last version available YNH_CWD=$PWD ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" --source_id="pi-hole_Core" # Overwrite admin dashboard YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=pi-hole_AdminLTE chown $app:www-data "$final_path" ) #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Resetting NGINX web server configuration..." --weight=1 # Create a dedicated nginx config yunohost app action run $app reset_default_nginx #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Resetting PHP-FPM configuration..." --weight=1 # Create a dedicated php-fpm config yunohost app action run $app reset_default_phpfpm #================================================= # RECREATE DIRECTORIES #================================================= ynh_script_progression --message="Recreating and populating directories..." --weight=1 mkdir -p "$PI_HOLE_CONFIG_DIR" chown $app: -R "$PI_HOLE_CONFIG_DIR" mkdir -p "$PI_HOLE_INSTALL_DIR" # Make a copy of Pi-Hole scripts cp -a "$PI_HOLE_LOCAL_REPO/gravity.sh" "$PI_HOLE_INSTALL_DIR/" cp -a $PI_HOLE_LOCAL_REPO/advanced/Scripts/*.sh "$PI_HOLE_INSTALL_DIR/" # And copy this fucking COL_TABLE file... cp -a "$PI_HOLE_LOCAL_REPO/advanced/Scripts/COL_TABLE" "$PI_HOLE_INSTALL_DIR/" #================================================= # COPY PI-HOLE MAIN SCRIPT #================================================= ynh_script_progression --message="Copying Pi-Hole main script..." cp -a "$PI_HOLE_LOCAL_REPO/pihole" $PI_HOLE_BIN_DIR/ cp -a "$PI_HOLE_LOCAL_REPO/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole #================================================= # RECREATE LOG FILES #================================================= touch /var/log/{pihole,pihole-FTL}.log chmod 644 /var/log/{pihole,pihole-FTL}.log dnsmasq_user=$(grep DNSMASQ_USER= /etc/init.d/dnsmasq | cut -d'"' -f2) chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log #================================================= # RECREATE SUDOER FILE #================================================= # This sudoers config allow pihole to execute $PI_HOLE_BIN_DIR/pihole as root without password. Nothing more. cp "$PI_HOLE_LOCAL_REPO/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole echo "$app ALL=NOPASSWD: $PI_HOLE_BIN_DIR/pihole" >> /etc/sudoers.d/pihole # echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:$PI_HOLE_BIN_DIR" >> /etc/sudoers.d/pihole chmod 0440 /etc/sudoers.d/pihole #================================================= # REINSTALL LOGROTATE SCRIPT FOR PI-HOLE #================================================= cp "$PI_HOLE_LOCAL_REPO/advanced/Templates/logrotate" "$PI_HOLE_CONFIG_DIR/logrotate" sed -i "/# su #/d;" "$PI_HOLE_CONFIG_DIR/logrotate" #================================================= # REINSTALLATION OF PIHOLE-FTL #================================================= ynh_script_progression --message="Reinstalling PiHole-FTL..." --weight=30 # Get the source of Pi-Hole-FTL FTL_temp_path=$(mktemp -d) # Install the last version available ynh_setup_source --dest_dir="$FTL_temp_path" --source_id="pi-hole_FTL" # Instead of downloading a binary file, we're going to compile it ( cd "$FTL_temp_path" ynh_exec_warn_less make ynh_exec_warn_less make install ) ynh_secure_remove --file="$FTL_temp_path" cp "../conf/dns-servers.conf" "$PI_HOLE_CONFIG_DIR" # Restore the default pihole-FTL.conf yunohost app action run $app reset_default_ftl cp -a $PI_HOLE_LOCAL_REPO/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-FTL chmod +x /etc/init.d/pihole-FTL ynh_exec_warn_less systemctl enable pihole-FTL # Reload systemd config systemctl daemon-reload #================================================= # RESET THE VARIABLES FILE #================================================= # Restore the default setupVars.conf yunohost app action run $app reset_default_setupvars #================================================= # RESET DNSMASQ CONFIG #================================================= # Restore the default setupVars.conf yunohost app action run $app reset_default_dnsmasq #================================================= # REINSTALL CRON JOB #================================================= cp $PI_HOLE_LOCAL_REPO/advanced/Templates/pihole.cron /etc/cron.d/pihole # Remove git usage for version. Which fails because we use here a release instead of master. ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole #================================================= # REINSTALL CONF_REGEN HOOK #================================================= ( cd scripts cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app" ) #================================================= # RESTART PIHOLE-FTL #================================================= ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2 ynh_systemd_action --action=restart --service_name=pihole-FTL #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # DEACTIVE MAINTENANCE MODE #================================================= ynh_script_progression --message="Disabling maintenance mode..." --weight=1 ynh_maintenance_mode_OFF #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Execution completed" --last