From 21d8054894f3f7c8bed96752202fd2c2dfe5e049 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 22 Jun 2023 09:51:23 +0200 Subject: [PATCH] initial commit --- .gitignore | 4 ++++ PKGBUILD | 20 ++++++++++++++++++++ wifi-connect | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 PKGBUILD create mode 100755 wifi-connect diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..765efc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +.DS_Store +*.pkg.tar.zst +*.pkg.tar.zst.sig diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..cf3b3c2 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,20 @@ +# Maintainer: Sebastian Hugentobler + +pkgname=wifi-connect +pkgver=0.1.0 +pkgrel=1 +pkgdesc="Connect to a wifi network with nmcli, getting the password from pass." +arch=("any") +url="https://code.vanwa.ch" +license=('MIT') +depends=("networkmanager" "pass") +source=( + "wifi-connect" +) +sha256sums=("e6709ad775505b9485243d32f2e440a5cc0e96a875174cd8438024b4e0d5bcf2") + +package() { + cd "$srcdir/" + + install -Dm 755 wifi-connect "$pkgdir/usr/bin/wifi-connect" +} diff --git a/wifi-connect b/wifi-connect new file mode 100755 index 0000000..a791df8 --- /dev/null +++ b/wifi-connect @@ -0,0 +1,46 @@ +#!/usr/bin/env sh +set -o errexit +set -o nounset + +ssid="" + +display_help() { + echo "Usage: $0 [option...] " >&2 + echo + echo " -s, ssid of the wifi network, \"wifi/\$ssid\" is used as the path for pass." + echo " -h, display this help and exit" + echo +} + +parse_args() { + while getopts ":hs:" opt; do + case $opt in + h) + display_help + exit 0 + ;; + s) + ssid=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + display_help + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + display_help + exit 1 + ;; + esac + done +} + +parse_args "$@" + +echo "getting wifi password..." +pw="$(pass wifi/"$ssid")" + +nmcli device wifi list +nmcli con delete "$ssid" >/dev/null 2>&1 || true +nmcli device wifi connect "$ssid" password "$pw"