mirror of
https://github.com/YunoHost-Apps/pihole_ynh.git
synced 2024-09-03 20:05:58 +02:00
Cleanup
This commit is contained in:
parent
de1d7281c1
commit
0819d938bf
14 changed files with 348 additions and 285 deletions
4
.github/workflows/updater.sh
vendored
4
.github/workflows/updater.sh
vendored
|
@ -67,10 +67,10 @@ for asset_url in ${assets[@]}; do
|
|||
# Leave $src empty to ignore the asset
|
||||
case $asset_url in
|
||||
*"AdminLTE"*)
|
||||
src="admin_dashboard"
|
||||
src="pi-hole_AdminLTE"
|
||||
;;
|
||||
*"pi-hole"*)
|
||||
src="app"
|
||||
src="pi-hole_Core"
|
||||
;;
|
||||
*)
|
||||
src=""
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
dhcp-authoritative
|
||||
dhcp-range=__A_RANGE__,__B_RANGE__,24h
|
||||
dhcp-option=option:router,__GATEWAY__
|
||||
dhcp-leasefile=/etc/pihole/dhcp.leases
|
||||
dhcp-leasefile=$PI_HOLE_CONFIG_DIR/dhcp.leases
|
||||
#quiet-dhcp
|
||||
|
||||
domain=local
|
||||
|
|
|
@ -4,14 +4,18 @@
|
|||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
php_dependencies="php$YNH_DEFAULT_PHP_VERSION-sqlite3"
|
||||
php_dependencies="php$YNH_DEFAULT_PHP_VERSION-common php$YNH_DEFAULT_PHP_VERSION-cgi php$YNH_DEFAULT_PHP_VERSION-sqlite3 php$YNH_DEFAULT_PHP_VERSION-xml php$YNH_DEFAULT_PHP_VERSION-intl"
|
||||
|
||||
# dependencies used by the app (must be on a single line)
|
||||
pkg_dependencies="sqlite3 idn2 nettle-dev libcap2-bin build-essential libgmp-dev m4 cmake libidn11-dev libreadline-dev xxd $php_dependencies"
|
||||
pkg_dependencies="cmake build-essential libgmp-dev libidn11-dev nettle-dev libreadline-dev sqlite3 cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd procps jq $php_dependencies"
|
||||
|
||||
pihole_core_version=5.11.4
|
||||
dashboard_version=5.13
|
||||
FTL_version=5.16.1
|
||||
pihole_adminlte_version=5.13
|
||||
pihole_flt_version=5.16.1
|
||||
|
||||
PI_HOLE_LOCAL_REPO="/etc/.pihole"
|
||||
PI_HOLE_INSTALL_DIR="/opt/pihole"
|
||||
PI_HOLE_CONFIG_DIR="/etc/pihole"
|
||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
|
|
|
@ -54,13 +54,12 @@ ynh_system_user_create --username=$app
|
|||
ynh_script_progression --message="Resetting source files..." --weight=1
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
pihole_local_repo="/etc/.pihole"
|
||||
(
|
||||
cd scripts
|
||||
# Overwrite the last version available
|
||||
YNH_CWD=$PWD ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
|
||||
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=admin_dashboard
|
||||
YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path" --source_id=pi-hole_AdminLTE
|
||||
|
||||
chown $app:www-data "$final_path"
|
||||
|
||||
|
@ -87,27 +86,25 @@ yunohost app action run $app reset_default_phpfpm
|
|||
#=================================================
|
||||
ynh_script_progression --message="Recreating and populating directories..." --weight=1
|
||||
|
||||
pihole_storage="/etc/pihole"
|
||||
mkdir -p "$pihole_storage"
|
||||
chown $app: -R "$pihole_storage"
|
||||
mkdir -p "$PI_HOLE_CONFIG_DIR"
|
||||
chown $app: -R "$PI_HOLE_CONFIG_DIR"
|
||||
|
||||
pihole_dir="/opt/pihole"
|
||||
mkdir -p "$pihole_dir"
|
||||
mkdir -p "$PI_HOLE_INSTALL_DIR"
|
||||
|
||||
# Make a copy of Pi-Hole scripts
|
||||
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
|
||||
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
|
||||
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 "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
|
||||
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 "$pihole_local_repo/pihole" /usr/local/bin/
|
||||
cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
|
||||
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
|
||||
|
@ -122,18 +119,18 @@ chown $dnsmasq_user:root /var/log/{pihole,pihole-FTL}.log
|
|||
# RECREATE SUDOER FILE
|
||||
#=================================================
|
||||
|
||||
# This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
|
||||
cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
|
||||
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
|
||||
# echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
|
||||
# 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 "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
|
||||
sed -i "/# su #/d;" "$pihole_storage/logrotate"
|
||||
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
|
||||
|
@ -143,7 +140,7 @@ 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=FTL
|
||||
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
|
||||
(
|
||||
|
@ -153,12 +150,12 @@ ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL
|
|||
)
|
||||
ynh_secure_remove --file="$FTL_temp_path"
|
||||
|
||||
cp "../conf/dns-servers.conf" "$pihole_storage"
|
||||
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 $pihole_local_repo/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-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
|
||||
|
||||
|
@ -183,7 +180,7 @@ yunohost app action run $app reset_default_dnsmasq
|
|||
# REINSTALL CRON JOB
|
||||
#=================================================
|
||||
|
||||
cp $pihole_local_repo/advanced/Templates/pihole.cron /etc/cron.d/pihole
|
||||
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
|
||||
|
|
|
@ -31,9 +31,9 @@ query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
|
|||
file="$1"
|
||||
|
||||
if [ "$file" = "setupVars.conf" ]; then
|
||||
config_file="/etc/pihole/setupVars.conf"
|
||||
config_file="$PI_HOLE_CONFIG_DIR/setupVars.conf"
|
||||
elif [ "$file" = "pihole-FTL.conf" ]; then
|
||||
config_file="/etc/pihole/pihole-FTL.conf"
|
||||
config_file="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -62,13 +62,13 @@ ynh_backup --src_path="$fpm_config_dir/pool.d/$app.conf"
|
|||
# BACKUP VARIOUS FILES
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/.pihole"
|
||||
ynh_backup --src_path="/etc/pihole"
|
||||
ynh_backup --src_path="/opt/pihole"
|
||||
ynh_backup --src_path="$PI_HOLE_LOCAL_REPO"
|
||||
ynh_backup --src_path="$PI_HOLE_CONFIG_DIR"
|
||||
ynh_backup --src_path="$PI_HOLE_INSTALL_DIR"
|
||||
|
||||
ynh_backup --src_path="/etc/cron.d/pihole"
|
||||
|
||||
ynh_backup --src_path="/usr/local/bin/pihole"
|
||||
ynh_backup --src_path="$PI_HOLE_BIN_DIR/pihole"
|
||||
ynh_backup --src_path="/etc/bash_completion.d/pihole"
|
||||
|
||||
ynh_backup --src_path="/etc/sudoers.d/pihole"
|
||||
|
|
|
@ -49,7 +49,7 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
# ACTIVATE MAINTENANCE MODE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Activating maintenance mode..."
|
||||
ynh_script_progression --message="Activating maintenance mode..." --weight=1
|
||||
|
||||
path_url=$old_path
|
||||
domain=$old_domain
|
||||
|
@ -107,7 +107,7 @@ fi
|
|||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..."
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
|
|
231
scripts/install
231
scripts/install
|
@ -99,15 +99,15 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
|
|||
ynh_script_progression --message="Setting up source files..." --weight=4
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
# Make a copy of local pihole repository (for Gravity)
|
||||
pihole_local_repo="/etc/.pihole"
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" --source_id="pi-hole_Core"
|
||||
ynh_setup_source --dest_dir="$final_path" --source_id=pi-hole_AdminLTE
|
||||
FTL_temp_path=$(mktemp -d)
|
||||
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id="pi-hole_FTL"
|
||||
|
||||
# Install the last version available
|
||||
ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
|
||||
# Install admin dashboard
|
||||
ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard
|
||||
|
||||
chown $app:www-data "$final_path"
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
|
@ -127,71 +127,11 @@ ynh_add_nginx_config
|
|||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# CREATE DIRECTORIES AND POPULATE THEM
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating and populating directories..." --weight=1
|
||||
|
||||
pihole_storage="/etc/pihole"
|
||||
mkdir -p "$pihole_storage"
|
||||
chown $app: -R "$pihole_storage"
|
||||
|
||||
pihole_dir="/opt/pihole"
|
||||
mkdir -p "$pihole_dir"
|
||||
|
||||
# Make a copy of Pi-Hole scripts
|
||||
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
|
||||
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
|
||||
|
||||
# And copy this fucking COL_TABLE file...
|
||||
cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
|
||||
|
||||
#=================================================
|
||||
# COPY PI-HOLE MAIN SCRIPT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Copying Pi-Hole main script..." --weight=1
|
||||
|
||||
cp -a "$pihole_local_repo/pihole" /usr/local/bin/
|
||||
cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
|
||||
|
||||
#=================================================
|
||||
# CREATE 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
|
||||
|
||||
#=================================================
|
||||
# CREATE SUDOER FILE
|
||||
#=================================================
|
||||
|
||||
# This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
|
||||
cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
|
||||
|
||||
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
|
||||
# echo "Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin" >> /etc/sudoers.d/pihole
|
||||
chmod 0440 /etc/sudoers.d/pihole
|
||||
|
||||
#=================================================
|
||||
# INSTALL LOGROTATE SCRIPT FOR PI-HOLE
|
||||
#=================================================
|
||||
|
||||
cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
|
||||
|
||||
sed -i "/# su #/d;" "$pihole_storage/logrotate"
|
||||
|
||||
#=================================================
|
||||
# INSTALLATION OF PIHOLE-FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing 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=FTL
|
||||
|
||||
# Instead of downloading a binary file, we're going to compile it
|
||||
(
|
||||
cd "$FTL_temp_path"
|
||||
|
@ -202,9 +142,71 @@ ynh_setup_source --dest_dir="$FTL_temp_path" --source_id=FTL
|
|||
|
||||
ynh_secure_remove --file="$FTL_temp_path"
|
||||
|
||||
cp "../conf/dns-servers.conf" "$pihole_storage"
|
||||
#=================================================
|
||||
# INSTALL THE SCRIPTS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing the scripts..." --weight=1
|
||||
|
||||
ynh_add_config --template="../conf/pihole-FTL.conf" --destination="$pihole_storage/pihole-FTL.conf"
|
||||
pushd "${PI_HOLE_LOCAL_REPO}"
|
||||
install -o "${app}" -Dm755 -d "${PI_HOLE_INSTALL_DIR}"
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" gravity.sh
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/*.sh
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/COL_TABLE
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_BIN_DIR}" pihole
|
||||
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# INSTALL THE CONFIGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing the configs..." --weight=1
|
||||
|
||||
install -d -m 0755 ${PI_HOLE_CONFIG_DIR}
|
||||
|
||||
cp "../conf/dns-servers.conf" "$PI_HOLE_CONFIG_DIR/dns-servers.conf"
|
||||
chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf"
|
||||
|
||||
ynh_add_config --template="../conf/pihole-FTL.conf" --destination="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf"
|
||||
|
||||
install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
|
||||
|
||||
#=================================================
|
||||
# INSTALL SUDOER FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing sudoer file..." --weight=1
|
||||
|
||||
install -m 0640 ${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
|
||||
|
||||
#=================================================
|
||||
# INSTALL A CRON JOB
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing a cron job..." --weight=1
|
||||
|
||||
install -D -m 644 -T -o root -g root ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.cron /etc/cron.d/pihole
|
||||
|
||||
# Randomize gravity update time
|
||||
sed -i "s/59 1 /$((1 + RANDOM % 58)) $((3 + RANDOM % 2))/" /etc/cron.d/pihole
|
||||
|
||||
# Randomize update checker time
|
||||
sed -i "s/59 17/$((1 + RANDOM % 58)) $((12 + RANDOM % 8))/" /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
|
||||
|
||||
#=================================================
|
||||
# INSTALL LOGROTATE SCRIPT FOR PI-HOLE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing logrotate script for PI-HOLE..." --weight=1
|
||||
|
||||
install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate "$PI_HOLE_CONFIG_DIR/logrotate"
|
||||
|
||||
sed -i "/# su #/d;" "$PI_HOLE_CONFIG_DIR/logrotate"
|
||||
|
||||
#=================================================
|
||||
# DISABLING DNSMASQ
|
||||
#=================================================
|
||||
ynh_script_progression --message="Disabling DNSMASQ..." --weight=1
|
||||
|
||||
# Last version available
|
||||
# Stopped dnsmasq to replace it by pihole-FTL
|
||||
|
@ -213,34 +215,12 @@ ynh_systemd_action --action=stop --service_name=dnsmasq
|
|||
# Disable the real dnsmasq service
|
||||
#ynh_exec_warn_less systemctl disable dnsmasq --quiet
|
||||
|
||||
# And move the files that make the service available in systemd to really disable it
|
||||
#mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
|
||||
#mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
|
||||
|
||||
# Move dnsmasq to preserve the current binary
|
||||
#mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
|
||||
# Replace dnsmasq by pihole-FTL
|
||||
# NOTE: pihole-FTL is actually a modified version of dnsmasq
|
||||
# https://github.com/pi-hole/FTL/tree/master/dnsmasq
|
||||
#ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
|
||||
|
||||
cp -a $pihole_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 --quiet
|
||||
|
||||
# Replace the service dnsmasq by pihole-FTL
|
||||
# That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
|
||||
#ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
|
||||
systemctl mask dnsmasq.service
|
||||
|
||||
# Reload systemd config
|
||||
systemctl daemon-reload
|
||||
|
||||
#=================================================
|
||||
# BUILD VARIABLES FILE
|
||||
# FINAL EXPORTS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Final exports..." --weight=1
|
||||
|
||||
setupVars="$pihole_storage/setupVars.conf"
|
||||
setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf"
|
||||
|
||||
# Get the default network interface
|
||||
main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
|
||||
|
@ -260,6 +240,39 @@ echo "INSTALL_WEB=true" >> $setupVars
|
|||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="$setupVars"
|
||||
|
||||
#=================================================
|
||||
# ENABLING FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Enable FTL..." --weight=1
|
||||
|
||||
ynh_exec_warn_less systemctl enable pihole-FTL --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
|
||||
|
||||
#=================================================
|
||||
# CREATE LOG FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating log files..." --weight=1
|
||||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# BUILD THE LISTS WITH GRAVITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building the lists with Gravity..." --weight=7
|
||||
|
||||
cp "../conf/adlists.default" "$PI_HOLE_CONFIG_DIR/adlists.list"
|
||||
ynh_exec_warn_less $PI_HOLE_INSTALL_DIR/gravity.sh --force
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE DNS FOR THE LOCAL DOMAINS
|
||||
#=================================================
|
||||
|
@ -282,6 +295,7 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
|||
#=================================================
|
||||
# ENABLE DHCP SERVER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Enabling DHCP server..." --weight=1
|
||||
|
||||
# Open the UDP port 67 for dhcp
|
||||
ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
|
||||
|
@ -289,30 +303,15 @@ ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
|
|||
#=================================================
|
||||
# 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" > $pihole_storage/localbranches
|
||||
echo "$pihole_core_version $dashboard_version $FTL_version" | tee $pihole_storage/{GitHubVersions,localversions} > /dev/null
|
||||
|
||||
#=================================================
|
||||
# INSTALL CRON JOB
|
||||
#=================================================
|
||||
|
||||
cp $pihole_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
|
||||
|
||||
#=================================================
|
||||
# BUILD THE LISTS WITH GRAVITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building the lists with Gravity..." --weight=7
|
||||
|
||||
cp "../conf/adlists.default" "$pihole_storage/adlists.list"
|
||||
ynh_exec_warn_less /opt/pihole/gravity.sh
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# SET UP CONF_REGEN HOOK
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up conf_regen hook..." --weight=1
|
||||
|
||||
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"
|
||||
|
@ -327,14 +326,14 @@ ynh_exec_warn_less yunohost tools regen-conf dnsmasq
|
|||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log"
|
||||
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 a systemd service..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL --log_path="/var/log/pihole-FTL.log"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
|
|
|
@ -63,6 +63,14 @@ ynh_secure_remove --file="/usr/bin/pihole-FTL"
|
|||
ynh_secure_remove --file="/var/run/pihole-FTL.pid"
|
||||
ynh_secure_remove --file="/var/run/pihole-FTL.port"
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing app main directory..." --weight=1
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -108,29 +116,27 @@ fi
|
|||
#=================================================
|
||||
# REMOVE VARIOUS FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing various files..."
|
||||
ynh_script_progression --message="Removing various files..." --weight=1
|
||||
|
||||
ynh_secure_remove --file="/etc/cron.d/pihole"
|
||||
# Remove a cron file
|
||||
ynh_secure_remove --file="/etc/cron.d/$app"
|
||||
|
||||
# Remove logs
|
||||
ynh_secure_remove --file="/var/log/pihole.log"
|
||||
ynh_secure_remove --file="/var/log/pihole-FTL.log"
|
||||
# Remove the log files
|
||||
ynh_secure_remove --file="/var/log/$app"
|
||||
|
||||
# Remove main script
|
||||
ynh_secure_remove --file="/usr/local/bin/pihole"
|
||||
ynh_secure_remove --file="$PI_HOLE_BIN_DIR/pihole"
|
||||
ynh_secure_remove --file="/etc/bash_completion.d/pihole"
|
||||
|
||||
# Remove sudoer file
|
||||
ynh_secure_remove --file="/etc/sudoers.d/pihole"
|
||||
|
||||
# Remove storage directory
|
||||
ynh_secure_remove --file="/etc/pihole"
|
||||
ynh_secure_remove --file="$PI_HOLE_CONFIG_DIR"
|
||||
# Remove app directory
|
||||
ynh_secure_remove --file="/opt/pihole"
|
||||
# Remove admin panel directory
|
||||
ynh_secure_remove --file="$final_path"
|
||||
ynh_secure_remove --file="$PI_HOLE_INSTALL_DIR"
|
||||
# Remove local clone of the repository
|
||||
ynh_secure_remove --file="/etc/.pihole"
|
||||
ynh_secure_remove --file="$PI_HOLE_LOCAL_REPO"
|
||||
|
||||
#=================================================
|
||||
# REMOVE DNSMASQ CONFIG
|
||||
|
@ -142,7 +148,7 @@ ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
|||
#=================================================
|
||||
# CLEAN /etc/hosts
|
||||
#=================================================
|
||||
ynh_script_progression --message="Clean /etc/hosts"
|
||||
ynh_script_progression --message="Clean /etc/hosts" --weight=1
|
||||
|
||||
# Uncomment lines in /etc/hosts
|
||||
ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts
|
||||
|
@ -153,6 +159,7 @@ sed -i "/#Added by pihole#/d" /etc/hosts
|
|||
#=================================================
|
||||
# REMOVE CONF_REGEN HOOK
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing conf_regen hook..." --weight=1
|
||||
|
||||
ynh_systemd_action --action=stop --service_name=dnsmasq
|
||||
|
||||
|
@ -163,7 +170,7 @@ ynh_exec_warn_less yunohost tools regen-conf dnsmasq
|
|||
#=================================================
|
||||
# RESTART DNSMASQ
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restarting Dnsmasq..."
|
||||
ynh_script_progression --message="Restarting Dnsmasq..." --weight=1
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=dnsmasq
|
||||
|
||||
|
|
|
@ -71,16 +71,20 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
|
|||
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/.pihole"
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/pihole"
|
||||
ynh_restore_file --origin_path="$PI_HOLE_LOCAL_REPO"
|
||||
|
||||
ynh_restore_file --origin_path="/opt/pihole"
|
||||
ynh_restore_file --origin_path="$PI_HOLE_CONFIG_DIR"
|
||||
|
||||
ynh_restore_file --origin_path="$PI_HOLE_INSTALL_DIR"
|
||||
|
||||
# Restore permissions on app files
|
||||
chown $app: -R "/etc/pihole"
|
||||
# /etc/pihole/logrotate have to belong to root, otherwise logrotate will failed silently...
|
||||
chown root: -R "/etc/pihole/logrotate"
|
||||
chown $app: -R "$PI_HOLE_CONFIG_DIR"
|
||||
# $PI_HOLE_CONFIG_DIR/logrotate have to belong to root, otherwise logrotate will failed silently...
|
||||
chown root: -R "$PI_HOLE_CONFIG_DIR/logrotate"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
|
@ -114,12 +118,14 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|||
#=================================================
|
||||
# RESTORE THE CRON FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the cron file..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="/etc/cron.d/pihole"
|
||||
|
||||
#=================================================
|
||||
# RECREATE LOG FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreate log files..." --weight=1
|
||||
|
||||
touch /var/log/pihole.log
|
||||
chmod 644 /var/log/pihole.log
|
||||
|
@ -129,9 +135,9 @@ chown $dnsmasq_user:root /var/log/pihole.log
|
|||
#=================================================
|
||||
# RESTORE SPECIFIC FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring specific files..."
|
||||
ynh_script_progression --message="Restoring specific files..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="/usr/local/bin/pihole"
|
||||
ynh_restore_file --origin_path="$PI_HOLE_BIN_DIR/pihole"
|
||||
ynh_restore_file --origin_path="/etc/bash_completion.d/pihole"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/sudoers.d/pihole"
|
||||
|
@ -144,6 +150,7 @@ ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_
|
|||
#=================================================
|
||||
# REPLACE THE DEFAULT DNSMASQ BY PIHOLE-FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Replacing the default DNSMASQ by PIHILE-FTL..." --weight=1
|
||||
|
||||
# Last version available
|
||||
# Stopped dnsmasq to replace it by pihole-FTL
|
||||
|
@ -163,8 +170,7 @@ ynh_systemd_action --action=stop --service_name=dnsmasq
|
|||
# https://github.com/pi-hole/FTL/tree/master/dnsmasq
|
||||
#ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
|
||||
|
||||
pihole_local_repo="/etc/.pihole"
|
||||
cp -a $pihole_local_repo/advanced/Templates/pihole-FTL.service /etc/init.d/pihole-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 --quiet
|
||||
|
||||
|
@ -179,7 +185,7 @@ systemctl daemon-reload
|
|||
#=================================================
|
||||
# RESTORE DNSMASQ CONFIG
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring Dnsmasq config..."
|
||||
ynh_script_progression --message="Restoring Dnsmasq config..." --weight=1
|
||||
|
||||
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && \
|
||||
ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
|
@ -211,8 +217,9 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
|||
#=================================================
|
||||
# UPDATE VARIABLES FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating variables files..." --weight=1
|
||||
|
||||
setupVars="/etc/pihole/setupVars.conf"
|
||||
setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf"
|
||||
|
||||
echo "PIHOLE_INTERFACE=$main_iface" > $setupVars
|
||||
ynh_replace_string --match_string="^PIHOLE_INTERFACE=.*" --replace_string="PIHOLE_INTERFACE=$main_iface" --target_file=$setupVars
|
||||
|
@ -226,7 +233,7 @@ ynh_store_file_checksum --file="$setupVars"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log"
|
||||
yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log" --needs_exposed_ports 53 67
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
|
|
257
scripts/upgrade
257
scripts/upgrade
|
@ -48,7 +48,6 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
|
|||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
read -p "999"
|
||||
# Restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
|
@ -58,7 +57,7 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
# ACTIVATE MAINTENANCE MODE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Activating maintenance mode..."
|
||||
ynh_script_progression --message="Activating maintenance mode..." --weight=1
|
||||
|
||||
ynh_maintenance_mode_ON
|
||||
|
||||
|
@ -67,7 +66,7 @@ ynh_maintenance_mode_ON
|
|||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||
|
||||
# If overwrite_setupvars doesn't exist, create it
|
||||
if [ -z "$overwrite_setupvars" ]; then
|
||||
|
@ -129,17 +128,18 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
|
|||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
pihole_local_repo="/etc/.pihole"
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..." --weight=4
|
||||
# Update the last version available
|
||||
ynh_setup_source --dest_dir="$pihole_local_repo" --source_id=app
|
||||
# Update admin dashboard
|
||||
ynh_setup_source --dest_dir="$final_path" --source_id=admin_dashboard
|
||||
ynh_setup_source --dest_dir="$PI_HOLE_LOCAL_REPO" --source_id="pi-hole_Core"
|
||||
ynh_setup_source --dest_dir="$final_path" --source_id=pi-hole_AdminLTE
|
||||
FTL_temp_path=$(mktemp -d)
|
||||
ynh_setup_source --dest_dir="$FTL_temp_path" --source_id="pi-hole_FTL"
|
||||
fi
|
||||
|
||||
chown $app:www-data "$final_path"
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
|
@ -174,55 +174,13 @@ fi
|
|||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# UPDATE PI-HOLE SCRIPTS
|
||||
#=================================================
|
||||
|
||||
pihole_dir="/opt/pihole"
|
||||
cp -a "$pihole_local_repo/gravity.sh" "$pihole_dir/"
|
||||
cp -a $pihole_local_repo/advanced/Scripts/*.sh "$pihole_dir/"
|
||||
|
||||
# And copy this fucking COL_TABLE file...
|
||||
cp -a "$pihole_local_repo/advanced/Scripts/COL_TABLE" "$pihole_dir/"
|
||||
|
||||
#=================================================
|
||||
# COPY PI-HOLE MAIN SCRIPT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Copying Pi-Hole main script..."
|
||||
|
||||
cp -a "$pihole_local_repo/pihole" /usr/local/bin/
|
||||
cp -a "$pihole_local_repo/advanced/bash-completion/pihole" /etc/bash_completion.d/pihole
|
||||
|
||||
#=================================================
|
||||
# CREATE SUDOER FILE
|
||||
#=================================================
|
||||
|
||||
# This sudoers config allow pihole to execute /usr/local/bin/pihole as root without password. Nothing more.
|
||||
cp "$pihole_local_repo/advanced/Templates/pihole.sudo" /etc/sudoers.d/pihole
|
||||
echo "$app ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole
|
||||
chmod 0440 /etc/sudoers.d/pihole
|
||||
|
||||
#=================================================
|
||||
# UPDATE LOGROTATE SCRIPT FOR PI-HOLE
|
||||
#=================================================
|
||||
|
||||
pihole_storage="/etc/pihole"
|
||||
cp "$pihole_local_repo/advanced/Templates/logrotate" "$pihole_storage/logrotate"
|
||||
sed -i "/# su #/d;" "$pihole_storage/logrotate"
|
||||
|
||||
#=================================================
|
||||
# UPDATE PIHOLE-FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading PiHole-FTL..." --weight=35
|
||||
|
||||
ynh_systemd_action --action=stop --service_name=pihole-FTL
|
||||
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
# 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=FTL
|
||||
ynh_script_progression --message="Upgrading PiHole-FTL..." --weight=35
|
||||
|
||||
# Instead of downloading a binary file, we're going to compile it
|
||||
(
|
||||
|
@ -234,12 +192,76 @@ then
|
|||
ynh_secure_remove --file="$FTL_temp_path"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# UPDATE THE SCRIPTS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating the scripts..." --weight=1
|
||||
|
||||
pushd "${PI_HOLE_LOCAL_REPO}"
|
||||
install -o "${app}" -Dm755 -d "${PI_HOLE_INSTALL_DIR}"
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" gravity.sh
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/*.sh
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_INSTALL_DIR}" ./advanced/Scripts/COL_TABLE
|
||||
install -o "${app}" -Dm755 -t "${PI_HOLE_BIN_DIR}" pihole
|
||||
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# UPDATE THE CONFIGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating the configs..." --weight=1
|
||||
|
||||
install -d -m 0755 ${PI_HOLE_CONFIG_DIR}
|
||||
|
||||
cp -f "../conf/dns-servers.conf" "$PI_HOLE_CONFIG_DIR/dns-servers.conf"
|
||||
chmod 644 "${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="../conf/pihole-FTL.conf" --destination="$pihole_storage/pihole-FTL.conf"
|
||||
ynh_add_config --template="../conf/pihole-FTL.conf" --destination="$PI_HOLE_CONFIG_DIR/pihole-FTL.conf"
|
||||
fi
|
||||
|
||||
install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL"
|
||||
|
||||
#=================================================
|
||||
# INSTALL SUDOER FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing sudoer file..." --weight=1
|
||||
|
||||
install -m 0640 ${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
|
||||
|
||||
#=================================================
|
||||
# UPDATE A CRON JOB
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating a cron job..." --weight=1
|
||||
|
||||
install -D -m 644 -T -o root -g root ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.cron /etc/cron.d/pihole
|
||||
|
||||
# Randomize gravity update time
|
||||
sed -i "s/59 1 /$((1 + RANDOM % 58)) $((3 + RANDOM % 2))/" /etc/cron.d/pihole
|
||||
|
||||
# Randomize update checker time
|
||||
sed -i "s/59 17/$((1 + RANDOM % 58)) $((12 + RANDOM % 8))/" /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
|
||||
|
||||
#=================================================
|
||||
# UPDATE LOGROTATE SCRIPT FOR PI-HOLE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating logrotate script for PI-HOLE..." --weight=1
|
||||
|
||||
install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate "$PI_HOLE_CONFIG_DIR/logrotate"
|
||||
|
||||
sed -i "/# su #/d;" "$PI_HOLE_CONFIG_DIR/logrotate"
|
||||
|
||||
#=================================================
|
||||
# DISABLING DNSMASQ
|
||||
#=================================================
|
||||
ynh_script_progression --message="Disabling DNSMASQ..." --weight=1
|
||||
|
||||
# Last version available
|
||||
# Stopped dnsmasq to replace it by pihole-FTL
|
||||
ynh_systemd_action --action=stop --service_name=dnsmasq
|
||||
|
@ -247,44 +269,17 @@ ynh_systemd_action --action=stop --service_name=dnsmasq
|
|||
# Disable the real dnsmasq service
|
||||
#ynh_exec_warn_less systemctl disable dnsmasq --quiet
|
||||
|
||||
# And move the files that make the service available in systemd to really disable it
|
||||
#if [ ! -e "/lib/systemd/system/.dnsmasq.service.backup_by_pihole" ]; then
|
||||
# mv /lib/systemd/system/dnsmasq.service /lib/systemd/system/.dnsmasq.service.backup_by_pihole
|
||||
#fi
|
||||
#if [ ! -e "/etc/init.d/.dnsmasq.backup_by_pihole" ]; then
|
||||
# mv /etc/init.d/dnsmasq /etc/init.d/.dnsmasq.backup_by_pihole
|
||||
#fi
|
||||
|
||||
# Move dnsmasq to preserve the current binary
|
||||
#if [ ! -e "/usr/sbin/dnsmasq.backup_by_pihole" ]; then
|
||||
# mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.backup_by_pihole
|
||||
#fi
|
||||
# Replace dnsmasq by pihole-FTL
|
||||
# NOTE: pihole-FTL is actually a modified version of dnsmasq
|
||||
# https://github.com/pi-hole/FTL/tree/master/dnsmasq
|
||||
#ln -sf /usr/bin/pihole-FTL /usr/sbin/dnsmasq
|
||||
|
||||
cp -a $pihole_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 --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
|
||||
|
||||
#=================================================
|
||||
# BUILD VARIABLES FILE
|
||||
# FINAL EXPORTS
|
||||
#=================================================
|
||||
|
||||
setupVars="$pihole_storage/setupVars.conf"
|
||||
setupVars="$PI_HOLE_CONFIG_DIR/setupVars.conf"
|
||||
|
||||
# Overwrite the setupVars config file only if it's allowed
|
||||
if [ $overwrite_setupvars -eq 1 ]
|
||||
then
|
||||
ynh_script_progression --message="Final exports..." --weight=1
|
||||
|
||||
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
|
||||
ynh_backup_if_checksum_is_different --file="$setupVars"
|
||||
|
||||
|
@ -307,28 +302,73 @@ then
|
|||
ynh_store_file_checksum --file="$setupVars"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# ENABLING FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Enable FTL..." --weight=1
|
||||
|
||||
ynh_exec_warn_less systemctl enable pihole-FTL --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
|
||||
|
||||
#=================================================
|
||||
# CREATE LOG FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating log files..." --weight=1
|
||||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# BUILD THE LISTS WITH GRAVITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building the lists with Gravity..." --weight=7
|
||||
|
||||
cp -f "../conf/adlists.default" "$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
|
||||
|
||||
# Find the IP associated to the network interface
|
||||
localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
|
||||
|
||||
# List all YunoHost domains
|
||||
while read 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/.*: \|.*- //')"
|
||||
|
||||
#=================================================
|
||||
# ENABLE DHCP SERVER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Enabling DHCP server..." --weight=1
|
||||
|
||||
# Open the UDP port 67 for dhcp
|
||||
ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
|
||||
|
||||
#=================================================
|
||||
# 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" > $pihole_storage/localbranches
|
||||
echo "$pihole_core_version $dashboard_version $FTL_version" | tee $pihole_storage/{GitHubVersions,localversions} > /dev/null
|
||||
|
||||
#=================================================
|
||||
# UPDATE CRON JOB
|
||||
#=================================================
|
||||
|
||||
cp $pihole_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
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add pihole-FTL --description="PiHole backend service" --log="/var/log/pihole-FTL.log"
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# UPDATE CONF_REGEN HOOK
|
||||
|
@ -342,9 +382,18 @@ systemctl daemon-reload
|
|||
ynh_exec_warn_less yunohost tools regen-conf dnsmasq
|
||||
|
||||
#=================================================
|
||||
# START PIHOLE-FTL
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
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 a systemd service..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue