From: Siraaj Khandkar Date: Fri, 20 Mar 2020 19:21:02 +0000 (-0400) Subject: Add resolv toggling script X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=0152c91e1ea7751d91d078682c47d14ef2724b4f;p=khome.git Add resolv toggling script --- diff --git a/home/bin/resolv b/home/bin/resolv new file mode 100755 index 0000000..0b12139 --- /dev/null +++ b/home/bin/resolv @@ -0,0 +1,40 @@ +#! /bin/sh + +FILE='/etc/resolv.conf' +CONTENT=\ +'nameserver 167.206.13.180 +nameserver 167.206.13.181 +nameserver 192.168.1.1' + +uncommented() { + echo "$CONTENT" +} + +commented() { + for line in "$CONTENT" + do + echo "$line" | sed 's/^/#/' + done +} + +switch_on() { + chattr -i "$FILE" # Make mutable + rm -f "$FILE" + uncommented > "$FILE" + chmod a+r "$FILE" +} + +switch_off() { + rm -f "$FILE" + commented > "$FILE" + chmod a-rw "$FILE" + chattr +i "$FILE" # Make immutable +} + +case "$1" in + 'on' ) switch_on;; + 'off') switch_off;; + '') + echo "usage: $0 SWITCH\n\nSWITCH = on | off" + exit 1;; +esac