summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-02 15:19:25 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-02 15:19:25 +0200
commit9b791ac8786eed2d242d0909dd2379f008952042 (patch)
tree403c08eb322e18d045606822911a7eb6036f0070 /bin
parente614a330978ce7e7f6d130cc7d199150e16a409d (diff)
parent63c64f071ecd45cf66ab49d199a634cd8db27056 (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin')
-rwxr-xr-xbin/common/aumount102
-rwxr-xr-xbin/common/cx2
-rwxr-xr-xbin/common/drop_cache2
-rwxr-xr-xbin/common/saf24
-rwxr-xr-xbin/common/sync-install.sh58
-rwxr-xr-xbin/common/toush14
-rwxr-xr-xbin/common/wt7
-rwxr-xr-xbin/common/y2feed15
-rwxr-xr-xbin/extra/aivpn39
-rwxr-xr-xbin/guiscripts/locker9
-rwxr-xr-xbin/guiscripts/startw5
-rwxr-xr-xbin/menuscripts/mpass3
-rwxr-xr-xbin/menuscripts/mpower9
-rwxr-xr-xbin/serverscripts/dlcons2
14 files changed, 263 insertions, 28 deletions
diff --git a/bin/common/aumount b/bin/common/aumount
new file mode 100755
index 0000000..19b33e0
--- /dev/null
+++ b/bin/common/aumount
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+tmp="$(mktemp)"
+test "$(id -u)" != "0" && sudo="sudo"
+
+die ()
+{
+ echo "$@" >&2
+}
+
+# Read one character
+read_char ()
+{
+ die -n ">"
+ old_stty_cfg=$(stty -g)
+ stty raw
+ dd ibs=1 count=${1:-1} 2> /dev/null
+ stty $old_stty_cfg
+ die ""
+}
+
+get_dev ()
+{
+ grep "^$1\." "$tmp" | cut -f 2- -d ' '
+}
+
+# mount the device with $1 as the choice
+mount ()
+{
+ dev="$(get_dev "$1")"
+ test -z "$dev" && exit 1
+
+ die "Mounting /dev/$dev on /media/$dev"
+ mkdir -p /media/$dev
+ $sudo mount /dev/$dev /media/$dev > /dev/null 2>&1 ||
+ return 1
+}
+
+# umount the device with $1 as the choice
+umount ()
+{
+ mountpoint="$(sed -n "${1}p" "$tmp" |
+ awk '{print $3}')"
+ test -z "$mountpoint" && exit 1
+
+ die "Unmounting $mountpoint"
+ $sudo umount "$mountpoint" ||
+ return 1
+}
+
+ejekt ()
+{
+ dev="$(get_dev "$1" | sed 's/.$//')"
+ test -z "$dev" && exit 1
+
+ die "Ejecting /dev/$dev"
+ $sudo eject /dev/$dev > /dev/null 2>&1 ||
+ return 1
+}
+
+# print lsblk, use $1 to print only devices with mountpoints or without
+pr_lsblk ()
+{
+ clear
+ lsblk -o name,size,type,mountpoint
+ die "───────────────────────────────────"
+ lsblk --ascii -o name,mountpoint |
+ grep '^.-' |
+ while read line
+ do
+ words="$(printf "$line" | wc -w)"
+ test $words -eq ${1:-1} && continue
+ printf "%s\n" "$line"
+ done |
+ cut -f 2- -d "-" |
+ awk '{print NR ". " $0}' |
+ tee "$tmp" >&2
+}
+
+cleanup ()
+{
+ rm -f "$tmp"
+}
+
+trap cleanup EXIT INT
+
+die "m(ount) u(mount) (e)ject ?"
+choice="$(read_char)"
+
+case $choice in
+ "m") i=2; cmd=mount ;;
+ "u") i=1; cmd=umount ;;
+ "e") i=2; cmd=ejekt ;;
+ *) exit 1 ;;
+esac
+
+pr_lsblk $i
+choice="$(read_char)"
+printf "$choice" | grep -q "[0-9]" || exit 1
+$cmd $choice &&
+ die "Successful." ||
+ die "Failed."
diff --git a/bin/common/cx b/bin/common/cx
new file mode 100755
index 0000000..88fb817
--- /dev/null
+++ b/bin/common/cx
@@ -0,0 +1,2 @@
+#!/bin/sh
+[ -x "$1" ] && chmod -x "$1" || chmod +x "$1"
diff --git a/bin/common/drop_cache b/bin/common/drop_cache
index 4833597..e4fc039 100755
--- a/bin/common/drop_cache
+++ b/bin/common/drop_cache
@@ -4,5 +4,5 @@ then
echo "Please run as root."
exit 1
fi
-echo 3 | tee /proc/sys/vm/drop_caches >/dev/null
+echo 3 > /proc/sys/vm/drop_caches
echo "cache cleared."
diff --git a/bin/common/saf b/bin/common/saf
new file mode 100755
index 0000000..0c6fbc4
--- /dev/null
+++ b/bin/common/saf
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Simple Ass Fetch by futxlii
+
+red="$(printf '\033[31m')"
+green="$(printf '\033[32m')"
+blue="$(printf '\033[34m')"
+reset="$(printf '\033[0m')"
+
+for file in /etc/os-release /usr/lib/os-release
+do
+ [ -f "$file" ] && . "$file" && break
+done
+
+KERNEL="$(uname -r)"
+UPTIME="$(uptime -p)"; UPTIME="${UPTIME##up }"
+SHELL="$(basename "$SHELL")"
+
+cat <<EOF
+ ${red}- ${blue}${ID:-"unknown"}
+ ${red}- ${blue}$KERNEL
+ ${red}- ${blue}$UPTIME
+ ${red}- ${blue}$SHELL${reset}
+EOF
diff --git a/bin/common/sync-install.sh b/bin/common/sync-install.sh
new file mode 100755
index 0000000..e26c74d
--- /dev/null
+++ b/bin/common/sync-install.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+die ()
+{
+ echo "$@" >&2
+}
+
+read_char ()
+{
+ old_stty_cfg=$(stty -g)
+ stty raw -echo
+ dd ibs=1 count=1 2> /dev/null
+ stty $old_stty_cfg
+}
+
+confirm ()
+{
+ printf "$1 "
+ read_char | grep "[yY]"
+}
+
+usage()
+{
+ >&2 printf 'Usage: %s <remote> <destination>\n' "${0##*/}"
+}
+
+[ $# -lt 2 ] && usage && exit 1
+REMOTE="$1"
+DEST="$2"
+SCRIPT="${3:-sync.sh}"
+
+if ! ssh $REMOTE test -w $DEST 2> /dev/null
+then
+ die "Not a valid remote or destination."
+ exit 1
+fi
+
+die "─────────────────────────────────────────────────────────────"
+cat <<EOF | tee "$SCRIPT" >&2
+#!/bin/sh
+
+THISDIR="\$(dirname "\$(readlink -f "\$0")")"
+inotifywait -m -e create,modify,delete --format "%f" "\$THISDIR" |
+while read FILE
+do
+ rsync -aP "\$THISDIR/" "$REMOTE:$DEST"
+ sleep 1m
+done
+EOF
+die "─────────────────────────────────────────────────────────────"
+die "located at $(readlink -f "$SCRIPT")"
+
+if confirm "good?"
+then
+ chmod +x "$SCRIPT"
+else
+ rm -f "$SCRIPT"
+fi
diff --git a/bin/common/toush b/bin/common/toush
new file mode 100755
index 0000000..dd675b9
--- /dev/null
+++ b/bin/common/toush
@@ -0,0 +1,14 @@
+#!/bin/sh
+# fork of
+# https://codeberg.org/futxlii/bin/toush :)
+
+shebang='#!/bin/sh'
+
+usage() { >&2 printf 'Usage: %s' "${0##*/}"; exit 1 ;}
+
+[ "$1" ] || usage
+while [ "$1" ]; do
+ [ -f "$1" ] && usage
+ printf '%s\n\n' "$shebang" > "$1" && chmod +x "$1"
+ shift
+done
diff --git a/bin/common/wt b/bin/common/wt
index 0568b99..d19539b 100755
--- a/bin/common/wt
+++ b/bin/common/wt
@@ -1,10 +1,7 @@
#!/bin/sh
-
-echo "$@" > /tmp/truewhile.tmp
while true
do
- sh /tmp/truewhile.tmp
- sleep 1
clear
+ $@
+ sleep 1
done
-rm /tmp/truewhile.tmp
diff --git a/bin/common/y2feed b/bin/common/y2feed
index 196ecb7..e30bccf 100755
--- a/bin/common/y2feed
+++ b/bin/common/y2feed
@@ -1,12 +1,5 @@
#!/bin/sh
-ua="$(yt-dlp --dump-user-agent)"
-
-test -z "${url:=$1}" &&
- url="$(cat /dev/stdin)"
-
-url="http://youtube.com/$(echo "$url" |
- awk -F '/' '{print $NF}')"
-echo "url: $url" >&2
-
-curl -L -s -H "$ua" "$url" |
- pup 'link[title=RSS] attr{href}'
+echo "url: $1" >&2
+curl -L -s "$1" |
+ pup 'link[title=RSS] attr{href}' |
+ tee /dev/stderr
diff --git a/bin/extra/aivpn b/bin/extra/aivpn
new file mode 100755
index 0000000..c67aa2c
--- /dev/null
+++ b/bin/extra/aivpn
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+die ()
+{
+ echo "$@" >&2
+}
+
+if [ "$1" = "-k" ]
+then
+ pgrep -f -- "ssh.*-L.*mc-wd" |
+ xargs kill
+ exit
+fi
+
+# For when script calls itself
+if [ -n "$PASSWORD" ]
+then
+ pass show "$PASSWORD" &&
+ exit
+ exit 1
+fi
+
+keyadd ehb/ai
+
+export SSH_ASKPASS="$0"
+export SSH_ASKPASS_REQUIRE="prefer"
+export PASSWORD=aluc
+
+die "I: Activating vpn"
+ssh mc-wd rasdial "vpn.student.ehb.be"
+ssh -f -N \
+ -L 2222:10.2.160.41:22 \
+ mc-wd
+
+ssh -t \
+ -L 8188:localhost:8188 \
+ mc-wd \
+ ssh -N -L 8188:localhost:8188 luca@10.2.160.41
+die "[8188], [2222]"
diff --git a/bin/guiscripts/locker b/bin/guiscripts/locker
index c35f6d4..b680484 100755
--- a/bin/guiscripts/locker
+++ b/bin/guiscripts/locker
@@ -3,10 +3,7 @@ which swaylock grim pixelate > /dev/null ||
exit 1
umask 077
-monitors="$(hyprctl monitors -j |
- jq -r '.[].name' |
- tr '\n' ' ' |
- sed 's,.$,,')"
+monitors="$(hyprctl monitors -j | jq -r '.[].name' | xargs)"
for monitor in $monitors
do
@@ -14,9 +11,9 @@ do
grim -l 0 -o "$monitor" "$file"
pixelate "$file" "$file"
# Create image command for swaylock
- icmd="$icmd --image $monitor:$file"
+ img_opt="--image $monitor:$file $img_opt"
files="$files $file"
done
-swaylock -f -u $icmd
+swaylock -f -u $img_opt
shred -uz -- $files
diff --git a/bin/guiscripts/startw b/bin/guiscripts/startw
new file mode 100755
index 0000000..768f401
--- /dev/null
+++ b/bin/guiscripts/startw
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+eval "$(keychain --dir "$XDG_CONFIG_HOME/keychain" --eval --quiet --agents gpg,ssh)"
+
+Hyprland
diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass
index 87559e9..a50f0fb 100755
--- a/bin/menuscripts/mpass
+++ b/bin/menuscripts/mpass
@@ -6,7 +6,7 @@ then
menucmd="tofi --prompt pass:"
elif [ "$MENUCMD" = "dmenu" ]
then
- menucmd="dmenu -l 4 -g 2 -x -i -p pass:"
+ menucmd="dmenu -l 4 -g 2 -i -p pass:"
else
menucmd="fzf --prompt pass:"
fi
@@ -17,6 +17,7 @@ do
file="$file/$choice"
done
+test -z "$file" && exit 1
pass show -c "$file" &&
if [ -n "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null
then
diff --git a/bin/menuscripts/mpower b/bin/menuscripts/mpower
index f03fd8e..443ed54 100755
--- a/bin/menuscripts/mpower
+++ b/bin/menuscripts/mpower
@@ -1,13 +1,14 @@
#!/bin/sh
if [ "$MENUCMD" = "tofi" ]
then
- menucmd="tofi --width 10% --height 10% --padding-left 2%"
+ menucmd="tofi --width 10% --height 13% --padding-left 2%"
elif [ "$MENUCMD" = "dmenu" ]
then
- menucmd="dmenu -g 2 -l 1"
+ menucmd="dmenu -g 2 -l 2"
else
menucmd="fzf"
fi
-choice="$(echo "poweroff\nreboot\nhibernate" | $menucmd)"
-test -z "$choice" || doas "$choice"
+choices="poweroff\nreboot\nhibernate\nsuspend"
+choice="$(printf "$choices" | $menucmd)"
+test -z "$choice" || systemctl "$choice"
diff --git a/bin/serverscripts/dlcons b/bin/serverscripts/dlcons
new file mode 100755
index 0000000..69d9484
--- /dev/null
+++ b/bin/serverscripts/dlcons
@@ -0,0 +1,2 @@
+#!/bin/sh
+docker exec -it deluge deluge-console -c /config