]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/contrib/unbound_cache.sh
c3dd9c3a2df939ec3ca8f111fe95681212f85084
3 # --------------------------------------------------------------
4 # -- DNS cache save/load script
7 # -- By Yuri Voinov (c) 2006, 2014
8 # --------------------------------------------------------------
10 # ident "@(#)unbound_cache.sh 1.1 14/04/26 YV"
17 # Installation base dir
18 CONF
="/etc/opt/csw/unbound"
22 UC
="$BASE/sbin/unbound-control"
23 FNAME
="unbound_cache.dmp"
26 BASENAME
=`which basename`
41 $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h]"
43 $ECHO "l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value."
44 $ECHO "s - Save - save Unbound DNS cache contents to plain file with domain names."
45 $ECHO "r - Reload - reloadind new cache entries and refresh existing cache"
46 $ECHO "h - this screen."
47 $ECHO "Note: Run without any arguments will be in default mode."
48 $ECHO " Also, unbound-control must be configured."
54 if [ ! `$ID | $CUT -f1 -d" "` = "uid=0(root)" ]; then
55 $ECHO "ERROR: You must be super-user to run this script."
62 if [ ! -f "$UC" ]; then
64 $ECHO "ERROR: $UC not found. Exiting..."
71 if [ ! -f "$CONF/$FNAME" ]; then
73 $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first."
81 $PRINTF "Saving cache in $CONF/$FNAME..."
82 $UC dump_cache
>$CONF/$FNAME
88 # Load saved cache contents and warmup DNS cache
89 $PRINTF "Loading cache from saved $CONF/$FNAME..."
91 $CAT $CONF/$FNAME|$UC load_cache
96 # Reloading and refresh existing cache and saved dump
108 # Check unbound-control
111 # Check command-line arguments
112 if [ "x$1" = "x" ]; then
113 # If arguments list empty, load cache by default
118 set -- `$GETOPT sSlLrRhH: $arg_list` || {
126 -s | -S) save_cache
;;
127 -l | -L) load_cache
;;
128 -r | -R) reload_cache
;;
129 -h | -H | \?) usage_note
;;