aboutsummaryrefslogtreecommitdiff
path: root/external/unbound/contrib/unbound_cache.sh
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2014-10-06 08:51:44 +0200
committerRiccardo Spagni <ric@spagni.net>2014-10-06 08:52:16 +0200
commit3463f0ab52a84b79977c3e67177637e62265c89c (patch)
tree1e2077aa15fa18fcc9b00fa23c9514d46df6ef95 /external/unbound/contrib/unbound_cache.sh
parentfix for miniupnpc static compile under Windows (diff)
parentadded aabramov's gpg key (diff)
downloadmonero-3463f0ab52a84b79977c3e67177637e62265c89c.tar.xz
Merge pull request #171
32be6ae added aabramov's gpg key (Riccardo Spagni) 010bfcf minor English wordlist tweaks (Riccardo Spagni) 9ef094b added unbound to external deps (Riccardo Spagni) 732493c split mnemonic printout over 3 lines (Riccardo Spagni)
Diffstat (limited to 'external/unbound/contrib/unbound_cache.sh')
-rw-r--r--external/unbound/contrib/unbound_cache.sh135
1 files changed, 135 insertions, 0 deletions
diff --git a/external/unbound/contrib/unbound_cache.sh b/external/unbound/contrib/unbound_cache.sh
new file mode 100644
index 000000000..c3dd9c3a2
--- /dev/null
+++ b/external/unbound/contrib/unbound_cache.sh
@@ -0,0 +1,135 @@
+#!/sbin/sh
+#
+# --------------------------------------------------------------
+# -- DNS cache save/load script
+# --
+# -- Version 1.0
+# -- By Yuri Voinov (c) 2006, 2014
+# --------------------------------------------------------------
+#
+# ident "@(#)unbound_cache.sh 1.1 14/04/26 YV"
+#
+
+#############
+# Variables #
+#############
+
+# Installation base dir
+CONF="/etc/opt/csw/unbound"
+BASE="/opt/csw"
+
+# Unbound binaries
+UC="$BASE/sbin/unbound-control"
+FNAME="unbound_cache.dmp"
+
+# OS utilities
+BASENAME=`which basename`
+CAT=`which cat`
+CUT=`which cut`
+ECHO=`which echo`
+GETOPT=`which getopt`
+ID=`which id`
+PRINTF=`which printf`
+
+###############
+# Subroutines #
+###############
+
+usage_note ()
+{
+# Script usage note
+ $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h]"
+ $ECHO
+ $ECHO "l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value."
+ $ECHO "s - Save - save Unbound DNS cache contents to plain file with domain names."
+ $ECHO "r - Reload - reloadind new cache entries and refresh existing cache"
+ $ECHO "h - this screen."
+ $ECHO "Note: Run without any arguments will be in default mode."
+ $ECHO " Also, unbound-control must be configured."
+ exit 0
+}
+
+root_check ()
+{
+ if [ ! `$ID | $CUT -f1 -d" "` = "uid=0(root)" ]; then
+ $ECHO "ERROR: You must be super-user to run this script."
+ exit 1
+ fi
+}
+
+check_uc ()
+{
+ if [ ! -f "$UC" ]; then
+ $ECHO .
+ $ECHO "ERROR: $UC not found. Exiting..."
+ exit 1
+ fi
+}
+
+check_saved_file ()
+{
+ if [ ! -f "$CONF/$FNAME" ]; then
+ $ECHO .
+ $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first."
+ exit 1
+ fi
+}
+
+save_cache ()
+{
+ # Save unbound cache
+ $PRINTF "Saving cache in $CONF/$FNAME..."
+ $UC dump_cache>$CONF/$FNAME
+ $ECHO "ok"
+}
+
+load_cache ()
+{
+ # Load saved cache contents and warmup DNS cache
+ $PRINTF "Loading cache from saved $CONF/$FNAME..."
+ check_saved_file
+ $CAT $CONF/$FNAME|$UC load_cache
+}
+
+reload_cache ()
+{
+ # Reloading and refresh existing cache and saved dump
+ save_cache
+ load_cache
+}
+
+##############
+# Main block #
+##############
+
+# Root check
+root_check
+
+# Check unbound-control
+check_uc
+
+# Check command-line arguments
+if [ "x$1" = "x" ]; then
+# If arguments list empty, load cache by default
+ load_cache
+else
+ arg_list=$1
+ # Parse command line
+ set -- `$GETOPT sSlLrRhH: $arg_list` || {
+ usage_note 1>&2
+ }
+
+ # Read arguments
+ for i in $arg_list
+ do
+ case $i in
+ -s | -S) save_cache;;
+ -l | -L) load_cache;;
+ -r | -R) reload_cache;;
+ -h | -H | \?) usage_note;;
+ esac
+ break
+ done
+fi
+
+exit 0 \ No newline at end of file