~hokiegeek/bin

83cf299aef2ad8a4fff2b6da8127b2f9144aa39e — HokieGeek 3 months ago a811711
so much goodness
7 files changed, 112 insertions(+), 1 deletions(-)

A bwvpn
M dns-test
A mkiso
A stim
M toggle-screens
A tor
M update-mirrorlist
A bwvpn => bwvpn +31 -0
@@ 0,0 1,31 @@
#!/bin/sh
vpncfg=$2

if [[ "$1" == "stop" ]]; then
    openvpn3 sessions-list | awk 'BEGIN{ FS=":" } $1 ~ /Path/ { p=$2 } $1 ~ /Config name/ && $2 = "'${vpncfg}'" { print p }' | while read p; do
        echo -n "$p\n\t"
        openvpn3 session-manage --disconnect --path $p
    done
elif [[ "$1" == "start" ]]; then
    bwsession=$(bw unlock | awk -F= '$1 ~ /export BW_SESSION/ { gsub(/"/, "", $2); print $2 }')
    item=vpn.sonatype.dev
    expect <<-EOF
    spawn openvpn3 session-start --config ${vpncfg}

    set timeout 60

    expect "Auth User name:"
    send -- "$(bw --session ${bwsession} get username ${item})\r"

    expect "Auth Password:"
    send -- "$(bw --session ${bwsession} get password ${item})\r"

    expect "Enter Authenticator Code:"
    send -- "$(bw --session ${bwsession} get totp ${item})\r"

    expect eof

EOF
else
    echo "just start or stop, dude"
fi

