script changes

This commit is contained in:
Arthur Khachaturov 2024-08-18 03:41:19 +03:00
parent 6e8683c725
commit 775a43810c
No known key found for this signature in database
GPG key ID: CAC2B7EB6DF45D55
6 changed files with 108 additions and 25 deletions

View file

@ -1,14 +1,53 @@
#!/bin/bash #!/bin/bash
if [ ! -d .git ]; then if [ ! -d "./.git" ]; then
echo "missing .git dir!" echo "missing .git dir!"
exit 1 exit 1
fi fi
echo "Last commit: $(git log | grep 'Date' | cut -d ' ' -f 4- | head -1)" last_commit() {
read -r -p "Date: " date 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] <git command>"
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_AUTHOR_DATE="${date}"
export GIT_COMMITTER_DATE="${date}" export GIT_COMMITTER_DATE="${date}"
git "$@" git commit -am "$@"

View file

@ -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}"

View file

@ -1,12 +1,6 @@
#!/bin/bash #!/bin/bash
IFNAME="wg_lva" IFNAME="wg_lva"
PIPE="/var/run/vpnd.sock"
vpn_sock() {
echo echoing "$@"
[ -p "$PIPE" ] && echo "$@" > $PIPE
}
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
@ -16,8 +10,6 @@ while [ "$#" -gt 0 ]; do
;; ;;
'-v'|'--verbose') VERBOSE=1 '-v'|'--verbose') VERBOSE=1
;; ;;
'--visual')
;;
*) echo "Wrong argument!"; exit 1 *) echo "Wrong argument!"; exit 1
;; ;;
esac esac
@ -35,15 +27,15 @@ UP_NAME="$(ip link show | grep 'wg' | cut -d ' ' -f 2 | sed 's/://')"
IFNAME="${IFNAME}${DPI}" IFNAME="${IFNAME}${DPI}"
if [ -n "${UP_NAME}" ]; then if [ -n "${UP_NAME}" ]; then
if [ "${UP_NAME}" != "${IFNAME}" ]; then if [ "${UP_NAME}" != "${IFNAME}" ]; then
vpn_sock replace "${UP_NAME}" "${IFNAME}" wg-quick down "${UP_NAME}"
wg-quick up "${IFNAME}"
else else
vpn_sock down "${UP_NAME}" wg-quick down "${UP_NAME}"
fi fi
else else
vpn_sock up "${IFNAME}" wg-quick up "${IFNAME}"
fi fi
read -r < "$PIPE"
pkill -36 dwmblocks pkill -36 dwmblocks
# vim: ft=bash # vim: ft=bash

49
.local/bin/scripts/vpnd Executable file
View file

@ -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

7
.local/bin/scripts/wg-quick Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
PIPE="/var/run/vpnd.sock"
[ -p $PIPE ] &&
echo "$@" > $PIPE &&
cat < $PIPE

View file

@ -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) [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && eval $(/usr/bin/dbus-launch --exit-with-session --sh-syntax)
dbus-update-activation-environment --verbose --all dbus-update-activation-environment --verbose --all
xr 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 # exec ssh-agent /usr/bin/dwm
# vim: ft=sh