dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 15fe4e6481384253dc5cc7906c84a80a1ac123e8
parent 3e1ea9a40a0faa7c6c3e1fa7fac70143536d372a
Author: hhvn <dev@hhvn.uk>
Date:   Tue, 19 Apr 2022 17:19:39 +0100

Add new wlan scripts to replace autowifi

Diffstat:
A.scripts/net/addwpa | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.scripts/net/autowifi | 56--------------------------------------------------------
A.scripts/net/scan | 25+++++++++++++++++++++++++
3 files changed, 87 insertions(+), 56 deletions(-)

diff --git a/.scripts/net/addwpa b/.scripts/net/addwpa @@ -0,0 +1,62 @@ +#!/bin/rc + +cfile = /etc/wpa_supplicant/wpa_supplicant.conf +efile = /tmp/$pid.errors + +fn sigexit { + if (!~ $havex11 1) { + stty echo + } + if (test -f $efile) { + rm -f $efile + } +} + +if (!~ $DISPLAY ()) { + havex11 = 1 +} else { + havex11 = 0 +} + +if (!~ `{id -u} 0) { + if (~ $havex11 1) { + echo Accept | dmenu -p 'Give me root, not this stupid ' ^ `{whoami} ^ ' user!' >/dev/null + } else { + printf 'Give me root, not this stupid %s user!\n' `{whoami} >[1=2] + } + exit 1 +} + +echo Scanning for SSIDs... +networks = `{net/scan} +if (~ $havex11 1) { + choices = `{echo $networks | tr ' ' '\n' | dmenu -i -p 'SSID:'} +} else { + echo $^networks + printf 'SSID: ' + choices = `{head -n 1} +} + +for (ssid in $choices) { + if (~ $havex11 1) { + pass = `$nl{dmenu -i -p $ssid ^ ' password:' </dev/null} + } else { + stty -echo + printf '%s password: ' $ssid + pass = `$nl{head -n 1} + printf '\n' + stty echo + } + conf = `''{wpa_passphrase $ssid $pass >[2]$efile} + if (!~ $bqstatus 0) { + if (~ $havex11 1) { + echo Accept | dmenu -p `''{cat $efile} >/dev/null + } else { + cat $efile >[1=2] + } + exit 1 + } + printf '%s' $conf | grep -v '#psk' >[1=2] + echo Writing to $cfile + printf '%s' $conf >> $cfile +} diff --git a/.scripts/net/autowifi b/.scripts/net/autowifi @@ -1,56 +0,0 @@ -#!/bin/sh -# -# autowifi.sh -# Created by Hayden Hamilton -# -# hayden@haydenvh.com -# Copyright (c) 2020 Hayden Hamilton -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# This work is free. You can redistribute it and/or modify it under the -# terms of the Do What The Fuck You Want To Public License, Version 2, -# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. -# -# depends: inetutils-ifconfig, wireless_tools, wpa_supplicant, dhclient - -[ $(id | sed -E 's~uid=([0-9]*).*~\1~') -eq 0 ] && super="" || { - command -v doas >/dev/null && super=doas || super=sudo -} - -# guess the wireless interface -[ -z $1 ] && { - interface=$(ip a | grep -o '^[0-9]*: w[^:]*:' | sed -E 's/[0-9]*: ([^:]*):/\1/' | head -n 1) - echo "$interface" | grep '[[:alnum:]]' >/dev/null || { - echo "Couldn't guess the interface, please provide one as argument 1" - exit 1 - } -} || interface="$1" - -$super ifconfig $interface up - -ssid=$($super iwlist $interface scan 2>&1 | grep SSID | sed -E 's/.*:"([^"]*)"/\1/' | dmenu -i) -pass=$(printf '' | dmenu -i -p "Passphrase:") - -wpa_passphrase "$ssid" "$pass" > /tmp/"$ssid".wpa.conf -$super wpa_supplicant -B -i $interface -c /tmp/"$ssid".wpa.conf -$super dhclient - -sleep 2 -tput setaf 10 -echo "...testing..." -sleep 7 -tput sgr0 -ping -I $interface -c 5 example.com 2>&1 | tee /dev/stderr | grep '[^0] received,' >/dev/null && { - tput setaf 10 - echo "Yup" -} || { - tput setaf 10 - echo "Something broke.. :(" -} diff --git a/.scripts/net/scan b/.scripts/net/scan @@ -0,0 +1,25 @@ +#!/bin/rc + +if (!~ `{id -u} 0) { + printf 'Give me root, not this stupid %s user!\n' `{whoami} >[1=2] + exit 1 +} + +interfaces = `$nl{ip a | awk '/^[0-9]/ {gsub(/:/, ""); print $2}'} +wireless = () +networks = () + +for (i in $interfaces) { + if (~ $i wl*) { + wireless = ($wireless $i) + } +} + +for (i in $wireless) { + networks = ($networks `$nl{iwlist $i scan | + awk '$1 ~ /^ESSID:".+"/ { + sub(/[^"]*"/, ""); sub(/"$/, ""); print + }' < f | sort -u}) +} + +echo $^networks