From 0152c91e1ea7751d91d078682c47d14ef2724b4f Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 20 Mar 2020 15:21:02 -0400 Subject: [PATCH] Add resolv toggling script --- home/bin/resolv | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 home/bin/resolv 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 -- 2.20.1