Add resolv toggling script
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 20 Mar 2020 19:21:02 +0000 (15:21 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 20 Mar 2020 19:21:02 +0000 (15:21 -0400)
home/bin/resolv [new file with mode: 0755]

diff --git a/home/bin/resolv b/home/bin/resolv
new file mode 100755 (executable)
index 0000000..0b12139
--- /dev/null
@@ -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
This page took 0.042394 seconds and 4 git commands to generate.