mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 07:28:39 +01:00
cache-domains: Fixed upstream changes + wolfssl
* The upstream script changed to use `.hosts` files from `.conf` files, so changes were required to make dnsmasq use the new file format. * Added a default wolfssl variant. Signed-off-by: Gerard Ryan <G.M0N3Y.2503@gmail.com>
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/config/uci.sh
|
||||
|
||||
set -e
|
||||
|
||||
CACHE_DOMAINS_DIR="/var/cache-domains"
|
||||
CACHE_DOMAINS_SRC="https://api.github.com/repos/uklans/cache-domains/tarball/master"
|
||||
CACHE_DOMAINS_DIR="/var/cache-domains"
|
||||
CACHE_DOMAINS_HOSTS_DIR="${CACHE_DOMAINS_DIR}/scripts/output/dnsmasq"
|
||||
CONFIG_FILE="/etc/cache-domains.json"
|
||||
|
||||
uci_changes() {
|
||||
local PACKAGE="$1"
|
||||
local STATE="$2"
|
||||
|
||||
CHANGES=$(/sbin/uci ${UCI_CONFIG_DIR:+-c ${UCI_CONFIG_DIR}} ${STATE:+-P ${STATE}} -q changes "${PACKAGE}" | wc -l)
|
||||
return "${CHANGES}"
|
||||
}
|
||||
|
||||
configure() {
|
||||
local INITIAL_DIR
|
||||
local I=0
|
||||
|
||||
mkdir -p "${CACHE_DOMAINS_DIR}"
|
||||
rm -fr "${CACHE_DOMAINS_DIR:?}/"*
|
||||
|
||||
@@ -16,30 +30,53 @@ configure() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INITIAL_DIR="$(pwd)"
|
||||
cd "${CACHE_DOMAINS_DIR}/"*"/scripts/"
|
||||
# move files out of versioned directory
|
||||
mv "${CACHE_DOMAINS_DIR}/"*"/"* "${CACHE_DOMAINS_DIR}/"
|
||||
|
||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||
cp "config.example.json" "${CONFIG_FILE}"
|
||||
cp "${CACHE_DOMAINS_DIR}/scripts/config.example.json" "${CONFIG_FILE}"
|
||||
echo "Using example config file ${CONFIG_FILE}"
|
||||
fi
|
||||
|
||||
INITIAL_DIR="$(pwd)"
|
||||
cd "${CACHE_DOMAINS_DIR}/scripts/"
|
||||
cp "${CONFIG_FILE}" "config.json"
|
||||
./create-dnsmasq.sh
|
||||
cp "./output/dnsmasq/"* "/var/dnsmasq.d/"
|
||||
|
||||
rm "config.json" "${CACHE_DOMAINS_HOSTS_DIR}/lancache.conf"
|
||||
cd "${INITIAL_DIR}"
|
||||
|
||||
/etc/init.d/dnsmasq restart
|
||||
while uci_get "dhcp" "@dnsmasq[${I}]" > /dev/null; do
|
||||
if uci_changes "dhcp"; then
|
||||
uci_remove_list "dhcp" "@dnsmasq[${I}]" "addnhosts" "${CACHE_DOMAINS_HOSTS_DIR}"
|
||||
uci_add_list "dhcp" "@dnsmasq[${I}]" "addnhosts" "${CACHE_DOMAINS_HOSTS_DIR}"
|
||||
uci_commit "dhcp"
|
||||
else
|
||||
echo "ERROR: Unexpected changes in the dhcp configuration, commit changes and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
I=$((${I} + 1))
|
||||
done
|
||||
|
||||
/etc/init.d/dnsmasq "restart"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
# leave dnsmasq in a clean state
|
||||
for FILE in "${CACHE_DOMAINS_DIR}/"*"/scripts/output/dnsmasq/"*; do
|
||||
rm -f "/tmp/dnsmasq.d/$(basename "${FILE}")"
|
||||
local I=0
|
||||
|
||||
while uci_get "dhcp" "@dnsmasq[${I}]" > /dev/null; do
|
||||
if uci_changes "dhcp"; then
|
||||
uci_remove_list "dhcp" "@dnsmasq[${I}]" "addnhosts" "${CACHE_DOMAINS_HOSTS_DIR}"
|
||||
uci_commit "dhcp"
|
||||
else
|
||||
echo "ERROR: Unexpected changes in the dhcp configuration, commit changes and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
I=$((${I} + 1))
|
||||
done
|
||||
|
||||
/etc/init.d/dnsmasq restart
|
||||
/etc/init.d/dnsmasq "restart"
|
||||
}
|
||||
|
||||
case ${1} in
|
||||
|
||||
Reference in New Issue
Block a user