From 276445b8cea1f67b788dcfc599f68b2467d40c46 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Tue, 1 Jun 2021 23:50:12 -0400 Subject: [PATCH] Added networking scripts (i.e. vpn*); Updated style of most scripts --- Makefile | 20 ++++- README.md | 106 +++++++++++++++++++------- bash-completion/mybashcompletion.bash | 12 +-- src/android-emulator | 13 ++++ src/check-x | 3 + src/docker-clean | 17 +++++ src/docker-get-all | 14 ++++ src/docker-get-exited | 14 ++++ src/docker-restart | 14 ++++ src/docker-up | 14 ++++ src/fw-status | 14 ++++ src/pactl-get-running-sink | 13 ++++ src/pactl-mute | 13 ++++ src/pactl-volume-down | 13 ++++ src/pactl-volume-printf | 13 ++++ src/pactl-volume-up | 13 ++++ src/pingable | 23 ++++++ src/qemu-test | 35 +++++++++ src/start-at | 23 ++++++ src/tarls | 2 +- src/vimsplit | 0 src/vpn-off | 17 +++++ src/vpn-on | 17 +++++ src/wg-off | 14 ++++ src/wg-on | 14 ++++ src/wg-status | 14 ++++ src/wg-test | 32 ++++++++ src/zipls | 41 ++++++++++ 28 files changed, 505 insertions(+), 33 deletions(-) create mode 100755 src/pingable create mode 100755 src/qemu-test create mode 100755 src/start-at mode change 100644 => 100755 src/vimsplit create mode 100755 src/vpn-off create mode 100755 src/vpn-on create mode 100755 src/wg-test create mode 100755 src/zipls diff --git a/Makefile b/Makefile index 91713d2..3127054 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ install: clean install -m755 src/myparse.bash $(LIB_DIR)/myparse.bash install -m755 src/myminiparse.sh $(LIB_DIR)/myminiparse.sh install -m755 src/unittest-color.awk $(LIB_DIR)/unittest-color.awk + install -m755 src/android-emulator $(BIN_DIR)/android-emulator install -m755 src/check-x $(BIN_DIR)/check-x install -m755 src/ctdir $(BIN_DIR)/ctdir @@ -16,8 +17,8 @@ install: clean install -m755 src/docker-get-exited $(BIN_DIR)/docker-get-exited install -m755 src/docker-restart $(BIN_DIR)/docker-restart install -m755 src/docker-up $(BIN_DIR)/docker-up - install -m755 src/epub $(BIN_DIR)/epub install -m755 src/enumerate $(BIN_DIR)/enumerate + install -m755 src/epub $(BIN_DIR)/epub install -m755 src/fw-status $(BIN_DIR)/fw-status install -m755 src/mkbak $(BIN_DIR)/mkbak install -m755 src/mktar $(BIN_DIR)/mktar @@ -26,30 +27,39 @@ install: clean install -m755 src/pactl-volume-down $(BIN_DIR)/pactl-volume-down install -m755 src/pactl-volume-printf $(BIN_DIR)/pactl-volume-printf install -m755 src/pactl-volume-up $(BIN_DIR)/pactl-volume-up + install -m755 src/pingable $(BIN_DIR)/pingable + install -m755 src/qemu-test $(BIN_DIR)/qemu-test install -m755 src/rand $(BIN_DIR)/rand install -m755 src/rebom $(BIN_DIR)/rebom install -m755 src/rmtar $(BIN_DIR)/rmtar install -m755 src/rmzip $(BIN_DIR)/rmzip + install -m755 src/start-at $(BIN_DIR)/start-at + install -m755 src/stop-at $(BIN_DIR)/stop-at install -m755 src/tarcat $(BIN_DIR)/tarcat install -m755 src/tarls $(BIN_DIR)/tarls install -m755 src/unittest $(BIN_DIR)/unittest install -m755 src/untar $(BIN_DIR)/untar install -m755 src/vimsplit $(BIN_DIR)/vimsplit + install -m755 src/vpn-off $(BIN_DIR)/vpn-off + install -m755 src/vpn-on $(BIN_DIR)/vpn-on install -m755 src/wg-off $(BIN_DIR)/wg-off install -m755 src/wg-on $(BIN_DIR)/wg-on install -m755 src/wg-status $(BIN_DIR)/wg-status + install -m755 src/wg-test $(BIN_DIR)/wg-test install -m755 src/whichcat $(BIN_DIR)/whichcat install -m755 src/whiched $(BIN_DIR)/whiched install -m755 src/whichhead $(BIN_DIR)/whichhead install -m755 src/whichvi $(BIN_DIR)/whichvi install -m755 src/whisper $(BIN_DIR)/whisper install -m755 src/wttr $(BIN_DIR)/wttr + install -m755 src/zipls $(BIN_DIR)/zipls uninstall: rm $(LIB_DIR)/mylib.bash rm $(LIB_DIR)/myparse.bash rm $(LIB_DIR)/myminiparse.sh rm $(LIB_DIR)/unittest-color.awk + rm $(BIN_DIR)/android-emulator rm $(BIN_DIR)/check-x rm $(BIN_DIR)/ctdir @@ -69,24 +79,32 @@ uninstall: rm $(BIN_DIR)/pactl-volume-down rm $(BIN_DIR)/pactl-volume-printf rm $(BIN_DIR)/pactl-volume-up + rm $(BIN_DIR)/pingable + rm $(BIN_DIR)/qemu-test rm $(BIN_DIR)/rand rm $(BIN_DIR)/rebom rm $(BIN_DIR)/rmtar rm $(BIN_DIR)/rmzip + rm $(BIN_DIR)/start-at + rm $(BIN_DIR)/stop-at rm $(BIN_DIR)/tarcat rm $(BIN_DIR)/tarls rm $(BIN_DIR)/unittest rm $(BIN_DIR)/untar rm $(BIN_DIR)/vimsplit + rm $(BIN_DIR)/vpn-off + rm $(BIN_DIR)/vpn-on rm $(BIN_DIR)/wg-off rm $(BIN_DIR)/wg-on rm $(BIN_DIR)/wg-status + rm $(BIN_DIR)/wg-test rm $(BIN_DIR)/whichcat rm $(BIN_DIR)/whiched rm $(BIN_DIR)/whichhead rm $(BIN_DIR)/whichvi rm $(BIN_DIR)/whisper rm $(BIN_DIR)/wttr + rm $(BIN_DIR)/zipls test: clean static-test-files shellcheck src/*.bash src/*.sh $(LIB_DIR)/mylib.bash $(LIB_DIR)/myparse.bash $(LIB_DIR)/myminiparse.sh diff --git a/README.md b/README.md index e407a9d..fdba9b4 100644 --- a/README.md +++ b/README.md @@ -4,32 +4,86 @@ A set of scripts that I use frequently. Written in a mix of shell (some POSIX sh -## Scripts - -Executable |Description |Extra Dependencies -:----------|:-------------------------------------------------------------|:------------------------------------------ -check-x |Check if an X11 server is running -ctdir |Count entries in a target directory(ies) -debom |Remove BOM from a target file |`bash` -enumerate |Dumps HTML from an 'epub' e-book archive |`bash`, `zipinfo`, `unzip`, `w3m` -epub |Rename files in current directory into sequential numbers |`bash` -mkbak |Create a backup of a target file |`bash` -mktar |Wrapper around `tar` for easier compression |`bash` * -rand |Get a random number within an inclusive range |`shuf` -rebom |Add BOM to a target file | -rmtar |Delete 'tar' archive files -rmzip |Delete 'zip' archive files -stop-at |Re-print until a pattern is matched -tarcat |Print contents of target archive file(s) |* -tarls |Print listings of target archive file(s) |* -unittest |Wrapper around Python's `unittest` module |`python3`, GNU or New (AT&T) `awk` -untar |Wrapper around `tar` for easier decompression |* -whichcat |Print all lines from a program -whiched |Open a program with your editor -whichhead |Print the first 10 lines from a program |`bash` -whichvi |Open a program with your visual editor -whisper |Wrapper around `espeak` to mirror `say` in macOS |`espeak` -wttr |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego` +## General-Use Scripts + +Executable|Description |Extra Dependencies +:---------|:-------------------------------------------------------------|:------------------------------------------ +check-x |Check if an X11 server is running +ctdir |Count entries in a target directory(ies) +debom |Remove BOM from a target file |`bash` +enumerate |Dumps HTML from an 'epub' e-book archive |`bash`, `zipinfo`, `unzip`, `w3m` +epub |Rename files in current directory into sequential numbers |`bash` +fw-status |Print current firewall status |`ufw` +mkbak |Create a backup of a target file |`bash` +mktar |Wrapper around `tar` for easier compression |`bash` * +pingable |Check if an address/name is ping-able +rand |Get a random number within an inclusive range |`bash`, `shuf` +rebom |Add BOM to a target file | +rmtar |Delete 'tar' archive files +rmzip |Delete 'zip' archive files +start-at |After a pattern is matched, re-print |GNU or New (AT&T) `awk` +stop-at |Re-print until a pattern is matched |GNU or New (AT&T) `awk` +tarcat |Print contents of `tar` archive file(s) |* +tarls |List files within `tar` archive file(s) |* +unittest |Wrapper around Python's `unittest` module |`python3`, GNU or New (AT&T) `awk` +untar |Wrapper around `tar` for easier decompression |* +vimsplit |Open two files in split windows |`nvim` +whichcat |Print all lines from a program +whiched |Open a program with your editor +whichhead |Print the first 10 lines from a program |`bash` +whichvi |Open a program with your visual editor +whisper |Wrapper around `espeak` to mirror `say` in macOS |`espeak` +wttr |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego` +zipls |List files within `zip` archive file(s) |`zipinfo` + + +## Emulator Scripts + +Executable |Description |Extra Dependencies +:----------------|:------------------------------------------------------|:----------------- +android-emulator |Start an Android emulator session |`adb` +qemu-test |Check if hardware and OS are capable of virtualization | + + +## Docker Scripts + +The following all depend on `docker`. + +Executable |Description |Extra Dependencies +:-----------------|:-----------------------------------------------------------|:----------------- +docker-clean |Stop all containers, remove all images, and clear the cache | +docker-get-all |List all Docker containers' IDs | +docker-get-exited |List all exited Docker containers' IDs | +docker-restart |Restart all exited Docker containers | +docker-up |Start a Docker container using `./docker-compose.yml` |`docker-compose` + + +## Pulseaudio Scripts + +The following all depend on `pactl`. + +Executable |Description |Extra Dependencies +:---------------------|:----------------------------------------------------|:----------------- +pactl-get-running-sink|Get the currently running Pulseaudio sink ID | +pactl-mute |Toggle mute on the currently running Pulseaudio sink | +pactl-volume-down |Reduce volume (default: 10%) | +pactl-volume-printf |Print the currently running Pulseaudio sink volume | +pactl-volume-up |Increase volume (default: 10%) | + + +## VPN Scripts + +Executable|Description |Extra Dependencies +:---------|:---------------------------------------------------------|:----------------- +vpn-off |Stop all OpenVPN connections |`killall` +vpn-on |Start an OpenVPN connection using `$MYUTILS_OPENVPN_CONF` |`openvpn` +wg-off |Stop the `wg0` Wireguard connection |`wg`, `wg-quick` +wg-on |Start the `wg0` Wireguard connection |`wg`, `wg-quick` +wg-status |Print current Wireguard connection status |`wg` +wg-test |Check if Wireguard connection is on and working |`wg` + + +## Notes \* *While you **technically** won't run into an error, these scripts **do** expect `tar` to support Zstandard, which isn't necessarily POSIX standard.* diff --git a/bash-completion/mybashcompletion.bash b/bash-completion/mybashcompletion.bash index eac1fc7..0dcb96f 100644 --- a/bash-completion/mybashcompletion.bash +++ b/bash-completion/mybashcompletion.bash @@ -24,17 +24,19 @@ _epub_completion() { # Complete with function, and fallback to filenames complete -o default -F _epub_completion epub -# rmzip -# Complete with filenames matching pattern '*.zip', and fallback to filenames -complete -o default -f -X '!*.zip' rmzip +# rmzip, zipls +# Complete with filenames matching pattern '*.@(zip|cbr|epub)', and fallback to +# filenames +complete -o default -f -X '!*.@(zip|cbr|epub)' rmzip -# untar, tarcat, rmtar +# rmtar, tarcat, tarls, untar # Complete with filenames matching pattern # '*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)', and fallback to # filenames +complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' rmtar complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarcat +complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarls complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' untar -complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' rmtar # whichcat, whiched. whichhead, whichvi # Complete with program names diff --git a/src/android-emulator b/src/android-emulator index 4e0a7c5..4bc84d9 100755 --- a/src/android-emulator +++ b/src/android-emulator @@ -1,5 +1,18 @@ #!/bin/sh +name="android-emulator" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Start an Android emulator session + Usage: android-emulator + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + adb start-server trap "adb kill-server" EXIT diff --git a/src/check-x b/src/check-x index e7cc412..5bb0dab 100755 --- a/src/check-x +++ b/src/check-x @@ -6,6 +6,9 @@ version="1.0" help_message=$(/usr/bin/cat <<-EOF Check if an X11 server is running Usage: check-x + Options: + -h, --help print this message and exit + -v, --version print version number and exit EOF ) diff --git a/src/docker-clean b/src/docker-clean index 87cb290..6bb0002 100755 --- a/src/docker-clean +++ b/src/docker-clean @@ -1,6 +1,23 @@ #!/bin/sh + +name="docker-clean" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Stop all containers, remove all images, and clear the cache + Usage: docker-clean + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +# Stop all containers to mark everything as prune-able for id in $(docker ps --all --quiet); do docker rm "$id" --force done + +# Prune docker system prune --all --force diff --git a/src/docker-get-all b/src/docker-get-all index b49965c..a14523b 100755 --- a/src/docker-get-all +++ b/src/docker-get-all @@ -1,3 +1,17 @@ #!/bin/sh + +name="docker-get-all" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + List all Docker containers' IDs + Usage: docker-get-all + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + docker ps --format "{{.ID}}" --all diff --git a/src/docker-get-exited b/src/docker-get-exited index 039c91c..329bfdd 100755 --- a/src/docker-get-exited +++ b/src/docker-get-exited @@ -1,3 +1,17 @@ #!/bin/sh + +name="docker-get-exited" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + List all exited Docker containers' IDs + Usage: docker-get-exited + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + docker ps --format "{{.ID}}" --filter exited=1 --all diff --git a/src/docker-restart b/src/docker-restart index 41adc53..03c79f3 100755 --- a/src/docker-restart +++ b/src/docker-restart @@ -1,4 +1,18 @@ #!/bin/sh + +name="docker-restart" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Restart all exited Docker containers + Usage: docker-restart + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + for container in $(docker-get-exited); do docker start "$container" done diff --git a/src/docker-up b/src/docker-up index 456b364..1081c36 100755 --- a/src/docker-up +++ b/src/docker-up @@ -1,3 +1,17 @@ #!/bin/sh + +name="docker-up" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Start a Docker container using './docker-compose.yml'. + Usage: docker-up + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + docker-compose up --detach diff --git a/src/fw-status b/src/fw-status index 9c054f9..a7c01f5 100755 --- a/src/fw-status +++ b/src/fw-status @@ -1,3 +1,17 @@ #!/bin/sh + +name="fw-status" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Print current firewall status + Usage: fw-status + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + sudo ufw status diff --git a/src/pactl-get-running-sink b/src/pactl-get-running-sink index ae59b59..4b9b272 100755 --- a/src/pactl-get-running-sink +++ b/src/pactl-get-running-sink @@ -1,4 +1,17 @@ #!/bin/sh +name="pactl-get-running-sink" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Get the currently running Pulseaudio sink ID + Usage: pactl-get-running-sink + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + pactl list sinks short | grep -F 'RUNNING' | cut -f 1 diff --git a/src/pactl-mute b/src/pactl-mute index 9d9905d..955ac67 100755 --- a/src/pactl-mute +++ b/src/pactl-mute @@ -1,5 +1,18 @@ #!/bin/sh +name="pactl-mute" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Toggle mute on the currently running Pulseaudio sink + Usage: pactl-mute + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + SINK="$(pactl-get-running-sink)" if [ -z "$SINK" ]; then SINK=0 diff --git a/src/pactl-volume-down b/src/pactl-volume-down index 9b0865f..cbd2944 100755 --- a/src/pactl-volume-down +++ b/src/pactl-volume-down @@ -1,5 +1,18 @@ #!/bin/sh +name="pactl-volume-down" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Reduce volume (default: 10%) + Usage: pactl-volume-down [PERCENT] + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + SINK="$(pactl-get-running-sink)" if [ -z "$SINK" ]; then SINK=0 diff --git a/src/pactl-volume-printf b/src/pactl-volume-printf index 910367c..e78501a 100755 --- a/src/pactl-volume-printf +++ b/src/pactl-volume-printf @@ -1,5 +1,18 @@ #!/bin/sh +name="pactl-volume-printf" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Print the currently running Pulseaudio sink volume + Usage: pactl-volume-printf [FORMAT] + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + volumes=$(pactl list sinks \ | grep -F 'Volume:' \ | grep -o -e '[0-9]\+%' \ diff --git a/src/pactl-volume-up b/src/pactl-volume-up index 0446965..a3bf835 100755 --- a/src/pactl-volume-up +++ b/src/pactl-volume-up @@ -1,5 +1,18 @@ #!/bin/sh +name="pactl-volume-up" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Increase volume (default: 10%) + Usage: pactl-volume-up [PERCENT] + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + SINK="$(pactl-get-running-sink)" if [ -z "$SINK" ]; then SINK=0 diff --git a/src/pingable b/src/pingable new file mode 100755 index 0000000..2862aa2 --- /dev/null +++ b/src/pingable @@ -0,0 +1,23 @@ +#!/bin/sh + +name="pingable" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Check if an address or name is ping-able + Usage: pingable [ ADDRESS | NAME ] + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +# Note: `ping` will set the return code to... +# 0 on success +# 1 on failure to ping +# 2 on name resolution failure for most (i.e. Linux) platforms +# 68 on name resolution failure for some (i.e. macOS) platforms + +. /usr/local/lib/myminiparse.sh + +ping -c 1 $1 >/dev/null 2>&1 + diff --git a/src/qemu-test b/src/qemu-test new file mode 100755 index 0000000..9e10ec0 --- /dev/null +++ b/src/qemu-test @@ -0,0 +1,35 @@ +#!/bin/sh + +name="qemu-test" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Check if hardware and OS are capable of virtualization + Usage: qemu-test + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +printf_then_exec() { + printf "%s\n" "$1" + $1 +} + +if ! LC_ALL=C lscpu | grep Virtualization >/dev/null 2>&1; then + printf "Virtualization is not supported by the CPU\n" + printf_then_exec "LC_ALL=C lscpu | grep Virtualization" + exit 1 +elif ! zgrep CONFIG_KVM /proc/config.gz >/dev/null 2>&1; then + printf "Virtualization is not supported by the kernel\n" + printf_then_exec "zgrep CONFIG_KVM /proc/config.gz" + exit 1 +elif ! lsmod | grep kvm >/dev/null 2>&1; then + printf "Kernel modules for virtualization support are not loaded\n" + printf_then_exec "lsmod | grep kvm" + exit 1 +fi +exit 0 + diff --git a/src/start-at b/src/start-at new file mode 100755 index 0000000..dd583c6 --- /dev/null +++ b/src/start-at @@ -0,0 +1,23 @@ +#!/bin/awk -f + +# start-at +# =========== +# Usage: | start-at -v pattern='^-+$' +# +# After a pattern is matched, re-print. + +BEGIN { + if (pattern == "" || inclusive !~ /^[01]?$/) { + print "Usage: start-at -v pattern=PATTERN -v inclusive=0|1" + exit 1 + } + matched=0 +} +{ + if (matched==1) print; + if ($0 ~ pattern) { + matched=1; + if (inclusive==1) print; + } +} + diff --git a/src/tarls b/src/tarls index 9d6d590..fbd3ec6 100755 --- a/src/tarls +++ b/src/tarls @@ -3,7 +3,7 @@ name="tarls" version="1.0" help_message=$(/usr/bin/cat <<-EOF - Wrapper around 'tar' for easier listing + List files within 'tar' archive file(s) Usage: tarls TARGET [..] [OPTIONS] Options: -h, --help print this message and exit diff --git a/src/vimsplit b/src/vimsplit old mode 100644 new mode 100755 diff --git a/src/vpn-off b/src/vpn-off new file mode 100755 index 0000000..c633f5c --- /dev/null +++ b/src/vpn-off @@ -0,0 +1,17 @@ +#!/bin/sh + +name="vpn-off" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Stop the OpenVPN connection + Usage: vpn-off + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +sudo killall openvpn + diff --git a/src/vpn-on b/src/vpn-on new file mode 100755 index 0000000..2bd4596 --- /dev/null +++ b/src/vpn-on @@ -0,0 +1,17 @@ +#!/bin/sh + +name="vpn-on" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Start an OpenVPN connection using '\$MYUTILS_OPENVPN_CONF' + Usage: vpn-on + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +sudo openvpn --config "$MYUTILS_OPENVPN_CONF" --daemon + diff --git a/src/wg-off b/src/wg-off index 8c2b996..da28927 100755 --- a/src/wg-off +++ b/src/wg-off @@ -1,4 +1,18 @@ #!/bin/sh + +name="wg-off" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Stop the 'wg0' Wireguard connection + Usage: wg-off + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + sudo wg-quick down wg0 sudo wg show diff --git a/src/wg-on b/src/wg-on index 7c7a374..9524b08 100755 --- a/src/wg-on +++ b/src/wg-on @@ -1,4 +1,18 @@ #!/bin/sh + +name="wg-on" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Start the 'wg0' Wireguard connection + Usage: wg-on + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + sudo wg-quick up wg0 sudo wg show diff --git a/src/wg-status b/src/wg-status index 2e0af63..7a6542a 100755 --- a/src/wg-status +++ b/src/wg-status @@ -1,3 +1,17 @@ #!/bin/sh + +name="wg-status" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Print current Wireguard connection status + Usage: wg-status + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + sudo wg show diff --git a/src/wg-test b/src/wg-test new file mode 100755 index 0000000..fae88a4 --- /dev/null +++ b/src/wg-test @@ -0,0 +1,32 @@ +#!/bin/sh + +name="wg-test" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + Check if Wireguard connection is on and working + Usage: wg-test + Options: + -h, --help print this message and exit + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +if [ $(wg-status | wc -l) -le 1 ]; then + printf "Wireguard is not running\n" + exit 1 +fi + +# NOTE: assume that Wireguard configurations use 10.0.0.0/24, just like pretty +# much all upstream documentation + +if ! pingable 10.0.0.1; then + printf "Wireguard server is not reachable; try checking...\n" + printf " - if the server is running\n" + printf " - if the server can ping peers\n" + printf " - if the server firewall is blocking connections\n" + exit 1 +fi +exit 0 + diff --git a/src/zipls b/src/zipls new file mode 100755 index 0000000..f465444 --- /dev/null +++ b/src/zipls @@ -0,0 +1,41 @@ +#!/bin/sh + +name="zipls" +version="1.0" +help_message=$(/usr/bin/cat <<-EOF + List files within 'zip' archive file(s) + Usage: zipls TARGET [..] [OPTIONS] + Options: + -h, --help print this message and exit + -q, --quiet suppress error messages + -v, --version print version number and exit +EOF +) + +. /usr/local/lib/myminiparse.sh + +# error if no directory names given +if [ "$#" -eq 0 ]; then + (>&2 /usr/bin/printf "Usage: zipls TARGET [OPTIONS]\n") + exit 1 +elif [ "$#" -eq 1 ] && [ "$quiet" -eq 1 ]; then + exit 1 +fi + +# main routine +code=0 +for target; do + if [ ! -f "$target" ]; then + if [ "$quiet" -eq 0 ]; then + (>&2 printf "%s: No such file '%s'\n" "$name" "$target") + fi + code=1 + else + if ! zipinfo -1 "$target"; then + code=1 + fi + fi +done + +exit "$code" + -- 2.45.2