M dns-test => dns-test +6 -0
@@ 16,6 16,9 @@ dnsTest() {

cloudFlare=$(dnsTest 1.1.1.1 ${name})
google=$(dnsTest 8.8.8.8 ${name})
quad9=$(dnsTest 9.9.9.9 ${name})
quad9unf=$(dnsTest 9.9.9.10 ${name})
opennicva=$(dnsTest 147.135.113.37 ${name})
localNoCache=$(dnsTest 10.10.10.10 ${name} NS)
localCached=$(dnsTest 10.10.10.10 ${name})



@@ 23,6 26,9 @@ localCached=$(dnsTest 10.10.10.10 ${name})
    echo "DNS Time"
    echo "CloudFlare ${cloudFlare}"
    echo "Google ${google}"
    echo "Quad9 ${quad9}"
    echo "Quad9 (unfiltered) ${quad9unf}"
    echo "OpenNIC (ns1.va.us) ${opennicva}"
    echo "LocalNoCache ${localNoCache}"
    echo "LocalCached ${localCached}"
#} | column

A mkiso => mkiso +13 -0
@@ 0,0 1,13 @@
#!/bin/sh

name=$1
dev=${2:-/dev/sr0}

isosize -x ${dev} |\
    awk 'BEGIN { FS=":"; RS="," }
         /count/ { cnt=$2 }
         /size/ { sz=$2 }
         END {
            printf "dd if='${dev}' of='${name}'.iso bs=%d count=%d status=progress && sync", sz, cnt | "/bin/sh"
         }'


A stim => stim +2 -0
@@ 0,0 1,2 @@
#!/bin/sh
/usr/bin/cpupower frequency-set -g performance

M toggle-screens => toggle-screens +7 -0
@@ 12,10 12,17 @@ xrandr |& awk '$1 ~ /'${screen}'/ && $3 != "primary" && $2 ~ /connected$/' | \
            xrandr --auto --output ${screen} --off
        elif [[ ${status} == "connected" && ! ${resolution} =~ $re ]]; then
            echo "Toggling on: ${screen}"
            #xrandr --output ${screen} --auto --${position}-of ${primary}
            xrandr --auto --output ${screen} --auto --${position}-of ${primary}
        fi
    done


#udevadm info -q all -a /sys/class/drm/card0-DP-1
#KERNEL=="card0-DP-1", SUBSYSTEM=="drm", ATTR{status}=="connected" RUN+="/usr/bin/xrandr --auto --output DP1 --auto left-of LVDS1"
#KERNEL=="card0-DP-1", SUBSYSTEM=="drm", ATTR{status}=="disconnected" RUN+="/usr/bin/xrandr --auto --output DP1 --off"
#KERNEL=="card0-VGA-1", SUBSYSTEM=="drm", RUN+="/usr/bin/xrandr --auto --output VGA1 --auto right-of LVDS1"
# card0-DP-1 == DP1
# RULE: SUBSYSTEM=="drm", DEVNAME=="/dev/dri/card0", ACTION=="change", RUN+="blah"
# cat /sys/class/drm/card0-HDMI-A-1/status (connected | disconnected)


A tor => tor +52 -0
@@ 0,0 1,52 @@
#!/bin/bash

TORCHROOT=/opt/torchroot #$(mktemp --directory)
# cleanup() {
#     setsid kill -- -$(ps -o pgid= $$ | grep -o [0-9]*)
#     sudo rm -rf $TORCHROOT
# }
# trap 'cleanup' EXIT


### Setup and start tor
# startTor() {
    sudo mkdir -p $TORCHROOT
    sudo mkdir -p $TORCHROOT/etc/tor
    sudo mkdir -p $TORCHROOT/dev
    sudo mkdir -p $TORCHROOT/usr/bin
    sudo mkdir -p $TORCHROOT/usr/lib
    sudo mkdir -p $TORCHROOT/usr/share/tor
    sudo mkdir -p $TORCHROOT/var/lib

    sudo ln -s /usr/lib  $TORCHROOT/lib
    sudo cp /etc/hosts           $TORCHROOT/etc/
    sudo cp /etc/host.conf       $TORCHROOT/etc/
    sudo cp /etc/localtime       $TORCHROOT/etc/
    sudo cp /etc/nsswitch.conf   $TORCHROOT/etc/
    sudo cp /etc/resolv.conf     $TORCHROOT/etc/
    sudo cp /etc/tor/torrc       $TORCHROOT/etc/tor/

    sudo cp /usr/bin/tor         $TORCHROOT/usr/bin/
    sudo cp /usr/share/tor/geoip* $TORCHROOT/usr/share/tor/
    sudo cp /lib/libnss* /lib/libnsl* /lib/ld-linux-*.so* /lib/libresolv* /lib/libgcc_s.so* $TORCHROOT/usr/lib/
    sudo cp $(ldd /usr/bin/tor | awk '{print $3}'|grep --color=never "^/") $TORCHROOT/usr/lib/
    sudo cp -r /var/lib/tor      $TORCHROOT/var/lib/
    sudo chown -R tor:tor $TORCHROOT/var/lib/tor

    sudo sh -c "grep --color=never ^tor /etc/passwd > $TORCHROOT/etc/passwd"
    sudo sh -c "grep --color=never ^tor /etc/group > $TORCHROOT/etc/group"

    sudo mknod -m 644 $TORCHROOT/dev/random c 1 8
    sudo mknod -m 644 $TORCHROOT/dev/urandom c 1 9
    sudo mknod -m 666 $TORCHROOT/dev/null c 1 3

    if [[ "$(uname -m)" == "x86_64" ]]; then
        sudo cp /usr/lib/ld-linux-x86-64.so* $TORCHROOT/usr/lib/.
        sudo ln -sr /usr/lib64 $TORCHROOT/lib64
        sudo ln -s $TORCHROOT/usr/lib ${TORCHROOT}/usr/lib64
    fi

    sudo chroot --userspec=tor:tor ${TORCHROOT} /usr/bin/tor &
# }

# startTor

M update-mirrorlist => update-mirrorlist +1 -1
@@ 22,7 22,7 @@ sudo cp ${list} ${list}.bak
## Download the list ranked by status and
## process it by uncommenting the top 10 mirrors (with the best score)
tmplist=`mktemp`
curl "https://www.archlinux.org/mirrorlist/?country=US&protocol=http&ip_version=4&use_mirror_status=on" | \
curl -L 'https://www.archlinux.org/mirrorlist/?country=US&protocol=http&ip_version=4&use_mirror_status=on' | \
    sed '/##/d;/^$/d' | sed '1,12s/^#//' > ${tmplist}

## Rank the list by speed