From ccc722b7ed330198d82a3cf28ead76d6d107a70a Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 6 Jun 2022 21:25:48 +0000 Subject: added java --- repo/unbound/migrate-dnscache-to-unbound | 147 +++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 repo/unbound/migrate-dnscache-to-unbound (limited to 'repo/unbound/migrate-dnscache-to-unbound') diff --git a/repo/unbound/migrate-dnscache-to-unbound b/repo/unbound/migrate-dnscache-to-unbound new file mode 100644 index 0000000..03b34cd --- /dev/null +++ b/repo/unbound/migrate-dnscache-to-unbound @@ -0,0 +1,147 @@ +#!/bin/sh + + +to_subnet() { + pref=$1 + case "$pref" in + *.*.*.*) echo $pref/32;; + *.*.*) echo $pref.0/24;; + *.*) echo $pref.0.0/16;; + *) echo $pref.0.0.0/8;; + esac +} + +gen_config() { + echo "# Config generated by $0, $(date)" + echo "server:" + + [ -n "$IP" ] && echo -e "\tinterface: $IP\n" + [ -n "$IPSEND" ] && echo -e "\toutgoing-interface: $IPSEND\n" + + for i in $access_control; do + echo -e "\taccess-control: $i allow" + done + echo "" + + # stub zones + local zonefile ip + local fwdtype="stub" + if [ -n "$FORWARDONLY" ]; then + fwdtype="forward" + fi + for zonefile in "$root"/etc/dnscache/servers/*; do + local zone=${zonefile##*/} + case "$zone" in + '@'|'*'|*.apk-new) continue;; + esac + echo "${fwdtype}-zone:" + echo -e "\tname: ${zone}" + for ip in $(cat $zonefile); do + echo -e "\t${fwdtype}-addr: $ip" + done + echo "" + done +} + +usage() { + cat >&2 <&2 + mv "$unbound_conf" "${unbound_conf}".backup +fi + +$quiet || echo "Generating $unbound_conf" >&2 +gen_config > "$unbound_conf" + +# stop dnscache and start unbound +if /etc/init.d/dnscache --quiet status 2>/dev/null; then + /etc/init.d/dnscache $quiet_opt stop + if ! /etc/init.d/unbound $quiet_opt start; then + echo "Failed to start unbound. Starting up dnscache again" + /etc/init.d/dnscache $quiet_opt start + exit 1 + fi +fi + +# update runlevels +errors=0 +if rc-update | grep -q -w dnscache; then + runlevels=$(rc-update | awk '$1 == "dnscache" { FS="|"; $0 = $0; print $2 }') + for level in $runlevels; do + rc-update $quiet_opt add unbound $level \ + || errors=$(($errors + 1)) + rc-update $quiet_opt del dnscache $level \ + || errors=$(($errors + 1)) + done +fi + +# cleanup if requested +if [ $errors -eq 0 ] && ! $keep_backup ; then + $quiet || echo "Purging dnscache and dnscache config" >&2 + apk del --purge $quiet_opt dnscache + rm -rf $root/etc/dnscache $root/etc/conf.d/dnscache + $quiet || echo "Purging ${unbound_conf}.backup" >&2 + rm -rf ${unbound_conf}.backup +fi + +exit $errors -- cgit v1.2.1