From 775a43810c62b787310a62eb680ae63337cf7ee6 Mon Sep 17 00:00:00 2001 From: Arthur Khachaturov Date: Sun, 18 Aug 2024 03:41:19 +0300 Subject: [PATCH] script changes --- .local/bin/scripts/gdt | 47 +++++++++++++++++++++++++++++++--- .local/bin/scripts/pentablet | 6 ----- .local/bin/scripts/vpn | 16 +++--------- .local/bin/scripts/vpnd | 49 ++++++++++++++++++++++++++++++++++++ .local/bin/scripts/wg-quick | 7 ++++++ .xinitrc | 8 +++--- 6 files changed, 108 insertions(+), 25 deletions(-) delete mode 100755 .local/bin/scripts/pentablet create mode 100755 .local/bin/scripts/vpnd create mode 100755 .local/bin/scripts/wg-quick diff --git a/.local/bin/scripts/gdt b/.local/bin/scripts/gdt index c4682d4..e633b34 100755 --- a/.local/bin/scripts/gdt +++ b/.local/bin/scripts/gdt @@ -1,14 +1,53 @@ #!/bin/bash -if [ ! -d .git ]; then +if [ ! -d "./.git" ]; then echo "missing .git dir!" exit 1 fi -echo "Last commit: $(git log | grep 'Date' | cut -d ' ' -f 4- | head -1)" -read -r -p "Date: " date +last_commit() { + printf "Last commit date: %s\n" "$(git log | grep 'Date' | cut -d ' ' -f 4- | head -1)" +} + +help() { + echo "gdt: Commit with fake date" + echo + echo "USAGE" + echo " $0 -[dl] " + echo + echo "ARGS" + echo " -d, --date Sets commit and author date" + echo " -h, --help Prints this message" +} + +die() { + echo "ERROR: $1" + echo + help >&2 + exit 1 +} + +case "$1" in + "-d"|"--date") + shift + [ -n "$1" ] && date="$1" || die "Missing date" + shift + ;; + "-h"|"--help") + help + exit + ;; + *) + last_commit + exit + ;; +esac + +if [ "$#" -lt "1" ]; then + die "Missing commit message!" +fi export GIT_AUTHOR_DATE="${date}" export GIT_COMMITTER_DATE="${date}" -git "$@" +git commit -am "$@" diff --git a/.local/bin/scripts/pentablet b/.local/bin/scripts/pentablet deleted file mode 100755 index e3e174a..0000000 --- a/.local/bin/scripts/pentablet +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -OUTPUT="${1:-"DP-1"}" -xinput --map-to-output "UGTABLET 6 inch PenTablet Mouse" "${OUTPUT}" -xinput --map-to-output "UGTABLET 6 inch PenTablet Pen (0)" "${OUTPUT}" -xinput --map-to-output "UGTABLET 6 inch PenTablet Eraser (0)" "${OUTPUT}" diff --git a/.local/bin/scripts/vpn b/.local/bin/scripts/vpn index f63255e..a7fdf8b 100755 --- a/.local/bin/scripts/vpn +++ b/.local/bin/scripts/vpn @@ -1,12 +1,6 @@ #!/bin/bash IFNAME="wg_lva" -PIPE="/var/run/vpnd.sock" - -vpn_sock() { - echo echoing "$@" - [ -p "$PIPE" ] && echo "$@" > $PIPE -} while [ "$#" -gt 0 ]; do case "$1" in @@ -16,8 +10,6 @@ while [ "$#" -gt 0 ]; do ;; '-v'|'--verbose') VERBOSE=1 ;; - '--visual') - ;; *) echo "Wrong argument!"; exit 1 ;; esac @@ -35,15 +27,15 @@ UP_NAME="$(ip link show | grep 'wg' | cut -d ' ' -f 2 | sed 's/://')" IFNAME="${IFNAME}${DPI}" if [ -n "${UP_NAME}" ]; then if [ "${UP_NAME}" != "${IFNAME}" ]; then - vpn_sock replace "${UP_NAME}" "${IFNAME}" + wg-quick down "${UP_NAME}" + wg-quick up "${IFNAME}" else - vpn_sock down "${UP_NAME}" + wg-quick down "${UP_NAME}" fi else - vpn_sock up "${IFNAME}" + wg-quick up "${IFNAME}" fi -read -r < "$PIPE" pkill -36 dwmblocks # vim: ft=bash diff --git a/.local/bin/scripts/vpnd b/.local/bin/scripts/vpnd new file mode 100755 index 0000000..c59786c --- /dev/null +++ b/.local/bin/scripts/vpnd @@ -0,0 +1,49 @@ +#!/bin/bash +# shellcheck disable=SC2034 + +PIPE="/var/run/vpnd.sock" + +[ -p $PIPE ] && exit 1 +[ "$(id -u)" != "0" ] && exit 1 + +trap 'die' SIGTERM SIGQUIT SIGINT + +declare -a CONFIGS +for config in /etc/wireguard/*; do + config="$(basename "$config")" + CONFIGS+=("${config%.conf}") +done + +COMMANDS=("up" "down") + +die() { + rm $PIPE + exit 0 +} + +in_arr() { + declare -n arr="$2" + + for value in "${arr[@]}"; do + [ "$value" = "$1" ] && return 0 + done + return 1 +} + +main() { + mkfifo $PIPE -m666 + + while :; do + read -r cmd ifname < $PIPE + + if ! in_arr "$ifname" "CONFIGS"; then + echo "ERROR: Invalid interface $ifname" > $PIPE + elif ! in_arr "$cmd" "COMMANDS"; then + echo "ERROR: Invalid command $cmd" > $PIPE + else + wg-quick "$cmd" "$ifname" > $PIPE 2>&1 + fi + done +} + +main diff --git a/.local/bin/scripts/wg-quick b/.local/bin/scripts/wg-quick new file mode 100755 index 0000000..fd3fb9c --- /dev/null +++ b/.local/bin/scripts/wg-quick @@ -0,0 +1,7 @@ +#!/bin/bash + +PIPE="/var/run/vpnd.sock" + +[ -p $PIPE ] && +echo "$@" > $PIPE && +cat < $PIPE diff --git a/.xinitrc b/.xinitrc index 0121d81..1ac76e4 100644 --- a/.xinitrc +++ b/.xinitrc @@ -1,8 +1,10 @@ -. ${HOME}/.config/X11/xprofile +. "${HOME}"/.config/X11/xprofile [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && eval $(/usr/bin/dbus-launch --exit-with-session --sh-syntax) dbus-update-activation-environment --verbose --all xr -. ${HOME}/.config/X11/autostart +. "${HOME}"/.config/X11/autostart -exec ssh-agent ${HOME}/.local/src/dwm/dwm +exec ssh-agent "${HOME}"/.local/src/dwm/dwm # exec ssh-agent /usr/bin/dwm + +# vim: ft=sh