diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-04-02 11:16:18 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-04-02 11:16:18 +0200 |
commit | 1f49833d4fc449d54c95c3235b5c18523e6f8d69 (patch) | |
tree | ae027273609339b9b89e3e546552af7a7afb23e7 /external/unbound/contrib/unbound_cache.sh | |
parent | Merge pull request #248 (diff) | |
download | monero-1f49833d4fc449d54c95c3235b5c18523e6f8d69.tar.xz |
update unbound from upstream
Diffstat (limited to 'external/unbound/contrib/unbound_cache.sh')
-rw-r--r-- | external/unbound/contrib/unbound_cache.sh | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/external/unbound/contrib/unbound_cache.sh b/external/unbound/contrib/unbound_cache.sh index 238d90e39..b3e876ba9 100644 --- a/external/unbound/contrib/unbound_cache.sh +++ b/external/unbound/contrib/unbound_cache.sh @@ -1,13 +1,13 @@ #!/sbin/sh -# + # -------------------------------------------------------------- # -- DNS cache save/load script # -- -# -- Version 1.0 +# -- Version 1.2 # -- By Yuri Voinov (c) 2006, 2014 # -------------------------------------------------------------- # -# ident "@(#)unbound_cache.sh 1.1 14/04/26 YV" +# ident "@(#)unbound_cache.sh 1.2 14/10/30 YV" # ############# @@ -27,9 +27,10 @@ BASENAME=`which basename` CAT=`which cat` CUT=`which cut` ECHO=`which echo` +EXPR=`which expr` GETOPT=`which getopt` ID=`which id` -PRINTF=`which printf` +LS=`which ls` ############### # Subroutines # @@ -38,12 +39,13 @@ PRINTF=`which printf` usage_note () { # Script usage note - $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h]" - $ECHO + $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h] [filename]" + $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 "filename - file to save/load dumped cache. If not specified, $CONF/$FNAME will be used instead." $ECHO "Note: Run without any arguments will be in default mode." $ECHO " Also, unbound-control must be configured." exit 0 @@ -68,7 +70,12 @@ check_uc () check_saved_file () { - if [ ! -f "$CONF/$FNAME" ]; then + filename=$1 + if [ ! -z "$filename" -a ! -f "$filename" ]; then + $ECHO . + $ECHO "ERROR: File $filename does not exists. Save it first." + exit 1 + elif [ ! -f "$CONF/$FNAME" ]; then $ECHO . $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first." exit 1 @@ -78,24 +85,42 @@ check_saved_file () save_cache () { # Save unbound cache - $PRINTF "Saving cache in $CONF/$FNAME..." - $UC dump_cache>$CONF/$FNAME + filename=$1 + if [ -z "$filename" ]; then + $ECHO "Saving cache in $CONF/$FNAME..." + $UC dump_cache>$CONF/$FNAME + $LS -lh $CONF/$FNAME + else + $ECHO "Saving cache in $filename..." + $UC dump_cache>$filename + $LS -lh $filename + fi $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 + # Load saved cache contents and warmup cache + filename=$1 + if [ -z "$filename" ]; then + $ECHO "Loading cache from saved $CONF/$FNAME..." + $LS -lh $CONF/$FNAME + check_saved_file $filename + $CAT $CONF/$FNAME|$UC load_cache + else + $ECHO "Loading cache from saved $filename..." + $LS -lh $filename + check_saved_file $filename + $CAT $filename|$UC load_cache + fi } reload_cache () { # Reloading and refresh existing cache and saved dump - save_cache - load_cache + filename=$1 + save_cache $filename + load_cache $filename } ############## @@ -109,27 +134,41 @@ root_check check_uc # Check command-line arguments -if [ "x$1" = "x" ]; then -# If arguments list empty, load cache by default +if [ "x$*" = "x" ]; then + # If arguments list empty,load cache by default load_cache else - arg_list=$1 + arg_list=$* # Parse command line set -- `$GETOPT sSlLrRhH: $arg_list` || { usage_note 1>&2 } - # Read arguments + # Read arguments for i in $arg_list do case $i in - -s | -S) save_cache;; - -l | -L) load_cache;; - -r | -R) reload_cache;; + -s | -S) save="1";; + -l | -L) save="0";; + -r | -R) save="2";; -h | -H | \?) usage_note;; + *) shift + file=$1 + break;; esac - break + shift done + + # Remove trailing -- + shift `$EXPR $OPTIND - 1` +fi + +if [ "$save" = "1" ]; then + save_cache $file +elif [ "$save" = "0" ]; then + load_cache $file +elif [ "$save" = "2" ]; then + reload_cache $file fi -exit 0 +exit 0
\ No newline at end of file |