summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2022-01-20 17:07:39 -0600
committerTimmy Keller <tjk@tjkeller.xyz>2022-01-20 17:07:39 -0600
commit1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68 (patch)
treeabf5bd1cfa67232bc349174135814e316be3de3b
parent32d34ac9c5e3b682800f65f24743f2f29af04347 (diff)
downloadscripts-1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68.tar.xz
scripts-1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68.zip
moved many scripts around, small tweaks/rewrites, mounter verify xsudo and xclick scripts
-rwxr-xr-xinit/g610bl2
-rwxr-xr-xkeyboard/dmenunametag6
-rwxr-xr-xkeyboard/mounter64
-rwxr-xr-xkeyboard/screenshot6
-rwxr-xr-xkeyboard/shutdownprompt4
l---------launch/chrome1
-rwxr-xr-xlaunch/dmenu_runapp7
-rwxr-xr-xlaunch/emu5
-rwxr-xr-xlaunch/launch5
-rwxr-xr-xlaunch/tserv13
-rwxr-xr-xmisc/cprs2
-rwxr-xr-xmisc/lsdu12
-rwxr-xr-xmisc/mksh8
-rwxr-xr-xmisc/passwdgen2
-rwxr-xr-xmisc/setup2
-rwxr-xr-xmisc/verify60
-rwxr-xr-xold/memuse (renamed from bar/memuse)0
-rwxr-xr-xold/mnt (renamed from keyboard/mnt)0
-rwxr-xr-xold/netstat (renamed from bar/netstat)0
-rwxr-xr-xold/sb-internet (renamed from bar/sb-internet)0
-rwxr-xr-xold/sinkold (renamed from sync/sinkold)0
-rwxr-xr-xold/umnt (renamed from keyboard/umnt)0
-rwxr-xr-xold/virt (renamed from launch/virt)1
-rwxr-xr-xsync/sink1
-rwxr-xr-xx11/testtimmywm1
-rwxr-xr-xx11/xclick7
-rwxr-xr-xx11/xsudo7
-rwxr-xr-xx11/xvsync2
28 files changed, 169 insertions, 49 deletions
diff --git a/init/g610bl b/init/g610bl
new file mode 100755
index 0000000..973e31b
--- /dev/null
+++ b/init/g610bl
@@ -0,0 +1,2 @@
+#!/bin/sh
+#g610-led -fx color keys 20 && g610-led -k logo 00
diff --git a/keyboard/dmenunametag b/keyboard/dmenunametag
index 82c59ad..0458c79 100755
--- a/keyboard/dmenunametag
+++ b/keyboard/dmenunametag
@@ -7,9 +7,9 @@ while !([ $tagnum -ge 1 2>/dev/null ] && [ $tagnum -le $numtags ]); do
[ "$tagnum" = "" ] && exit
done
name="$(echo -n "$defnames" | dmenu -p "Rename tag $tagnum to: ")"
-[ "$name" != "$rcn" ] \
- && nametag $tagnum n "$name" \
- || nametag $tagnum r
+[ "$name" = "$rcn" ] \
+ && nametag $tagnum r \
+ || nametag $tagnum n "$name"
# Force bar to update by setting the root name to itself since there is currently a bug in the window manager
#xsetroot -name "$(xprop -root WM_NAME | sed -n 's/^WM_NAME(STRING) = \"\(.*\)\"/\1/p')"
diff --git a/keyboard/mounter b/keyboard/mounter
new file mode 100755
index 0000000..d45e0b9
--- /dev/null
+++ b/keyboard/mounter
@@ -0,0 +1,64 @@
+#!/bin/sh
+# TODO: add support for mounting discs
+sudo=doas
+mps=/media/mnt # User should have ownership of this directory
+notify='notify-send --urgency low'
+
+devexist() { [ -z $1 ] || ([ ! -e "$1" ] && $notify "Device $1 does not exist!") && exit 1; }
+
+mnt() {
+ # Select a device with unmounted partitions
+ awk_printdisks='
+ /^disk/ { diskinfo = $2 " " toupper($3) " Device \"" substr($0, i ? i : i = index($0, $5)) "\" (" $4 ")" } # Fifth field is label since mp is null
+ /^part/ && !$4 && diskinfo { print diskinfo; diskinfo = "" } # Fourth field is the mp since type is null
+ '
+ sed_getdev='s/.*" (\(.*\))$/\/dev\/\1/; s/.* /\/dev\//'
+ devexist ${disk=$(lsblk -no TYPE,SIZE,TRAN,KNAME,MOUNTPOINT,MODEL | awk "$awk_printdisks" | dmenu -p 'Disk: ' | sed "$sed_getdev")}
+
+ # Select an unmounted partition
+ awk_printparts='/^part\s*[0-9]/ { print $2 " " toupper($3) " Partition " ($5 ? "\"" substr($0, i ? i : i = index($0, $5)) "\" (" $4 ")" : $4) }'
+ devexist ${part=$(lsblk -no TYPE,MOUNTPOINT,SIZE,FSTYPE,KNAME,LABEL $disk | awk "$awk_printparts" | dmenu -p 'Mount partition: ' | sed "$sed_getdev")}
+
+ # Create a mountpoint automatically
+ awk_mpname='{ print $3 ? substr($0, index($0, $3)) : $1 " " toupper($2) " Volume" }'
+ mp="$mps/$(lsblk -no SIZE,FSTYPE,LABEL $part | awk "$awk_mpname")"
+ [ -e "$mp" ] && mp="$mp $(lsblk -no PARTUUID $part)"
+ mkdir -p "$mp"
+
+ # Handle filesystem cases
+ case `lsblk -no FSTYPE $part` in
+ vfat) opts="-o rw,umask=0000" ;;
+ exfat) opts="-o uid=$(id -u),gid=$(id -g)" ;;
+ esac
+
+ # Mount the partition
+ mountout="`$sudo mount $part "$mp" $opts 2>&1`" \
+ && $notify "Device Successfully Mounted" "Mounted \"$part\" to \"$mp\"" \
+ || $notify "Error Mounting Device \"$part\" to \"$mp\"" "$mountout"
+}
+
+umnt() {
+ # Exclude mountpoints from /etc/fstab
+ awk_fstabmps='!/$^/ && !/^#/ { gsub(/\//, "\\/"); regex = (regex ? regex "|" : "") $2 "$" } END { print regex }'
+ excludere="$(awk "$awk_fstabmps" /etc/fstab)"
+
+ # Select a partition to unmount
+ awk_mpname='$2 &&'"!/$excludere/"'{ print $1 " on " substr($0, index($0, $2)) }'
+ selpart="$(lsblk -no KNAME,MOUNTPOINT | awk "$awk_mpname" | dmenu -p 'Unmount Partition: ')"
+ devexist ${part=$(echo "$selpart" | sed 's/^/\/dev\//; s/ .*//')}
+ mp="$(echo "$selpart" | cut -d' ' -f3-)"
+
+ # Unmount the partition
+ umountout="`$sudo umount -A $part`" \
+ && $notify "Device Successfully Unmounted" "Unmounted \"$part\" from \"$mp\"" \
+ || $notify "Error Unmounting Device \"$part\" from \"$mp\"" "$umountout"
+
+ # Remove mp directory if it is in mps
+ [ "$(echo "$mp" | cut -c1-$(expr `echo $mps | wc -m` - 1))" = $mps ] && rm -rf "$mp"
+}
+
+case $1 in
+ -m) mnt ;;
+ -u) umnt ;;
+ *) echo "Usage: $(basename "$0") [-m|-u]\n\nOPTIONS:\n -m\tMount mode\n -u\tUnmount mode"; exit 2 ;;
+esac
diff --git a/keyboard/screenshot b/keyboard/screenshot
index 909dbe6..f0d0fff 100755
--- a/keyboard/screenshot
+++ b/keyboard/screenshot
@@ -1,7 +1,7 @@
#!/bin/sh
-printusage() { echo -n "Usage: $0 [-cx]\nOptions:\n-c\tInteractively crop screenshot\n-x\tCopy screenshot to clipboard with xclip rather than saving it\n" && exit; }
+printusage() { echo "Usage: $(basename "$0") [-cx]\n\nOPTIONS:\n -c\tInteractively crop screenshot\n -x\tCopy screenshot to clipboard with xclip rather than saving it" && exit; }
-# scrot and xclip opts
+# Scrot and xclip opts
fmt=$(date '+%m-%d-%4Y_%I:%M:%S_%p.png')
tmppath=/tmp/$fmt
savpath=~/pics/screenshots/$fmt
@@ -10,7 +10,7 @@ cropopt='--select --freeze'
normexp='echo $f'
xclipexp='xclip -selection clipboard -target image/png -i $f && echo $f'
-# notify-send opts
+# Notify-send opts
notifyopts="--expire-time 4000 --urgency low"
normsumm="Screenshot Saved!"
xclipsumm="Screenshot Copied!"
diff --git a/keyboard/shutdownprompt b/keyboard/shutdownprompt
index 2b97be1..b56268d 100755
--- a/keyboard/shutdownprompt
+++ b/keyboard/shutdownprompt
@@ -1,6 +1,6 @@
#!/bin/sh
-#option=`echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " -nb "#AA0000" -nf "#FFF" -sb "#FF0000" -sf "#FFF" || exit` # Run this separately from the case statement so dmenu prompt closes before running the command
-[ -n "$1" ] && option="$1" || option=`echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " -nb "#AA0000" -nf "#FFF" -sb "#FF0000" -sf "#FFF" -nhb "#AA0000" -shb "#FF0000" -shf "#FAA" || exit` # Run this separately from the case statement so dmenu prompt closes before running the command
+dmenucolors='-nb #AA0000 -nf #FFF -sb #FF0000 -sf #FFF'
+[ -n "$1" ] && option="$1" || option=$(echo "Cancel\nSuspend\nShutdown\nRestart" | dmenu -p "Power Menu " $dmenucolors || exit)
case $option in
Suspend) launch zzz ;;
Shutdown) launch off ;;
diff --git a/launch/chrome b/launch/chrome
deleted file mode 120000
index 1fcdd6b..0000000
--- a/launch/chrome
+++ /dev/null
@@ -1 +0,0 @@
-../../lib/ungoogled-chromium/chrome \ No newline at end of file
diff --git a/launch/dmenu_runapp b/launch/dmenu_runapp
index 2de77f4..a2d8fb8 100755
--- a/launch/dmenu_runapp
+++ b/launch/dmenu_runapp
@@ -1,5 +1,4 @@
#!/bin/sh
-apps=/usr/share/applications
-name="$(grep -h -m1 '^Name=' $apps/* | cut -d'=' -f2- | sort | uniq | dmenu "$@")"
-#$(grep '^Exec=[^%]*' -o -m1 $(grep -l -m1 "$name" $apps/*) | cut -d'=' -f2-) &
-gtk-launch $(basename `grep -l -m1 "$name" $apps/*` .desktop) &
+apps="$(echo $XDG_DATA_DIRS: | sed 's/:/\/applications\/*.desktop /g')"
+name="$(grep -Rhm1 '^Name=' $apps 2>/dev/null | cut -d'=' -f2- | sort | uniq | dmenu "$@")"
+[ -n "$name" ] && gtk-launch $(basename `grep -Rlm1 "^Name=$name" $apps 2>/dev/null`) &
diff --git a/launch/emu b/launch/emu
index 7f9c8ec..fe17ed7 100755
--- a/launch/emu
+++ b/launch/emu
@@ -1,9 +1,8 @@
#!/bin/sh
-
# This only works for collections with a common extension. You can rename all your roms to use the same extension and (in any decent emulator at least) they should work regardless of the actual header type
gamedir=${XDG_DATA_HOME:-$HOME/.local/share}/games
dmenuprompt="dmenu -l 25"
-resolution() { cat /sys/class/drm/*/modes | head -1 }
+resolution() { cat /sys/class/drm/*/modes | head -1; }
case "$1" in
2600)
dmenucolors="-nb #111 -nf #e4963c -sb #6c3b17 -sf #fff -nhb #121212 -nhf #fc5231 -shb #804f2d -shf #fc5231"
@@ -41,7 +40,7 @@ case "$1" in
ext=nds
;;
*)
- console=`ls $gamedir | dmenu -l 25` && ($0 $console || emu) # Allows going back to select a different console
+ console=`ls $gamedir | dmenu -l 25` && ($0 $console || $0) # Allows going back to select a different console
exit
;;
esac
diff --git a/launch/launch b/launch/launch
index cb06b1d..22a2bce 100755
--- a/launch/launch
+++ b/launch/launch
@@ -54,10 +54,10 @@ gencache() {
if (cmd ~ hosts[host] && cmds[cmd] && cmds[cmd] != "-") {
i = cmd
sub(/.*:/, "", cmd)
- print "\t"cmd") "cmds[i]" \"$@\" ;;"
+ print "\t"cmd") "cmds[i]" \"$@\" & ;;"
}
}
- print "\t*) exit 1 ;;"
+ print "\t*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;"
print "esac"
}
}
@@ -90,5 +90,4 @@ case "$1" in
esac
# Run
-#sh $cache "$@" || "$@" || echo "$(me): $@: Does not exist or exited with an error" &
exec $cache "$@"
diff --git a/launch/tserv b/launch/tserv
deleted file mode 100755
index 5e0d072..0000000
--- a/launch/tserv
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-server=~/.local/share/Terraria/server/TerrariaServer.bin.x86_64
-#wldnum=1
-
-$server
-#$server << CMDS
-#$wldnum
-#16
-#7777
-#n
-#
-#say hello
-#CMDS
diff --git a/misc/cprs b/misc/cprs
index c9b99c2..f8ab27c 100755
--- a/misc/cprs
+++ b/misc/cprs
@@ -1,2 +1,2 @@
#!/bin/sh
-tar cvzf "$(echo $1 | sed 's/\/$//').tar.gz" "$1"
+tar cvf - "$1" | pv -s $(du -sb "$1" | cut -f1) | gzip > "$(echo $1 | sed 's/\/$//').tar.gz"
diff --git a/misc/lsdu b/misc/lsdu
index 9b1295a..ef3eb97 100755
--- a/misc/lsdu
+++ b/misc/lsdu
@@ -1,7 +1,7 @@
#!/bin/sh
-for file in $(ls -a); do
- ([ "$file" = "." ] || [ "$file" = ".." ]) && continue
- files="${files:+$files\n}$(du -h "$file" 2>/dev/null | tail -1)"
-done
-echo "$files" | sort -h
-
+du -ah -d1 "$@" 2>/dev/null | sed 's/\.\///' | sort -h
+#for file in $(ls -a $1); do
+# ([ "$file" = "." ] || [ "$file" = ".." ]) && continue
+# files="${files:+$files\n}$(du -h $1/"$file" 2>/dev/null | tail -1)"
+#done
+#echo "$files" | sort -h
diff --git a/misc/mksh b/misc/mksh
index 6cb5fd6..4b94652 100755
--- a/misc/mksh
+++ b/misc/mksh
@@ -1,11 +1,9 @@
#!/bin/sh
# Sorry in advance to 'mksh' users (users of the shell, not this script)
-newname() { defname="script"; name=$defname`ls | grep "^$defname[0-9]*" | wc -l | tr -d '[:blank:]'`; } # Remove blank space for certain non-GNU wc implementations
+newname() { defname="script"; name=$defname`ls | grep "^$defname[0-9]*" | wc -l | tr -d '[:blank:]'`; } # Remove blank space in certain non-GNU implementations of wc
[ -z "$1" ] && newname || name="$1"
+[ -e "$name" ] && echo "File $name exists!" && exit 1
[ -z "$2" ] && shebang="#!/bin/sh" || shebang="$2"
-touch "$name"
-echo "$shebang" > "$name"
-chmod +x "$name"
-$EDITOR "$name" || vim "$name" || vi "$name" || nano "$name" || ed "$name" # Try editors lol
+echo "$shebang" > "$name" && chmod +x "$name" && $EDITOR "$name"
# Delete file if it is just exited w/o being changed
[ "`cat "$name"`" = "$shebang" ] && rm "$name" && echo "Removed empty script \"$name\"" || echo "Saved script \"$name\""
diff --git a/misc/passwdgen b/misc/passwdgen
index 89318d0..ce67c92 100755
--- a/misc/passwdgen
+++ b/misc/passwdgen
@@ -1,5 +1,5 @@
#!/bin/sh
-[ -n "`echo $1$2 | tr -d '[:digit:]'`" ] && echo "Usage: $0 [Itterations] [Length] [Set]" && exit
+[ -n "`echo $1$2 | tr -d '[:digit:]'`" ] && echo "Usage: $0 [Itterations] [Length] [Character Set]" && exit
[ -z "$1" ] && itt=5 || itt=$1
[ -z "$2" ] && len=20 || len=$2
[ -z "$3" ] && set='[:graph:]' || set=$3
diff --git a/misc/setup b/misc/setup
index af83177..eaeec39 100755
--- a/misc/setup
+++ b/misc/setup
@@ -28,7 +28,7 @@ Icon=gtk-dialog-authentication
[X-Action-Profile profile-zero]
MimeTypes=inode/directory;
-Exec=/usr/bin/doas /usr/bin/pcmanfm %u
+Exec=/home/timmy/.local/bin/x11/xsudo /usr/bin/pcmanfm %u
Name=Default profile" > $pcmanfmroot/root.desktop
}
diff --git a/misc/verify b/misc/verify
new file mode 100755
index 0000000..0d17085
--- /dev/null
+++ b/misc/verify
@@ -0,0 +1,60 @@
+#!/bin/sh
+NORM="\033[0m"
+CYN="\033[0;36m"
+GRN="\033[0;32m"
+RED="\033[0;31m"
+printhelp() {
+echo "\
+Usage: $(basename "$0") [options] [file/directory]...
+
+OPTIONS:
+ -m, --md5 Create/verify md5 checksum
+ -s[alg], --sha[alg] Create/verify sha checksum
+ -x[alg], --xxh[alg] Create/verify xxh checksum
+ -c [alg], --crypt [alg] Create/verify [alg] checksum (uses [alg]sum)
+ -v, --verify Verify files with existing checksums
+ -h, --help Print help \
+";
+}
+crypt=xxh
+while true; do
+ case "$1" in
+ -m|--md5) crypt=md5 ;;
+ -s*|--sha*) crypt=sha$(echo "$1" | tr -cd [:digit:]) ;;
+ -x*|--xxh*) crypt=xxh$(echo "$1" | tr -cd [:digit:]) ;;
+ -c|--crypt) crypt=$2 && shift ;; # Shift twice
+ -v|--verify) verify=1 ;;
+ -h|--help) printhelp; exit 0 ;;
+ -*) printhelp; exit 2 ;;
+ *) break ;;
+ esac
+ shift
+done
+hashalg=${crypt}sum # Works for current algs
+command -v $hashalg >/dev/null || (echo "Hashing algorithm '$hashalg' does not exist!" && exit 2)
+
+while [ -n "$1" ]; do
+ file="$1"
+ [ ! "`echo "$file" | sed "s/.$crypt$//"`" = "$file" ] && shift && continue # Skip hash files
+ [ ! -e "$file" ] && echo "file '$file' does not exist!" && exit 1
+ [ -d "$file" ] && type=directory || type=file
+ hashfile="$file.$crypt"
+ [ -n "$verify" ] && [ ! -e "$hashfile" ] && shift && continue # Skip files without a hash in verify mode
+
+ echo "Getting $crypt checksum of $type '$file'..."
+ hash=`find "$file" -type f -print0 | sort -z | xargs -r0 pv -EE -F'%r [%b] [%t] [%e] %p' | $hashalg | cut -d' ' -f1`
+
+ if [ -e "$hashfile" ]; then
+ phash=`cat "$hashfile"`
+ [ $phash = $hash ] \
+ && echo "${GRN}Success: $type matches saved checksum!" \
+ || (echo "${RED}Error: $type does not match saved checksum!\nExpected checksum: $phash\nActual checksum: $hash" && ec=1)
+ else
+ echo $hash > "$hashfile" \
+ && echo "${CYN}$crypt checksum file saved at '$hashfile'!" \
+ || (echo "${RED}'$hashfile' could not be created!\n$crypt checksum of $type '$file' is $hash" && ec=1)
+ fi
+ printf "$NORM"; [ -n "$2" ] && echo
+ shift
+done
+exit $ec
diff --git a/bar/memuse b/old/memuse
index eb9ffde..eb9ffde 100755
--- a/bar/memuse
+++ b/old/memuse
diff --git a/keyboard/mnt b/old/mnt
index 7547912..7547912 100755
--- a/keyboard/mnt
+++ b/old/mnt
diff --git a/bar/netstat b/old/netstat
index e7b23c3..e7b23c3 100755
--- a/bar/netstat
+++ b/old/netstat
diff --git a/bar/sb-internet b/old/sb-internet
index ee1a160..ee1a160 100755
--- a/bar/sb-internet
+++ b/old/sb-internet
diff --git a/sync/sinkold b/old/sinkold
index 3022963..3022963 100755
--- a/sync/sinkold
+++ b/old/sinkold
diff --git a/keyboard/umnt b/old/umnt
index 8191047..8191047 100755
--- a/keyboard/umnt
+++ b/old/umnt
diff --git a/launch/virt b/old/virt
index 9706106..6d9f252 100755
--- a/launch/virt
+++ b/old/virt
@@ -15,6 +15,7 @@ startvm() {
-soundhw all \
-boot menu=on \
-drive file="$virtdir/$1.img" \
+ -drive file=~/docs/oss/openbsd7.0.img \
; }
#-vga none \
#-nographic \
diff --git a/sync/sink b/sync/sink
index 9ce49d7..b11b492 100755
--- a/sync/sink
+++ b/sync/sink
@@ -1,5 +1,4 @@
#!/bin/sh
-
printusage() { echo "Usage: $0 [<repos> ...] (repos: all,`echo $repos | tr ' ' ','`) [up|down]" && exit; }
repos="docs patches"
diff --git a/x11/testtimmywm b/x11/testtimmywm
index 330a328..33cda37 100755
--- a/x11/testtimmywm
+++ b/x11/testtimmywm
@@ -1,5 +1,4 @@
#!/bin/sh
-
Xephyr -br -ac -reset -screen 2160x1440 :1 &
sleep 1
export DISPLAY=:1
diff --git a/x11/xclick b/x11/xclick
new file mode 100755
index 0000000..3b05b38
--- /dev/null
+++ b/x11/xclick
@@ -0,0 +1,7 @@
+#!/bin/sh
+pkill xdotool && echo 'Killed old xclick process! Exiting...' && exit 0
+
+delay=${1:-`seq 500 500 10000 | dmenu -p 'Delay between clicks (in milliseconds): '`}
+click=${2:-`seq -f'Button %g' 5 | dmenu -p 'Mouse click: ' | tr -cd '[:digit:]'`}
+
+xdotool click --delay $delay --repeat 2147483647 $click # signed 32-bit integer limit is probably enough clicks since xdotool doesn't have an infinite repeat option
diff --git a/x11/xsudo b/x11/xsudo
new file mode 100755
index 0000000..5feabb1
--- /dev/null
+++ b/x11/xsudo
@@ -0,0 +1,7 @@
+#!/bin/sh
+sudo=doas
+while ! echo "$pass" | $sudo -n true; do
+ pass="$(dmenu -p 'Password: ' <&-)" # Ask user for password pass is incorrect (skipped if nopass in enabled)
+ [ "$pass" = '' ] && exit 0
+done
+echo "$pass" | $sudo xauth -f /root/.Xauthority add $(xauth list $DISPLAY) && echo "$pass" | $sudo "$@"
diff --git a/x11/xvsync b/x11/xvsync
index e80edab..0d5cd5c 100755
--- a/x11/xvsync
+++ b/x11/xvsync
@@ -1,5 +1,5 @@
#!/bin/sh
# Since this script runs xrandr to get the connected monitors, it is unnecessary to run xrandr by itself in your xinitrc
for monitor in `xrandr | sed -n 's/ connected.*//p'`; do
- #xrandr --output $monitor --set TearFree ${1:-on}
+ xrandr --output $monitor --set TearFree ${1:-on}
done