aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/.local/bin
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-03-29 16:50:45 -0500
committerToby Vincent <tobyv13@gmail.com>2022-03-29 16:50:45 -0500
commit6bfbdbf35365174903c305ec4b254c2523413ca6 (patch)
tree3b5b401cfaba667aaacca3db3eac455ac6930bd7 /scripts/.local/bin
parenteea16815b501369da58a8c3886f41558022835ca (diff)
refactor: moved scripts into wsl package
Diffstat (limited to 'scripts/.local/bin')
-rwxr-xr-xscripts/.local/bin/discord-relay.sh2
-rw-r--r--scripts/.local/bin/gpg-test.sh102
-rwxr-xr-xscripts/.local/bin/mkln.sh115
-rwxr-xr-xscripts/.local/bin/socket-relay.sh217
4 files changed, 0 insertions, 436 deletions
diff --git a/scripts/.local/bin/discord-relay.sh b/scripts/.local/bin/discord-relay.sh
deleted file mode 100755
index 3932908..0000000
--- a/scripts/.local/bin/discord-relay.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-exec socat UNIX-LISTEN:/var/run/discord-ipc-0,fork,group=discord,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/discord-ipc-0",nofork >/dev/null 2>&1
diff --git a/scripts/.local/bin/gpg-test.sh b/scripts/.local/bin/gpg-test.sh
deleted file mode 100644
index f23b83d..0000000
--- a/scripts/.local/bin/gpg-test.sh
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/env bash
-
-TEMP=$(getopt -o hvdsea: --long help,verbose,debug,signature,encryption,authentication \
- -n 'javawrap' -- "$@")
-
-if [ $? != 0 ]; then
- echo "Terminating..." >&2
- exit 1
-fi
-
-eval set -- "$TEMP"
-
-usage() {
- cat <<EOF
-usage: $0 [OPTIONS]
-
- -h,--help Show this message
- -v,--verbose Show test output
- -d,--debug NOT IMPLEMENTED
- -s,--signature Test signature key
- -e,--encryption Test encryption key
- -a,--authentication Test authentication key
-EOF
-}
-
-VERBOSE=false
-DEBUG=false
-SIGNATURE=false
-ENCRYPTION=false
-AUTHENTICATION=false
-ALL=true
-
-while true; do
- case "$1" in
- -h | --help)
- usage
- exit 0
- ;;
- -v | --verbose)
- VERBOSE=true
- shift
- ;;
- -d | --debug)
- DEBUG=true
- shift
- ;;
- -s | --signature)
- ALL=false
- SIGNATURE=true
- shift
- ;;
- -e | --encryption)
- ALL=false
- ENCRYPTION=true
- shift
- ;;
- -a | --authentication)
- ALL=false
- AUTHENTICATION=true
- shift
- ;;
- --)
- shift
- break
- ;;
- *) break ;;
- esac
-done
-
-function print_result() {
- if [ $? -ne 0 ]; then
- echo "Failed: $?"
- else
- echo "Succeeded"
- fi
-
- if [ $VERBOSE -eq "true" ]; then
- echo "\nOutput:\n$result"
- fi
-}
-
-if [[ $ALL -eq "true" || $SIGNITURE -eq "true" ]]; then
- echo "Testing signiture key..."
- result="$(echo '' | gpg --clearsign &>/dev/null 2>&1)"
- print_result result
-fi
-
-if [[ $ALL -eq "true" || $ENCRYPTION -eq "true" ]]; then
- echo "Testing encryption key..."
- temp="$(mktemp -d)"
- echo "secret file contents: 42" >$temp/test.txt
-
- result="$(gpg --output $temp/test.gpg -e $temp/test.txt 2>&1 && gpg --output $temp/test.out -d $temp/test.txt.gpg 2>&1)"
- grep '42' $temp/test.out 2>&1
- print_result result
-fi
-
-if [[ $ALL -eq "true" || $AUTHENTICATION -eq "true" ]]; then
- echo "Testing authentication key..."
- result="$(ssh-add -l)"
- print_result result
-fi
diff --git a/scripts/.local/bin/mkln.sh b/scripts/.local/bin/mkln.sh
deleted file mode 100755
index ef174c2..0000000
--- a/scripts/.local/bin/mkln.sh
+++ /dev/null
@@ -1,115 +0,0 @@
-#!/usr/bin/env bash
-
-TEMP=$(getopt -o hvqdf --long help,verbose,quiet,debug,force \
- -n 'javawrap' -- "$@")
-
-if [ $? != 0 ]; then
- echo "Terminating..." >&2
- exit 1
-fi
-
-eval set -- "$TEMP"
-
-SCRIPT="$(basename $0)"
-VERBOSE=false
-QUIET=false
-DEBUG=false
-FORCE=false
-
-read -r -d '' USAGE <<-EOF
-USAGE: $SCRIPT [OPTIONS] <SOURCE> <TARGET>
-
-OPTIONS:
- -h, --help Show this message
- -v, --verbose Show more output
- -q, --quiet Suppress all output
- -d, --debug NOT IMPLEMENTED
- -f, --force Overwrite items
-
-ARGS:
- <SOURCE> <TARGET>... File to link.
-EOF
-
-while true; do
- case "$1" in
- -h | --help)
- echo "$USAGE"
- exit 0
- ;;
- -v | --verbose)
- VERBOSE=true
- shift
- ;;
- -q | --quiet)
- QUIET=true
- shift
- ;;
- -d | --debug)
- DEBUG=true
- shift
- ;;
- -f | --force)
- FORCE=true
- shift
- ;;
- --)
- shift
- break
- ;;
- *)
- break
- ;;
- esac
-done
-
-if ! command -v powershell.exe &>/dev/null; then
- [ "$QUIET" != true ] && echo "Powershell not found in path." >&2
- exit 1
-fi
-
-if [ -z "$2" ]; then
- 2="$(pwd)"
-fi
-
-[ "$VERBOSE" == true ] && echo "linking $2 -> $1"
-
-if [ -d "$1" ]; then
- [ "$VERBOSE" == true ] && echo "$1 is a directory. Creating symbolic link."
- args='/D'
-fi
-
-mkdir -p $(dirname $2)
-
-source=$(wslpath -w $1)
-target=$(wslpath -w $(dirname $2))\\$(basename $2)
-
-if ls -la "$(dirname $2)/" 2>/dev/null | grep -q "$(basename $2)"; then
-
- current_path=$(powershell.exe -c "(Get-Item $target).Target" 2>/dev/null)
-
- if [[ "${current_path/*wsl$/}" == *"${source/*wsl$/}"* ]]; then
- [ "$VERBOSE" == true ] && echo "$(basename $2) is set correctly. Skipping."
- exit 0
- fi
-
- if [ "$FORCE" == true ]; then
- [ "$VERBOSE" == true ] && echo "$(basename $2) exists. Overwriting."
- rm -rf "$2"
- else
- [ "$QUIET" != true ] && echo "$(basename $target) already exists. Use -f to overwrite." >&2
- exit 1
- fi
-fi
-
-mkdir -p "$(dirname $2)"
-cmd="cd ~; cmd /c mklink ${args} ${target} ${source}"
-
-if [ "$DEBUG" == true ]; then
- [ "$QUIET" != true ] && printf '\nCommand: \n%s\n\n' "powershell.exe -c ${cmd} &>/dev/null"
-else
- if $QUIET; then
- powershell.exe -c "${cmd}" &>/dev/null
- else
- powershell.exe -c "${cmd}"
- fi
-fi
diff --git a/scripts/.local/bin/socket-relay.sh b/scripts/.local/bin/socket-relay.sh
deleted file mode 100755
index 436fa54..0000000
--- a/scripts/.local/bin/socket-relay.sh
+++ /dev/null
@@ -1,217 +0,0 @@
-#!/usr/bin/env bash
-set -euo pipefail
-
-OPTS=$(getopt -o hds:x: --long help,debug,sock:,exec:,ssh,gpg,gpg-extra,discord -n 'javawrap' -- "$@")
-
-eval set -- "$OPTS"
-
-PAGEANT="$HOME/.ssh/wsl2-ssh-pageant.exe"
-NPIPE="$(command -v npiperelay.exe)"
-SCRIPT="$(basename "$0")"
-
-help() {
- cat <<-EOF
-$SCRIPT
-Toby Vincent <tobyv13@gmail.com>
-
-$SCRIPT description
-
-USAGE:
- $SCRIPT [OPTIONS] <COMMAND>
- $SCRIPT [OPTIONS]
-
-OPTIONS:
- -h, --help Display this message
- -s, --sock <SOCKET> Path to the linux socket
- -x, --exec <CMD> Command to run for socat's EXEC: arg
- --ssh Relay the ssh agent's socket
- --gpg Relay the gpg agent's socket
- --gpg-extra Relay the gpg agent's extra socket
-
-ARGS:
- start (default)
- Start the socat process
-
- stop
- Kill the socat process
-EOF
-}
-
-say() {
- if ! $quiet; then
- echo "$SCRIPT: $1"
- fi
-}
-
-say_err() {
- say "$1" >&2
-}
-
-err() {
- say_err "ERROR: $1"
- exit 1
-}
-
-need() {
- for cmd in $@; do
- if ! command -v $cmd >/dev/null 2>&1; then
- err "need $cmd (command not found)"
- fi
- done
-}
-
-start() {
- if ! ss -a | grep -q "$sock"; then
- if test -x "$relay"; then
- rm -rf "$sock"
- (setsid nohup socat UNIX-LISTEN:"${sock},${listen_args}" EXEC:"$cmd" >/dev/null 2>&1 &)
-
- else
- echo >&2 "WARNING: $relay is not executable."
- fi
- fi
-
- if $gpg; then
- gpg-connect-agent.exe /bye &>/dev/null
- fi
-}
-
-stop() {
- if $gpg; then
- gpg-connect-agent.exe KILLAGENT /bye &>/dev/null
- fi
-
- if pgrep -f "socat.*$sock.*$relay" &>/dev/null; then
- pkill -f "socat.*$sock.*$relay"
- fi
-}
-
-check() {
- pgrep -fa "socat.*$sock.*$relay"
-}
-
-quiet=false
-debug=false
-sock=""
-cmd=""
-gpg=false
-ssh=false
-extra=false
-discord=false
-while test $# -gt 0; do
- case $1 in
- -h | --help)
- help
- return 0
- ;;
- -q | --quiet)
- quiet=true
- shift
- ;;
- -d | --debug)
- debug=true
- shift
- ;;
- -s | --sock)
- sock=$2
- shift
- shift
- ;;
- -x | --exec)
- cmd=$2
- shift
- shift
- ;;
- --ssh)
- ssh=true
- shift
- ;;
- --gpg)
- gpg=true
- shift
- ;;
- --gpg-extra)
- gpg=true
- extra=true
- shift
- ;;
- --discord)
- discord=true
- shift
- ;;
- --)
- shift
- break
- ;;
- *)
- help
- exit 1
- ;;
- esac
-done
-
-need ss
-need socat
-
-listen_args="fork"
-
-case true in
-$ssh)
- need $PAGEANT
-
- sock="${SSH_AUTH_SOCK:-$HOME/.ssh/agent.sock}"
- cmd="$PAGEANT"
- ;;
-$gpg)
- need $PAGEANT
- need "gpg-connect-agent.exe"
-
- sock="${GPG_AGENT_SOCK:-$HOME/.gnupg/S.gpg-agent}"
- if $extra; then
- sock+=".extra"
- fi
-
- cmd="$PAGEANT --gpg $(basename $sock)"
- ;;
-$discord)
- need $NPIPE
-
- sock="${DISCORD_IPC_SOCK:-/var/run/discord-ipc-0}"
- cmd="$NPIPE -ep -s //./pipe/$(basename $sock)"
-
- listen_args="fork,group=discord,umask=007"
- ;;
-$(test -z "${cmd}"))
- err "No EXEC provided. Must supply either --ssh, --gpg, --gpg-extra, --pipe, or --exec"
- ;;
-esac
-
-if test -z "${sock}"; then
- err "No socket provided."
-fi
-
-relay="$(echo $cmd | head -n1 | awk '{print $1;}')"
-
-case ${1:-'start'} in
-check)
- shift
- check
- ;;
-start)
- shift
- start
- ;;
-stop)
- shift
- stop
- ;;
-restart)
- shift
- stop
- start
- ;;
-*)
- help
- exit 1
- ;;
-esac