packages/utils/cache-domains/files/cache-domains
Gerard Ryan 124deec9ae cache-domains: Changed to hotplug script
Since we have to restart dnsmasq to reload the config anyway, this
package doesn't need to run before anything. We do however need to
wait for the network so I've changed this service to be a hotplug
script and utility script.

Signed-off-by: Gerard Ryan <G.M0N3Y.2503@gmail.com>
2019-12-02 19:16:42 +10:00

52 lines
1 KiB
Bash

#!/bin/sh
CACHE_DOMAINS_DIR="/var/cache-domains"
CACHE_DOMAINS_SRC="https://api.github.com/repos/uklans/cache-domains/tarball/master"
CONFIG_FILE="/etc/cache-domains.json"
configure() {
mkdir -p ${CACHE_DOMAINS_DIR}
rm -fr ${CACHE_DOMAINS_DIR}/*
if ! wget -qO - ${CACHE_DOMAINS_SRC} | tar -xzC ${CACHE_DOMAINS_DIR}; then
echo "ERROR: Could not retrieve ${CACHE_DOMAINS_SRC}"
return 1
fi
INITIAL_DIR="$(pwd)"
cd ${CACHE_DOMAINS_DIR}/*/scripts/
if [ ! -f ${CONFIG_FILE} ]; then
cp config.example.json ${CONFIG_FILE}
echo "Using example config file ${CONFIG_FILE}"
fi
cp ${CONFIG_FILE} config.json
./create-dnsmasq.sh
cp ./output/dnsmasq/* /var/dnsmasq.d/
cd ${INITIAL_DIR}
/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})
done
/etc/init.d/dnsmasq restart
}
case ${1} in
config*)
configure
;;
clean*)
cleanup
;;
*)
echo "${0} <configure|cleanup>"
;;
esac