You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
971 B

  1. #!/bin/sh /etc/rc.common
  2. START=24
  3. SERVICE_NAME=cache-domains
  4. CACHE_DOMAINS_DIR="/var/${SERVICE_NAME}"
  5. CACHE_DOMAINS_SRC="https://api.github.com/repos/uklans/cache-domains/tarball/master"
  6. CONFIG_FILE="/etc/${SERVICE_NAME}.json"
  7. start() {
  8. mkdir -p ${CACHE_DOMAINS_DIR}
  9. rm -fr ${CACHE_DOMAINS_DIR}/*
  10. if ! wget -qO - ${CACHE_DOMAINS_SRC} | tar -xzC ${CACHE_DOMAINS_DIR}; then
  11. echo "ERROR: Could not retrieve ${CACHE_DOMAINS_SRC}"
  12. return 1
  13. fi
  14. INITIAL_DIR="$(pwd)"
  15. cd ${CACHE_DOMAINS_DIR}/*/scripts/
  16. if [ ! -f ${CONFIG_FILE} ]; then
  17. cp config.example.json ${CONFIG_FILE}
  18. echo "Using example config file ${CONFIG_FILE}"
  19. fi
  20. cp ${CONFIG_FILE} config.json
  21. ./create-dnsmasq.sh
  22. cp ./output/dnsmasq/* /tmp/dnsmasq.d/
  23. cd ${INITIAL_DIR}
  24. /etc/init.d/dnsmasq restart
  25. }
  26. stop() {
  27. # leave dnsmasq in a clean state
  28. for FILE in ${CACHE_DOMAINS_DIR}/*/scripts/output/dnsmasq/*; do
  29. rm -f /tmp/dnsmasq.d/$(basename ${FILE})
  30. done
  31. /etc/init.d/dnsmasq restart
  32. }