X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=trusted-network;h=1b0ee8d8f39f97bcca562b3029fd8bc1b86e3eef;hb=ce4cacd36c5b5babeea85d0f93771017e6169180;hp=3f5154162d9f94530210764441988eab0f977530;hpb=b28eebdf9143aa17733f233b30b96f462008f3b6;p=distro-setup diff --git a/trusted-network b/trusted-network index 3f51541..1b0ee8d 100755 --- a/trusted-network +++ b/trusted-network @@ -1,22 +1,86 @@ -#!/bin/bash -l +#!/bin/bash + +# Usage: run to trust or untrust dns. public wifi sometimes needs to +# trust dns initially to log in. -set -eE -o pipefail -trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" -# Usage: run when switching from an untrusted network like public wifi -# to a trusted one. +source /a/bin/errhandle/err + +readonly this_file=$(readlink -f -- "${BASH_SOURCE[0]}") +readonly this_dir="${this_file%/*}" +script_name="${BASH_SOURCE[0]}" +script_name="${script_name##*/}" + +# removes malware and adult content +servers=(1.1.1.3 1.0.0.3 2606:4700:4700::1113 2606:4700:4700::1003) + +servers=(1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001) + +## trying out google +servers=(8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844) + + + +m() { printf "%s\n" "$*"; "$@"; } +e() { printf "%s\n" "$@"; } +i() { # install file + local tmp tmpdir dest="$1" + local base="${dest##*/}" + mkdir -p ${dest%/*} + ir=false # i result + tmpdir=$(mktemp -d) + cat >$tmpdir/"$base" + tmp=$(rsync -ic $tmpdir/"$base" "$dest") + if [[ $tmp ]]; then + printf "%s\n" "$tmp" + ir=true + fi + rm -rf $tmpdir +} + +e $script_name +exit 0 + +# i symlinked the script to another name to make it work different +trust=true +case $script_name in + untrusted-network) + trust=false + ;; +esac + -if [[ -e /etc/NetworkManager/conf.d/dns.conf ]]; then - rm -fv /etc/NetworkManager/conf.d/dns.conf - if [[ $(systemctl is-active NetworkManager) == active ]]; then +if $trust; then + if [[ -e /etc/NetworkManager/conf.d/dns.conf ]]; then + rm -fv /etc/NetworkManager/conf.d/dns.conf + if [[ $(systemctl is-active NetworkManager) == active ]]; then + m systemctl restart NetworkManager + fi + fi + + rm -fv /etc/systemd/resolved.conf.d/untrusted-network.conf +else #untrusted + # https://wiki.archlinux.org/index.php/Systemd-resolved#Manually + cat >/etc/systemd/resolved.conf.d/untrusted-network.conf <