mirror of
https://codeberg.org/h3xx/you-dont-need-pihole.git
synced 2024-08-14 20:27:01 +00:00
Compare commits
4 commits
637c4a1b81
...
dc38b1a376
Author | SHA1 | Date | |
---|---|---|---|
|
dc38b1a376 | ||
|
942465cc22 | ||
|
06e9f59489 | ||
|
cc52e56e47 |
2 changed files with 12 additions and 17 deletions
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# vi: et sts=4 sw=4 ts=4
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# You Don't Need Pi-hole
|
# You Don't Need Pi-hole
|
||||||
|
@ -117,7 +116,7 @@ MAIN: {
|
||||||
} @block_ip;
|
} @block_ip;
|
||||||
} sort keys %domains;
|
} sort keys %domains;
|
||||||
|
|
||||||
printf STDERR "%d domains written to %s from\n", $written, $out;
|
printf STDERR "%d domains written to %s from\n", $written, $out // 'STDOUT';
|
||||||
printf STDERR " - %d .domains files\n", (scalar @domain_lists);
|
printf STDERR " - %d .domains files\n", (scalar @domain_lists);
|
||||||
printf STDERR " - %d .hosts files\n", (scalar @hosts_lists);
|
printf STDERR " - %d .hosts files\n", (scalar @hosts_lists);
|
||||||
printf STDERR "(%d duplicates)\n", $dupes if $dupes;
|
printf STDERR "(%d duplicates)\n", $dupes if $dupes;
|
||||||
|
|
26
update.sh
26
update.sh
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# vi: et sts=4 sw=4 ts=4
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# You Don't Need Pi-hole
|
# You Don't Need Pi-hole
|
||||||
|
@ -14,20 +13,17 @@
|
||||||
# You may NOT use this software for commercial purposes.
|
# You may NOT use this software for commercial purposes.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
WORKDIR=${0%/*}
|
WORKDIR=${0%/*}
|
||||||
CFG=$WORKDIR/update.cfg
|
CFG=$WORKDIR/update.cfg
|
||||||
|
|
||||||
# Config defaults
|
# Config defaults
|
||||||
BACKUPSUFFIX=
|
BACKUPSUFFIX=
|
||||||
BLOCKLIST=$WORKDIR/block.list
|
BLOCKLIST=$WORKDIR/block.list
|
||||||
LIST_DIR=$WORKDIR/lists
|
|
||||||
OUT=()
|
OUT=()
|
||||||
URL=()
|
URL=()
|
||||||
DNSMASQ_RESTART_COMMAND=()
|
DNSMASQ_RESTART_COMMAND=()
|
||||||
if [[ -f $CFG ]]; then
|
if [[ -f $CFG ]]; then
|
||||||
. "$CFG"
|
. "$CFG" || exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEMP_DIR=$(mktemp -d -t "${0##*/}.XXXXXX")
|
TEMP_DIR=$(mktemp -d -t "${0##*/}.XXXXXX")
|
||||||
|
@ -38,9 +34,9 @@ trap 'cleanup' EXIT
|
||||||
|
|
||||||
copy_perms() {
|
copy_perms() {
|
||||||
local -r FROM=$1 TO=$2
|
local -r FROM=$1 TO=$2
|
||||||
chmod --reference="$FROM" -- "$TO"
|
chmod --reference="$FROM" -- "$TO" || exit
|
||||||
if [[ $UID -eq 0 ]]; then
|
if [[ $UID -eq 0 ]]; then
|
||||||
chown --reference="$FROM" -- "$TO"
|
chown --reference="$FROM" -- "$TO" || exit
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,12 +47,12 @@ replace_with() {
|
||||||
if [[ -f $ORIG ]]; then
|
if [[ -f $ORIG ]]; then
|
||||||
copy_perms "$ORIG" "$NEW"
|
copy_perms "$ORIG" "$NEW"
|
||||||
if [[ -n $BACKUPSUFFIX ]]; then
|
if [[ -n $BACKUPSUFFIX ]]; then
|
||||||
mv -- "$ORIG" "$ORIG$BACKUPSUFFIX"
|
mv -- "$ORIG" "$ORIG$BACKUPSUFFIX" || exit
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
mkdir -p -- "${ORIG%/*}"
|
mkdir -p -- "${ORIG%/*}" || exit
|
||||||
fi
|
fi
|
||||||
mv -- "$NEW" "$ORIG"
|
mv -- "$NEW" "$ORIG" || exit
|
||||||
else
|
else
|
||||||
printf 'File "%s" not modified\n' \
|
printf 'File "%s" not modified\n' \
|
||||||
"$ORIG" \
|
"$ORIG" \
|
||||||
|
@ -67,7 +63,7 @@ replace_with() {
|
||||||
(cd "$WORKDIR" &&
|
(cd "$WORKDIR" &&
|
||||||
git submodule update --init 'repos-noupdates/*' &&
|
git submodule update --init 'repos-noupdates/*' &&
|
||||||
git submodule update --init --remote 'repos/*'
|
git submodule update --init --remote 'repos/*'
|
||||||
)
|
) || exit
|
||||||
|
|
||||||
for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
|
for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
|
||||||
MY_URL=${URL[$I]}
|
MY_URL=${URL[$I]}
|
||||||
|
@ -85,13 +81,13 @@ for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
|
||||||
|
|
||||||
wget \
|
wget \
|
||||||
-O "$TEMP_OUT" \
|
-O "$TEMP_OUT" \
|
||||||
"$MY_URL"
|
"$MY_URL" || exit
|
||||||
|
|
||||||
replace_with "$MY_OUT" "$TEMP_OUT"
|
replace_with "$MY_OUT" "$TEMP_OUT"
|
||||||
done
|
done
|
||||||
|
|
||||||
TEMP_BLOCKLIST=$(mktemp -p "$TEMP_DIR")
|
TEMP_BLOCKLIST=$(mktemp -p "$TEMP_DIR")
|
||||||
"$WORKDIR/make-block.pl" --out="$TEMP_BLOCKLIST"
|
"$WORKDIR/make-block.pl" --out="$TEMP_BLOCKLIST" || exit
|
||||||
|
|
||||||
# Blocklist generation succeeded, install it!
|
# Blocklist generation succeeded, install it!
|
||||||
|
|
||||||
|
@ -103,11 +99,11 @@ if [[ ! -e $BLOCKLIST ]]; then
|
||||||
# whatever file permissions 'mktemp' sets.
|
# whatever file permissions 'mktemp' sets.
|
||||||
umask 0022
|
umask 0022
|
||||||
touch -- "$BLOCKLIST"
|
touch -- "$BLOCKLIST"
|
||||||
)
|
) || exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
replace_with "$BLOCKLIST" "$TEMP_BLOCKLIST"
|
replace_with "$BLOCKLIST" "$TEMP_BLOCKLIST"
|
||||||
|
|
||||||
if [[ ${#DNSMASQ_RESTART_COMMAND[@]} -gt 0 ]]; then
|
if [[ ${#DNSMASQ_RESTART_COMMAND[@]} -gt 0 ]]; then
|
||||||
"${DNSMASQ_RESTART_COMMAND[@]}"
|
"${DNSMASQ_RESTART_COMMAND[@]}" || exit
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue