From 1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68 Mon Sep 17 00:00:00 2001 From: Timmy Keller Date: Thu, 20 Jan 2022 17:07:39 -0600 Subject: moved many scripts around, small tweaks/rewrites, mounter verify xsudo and xclick scripts --- bar/memuse | 33 ------------------------- bar/netstat | 45 ---------------------------------- bar/sb-internet | 24 ------------------- init/g610bl | 2 ++ keyboard/dmenunametag | 6 ++--- keyboard/mnt | 11 --------- keyboard/mounter | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ keyboard/screenshot | 6 ++--- keyboard/shutdownprompt | 4 ++-- keyboard/umnt | 8 ------- launch/chrome | 1 - launch/dmenu_runapp | 7 +++--- launch/emu | 5 ++-- launch/launch | 5 ++-- launch/tserv | 13 ---------- launch/virt | 30 ----------------------- misc/cprs | 2 +- misc/lsdu | 12 +++++----- misc/mksh | 8 +++---- misc/passwdgen | 2 +- misc/setup | 2 +- misc/verify | 60 ++++++++++++++++++++++++++++++++++++++++++++++ old/memuse | 33 +++++++++++++++++++++++++ old/mnt | 11 +++++++++ old/netstat | 45 ++++++++++++++++++++++++++++++++++ old/sb-internet | 24 +++++++++++++++++++ old/sinkold | 48 +++++++++++++++++++++++++++++++++++++ old/umnt | 8 +++++++ old/virt | 31 ++++++++++++++++++++++++ sync/sink | 1 - sync/sinkold | 48 ------------------------------------- x11/testtimmywm | 1 - x11/xclick | 7 ++++++ x11/xsudo | 7 ++++++ x11/xvsync | 2 +- 35 files changed, 368 insertions(+), 248 deletions(-) delete mode 100755 bar/memuse delete mode 100755 bar/netstat delete mode 100755 bar/sb-internet create mode 100755 init/g610bl delete mode 100755 keyboard/mnt create mode 100755 keyboard/mounter delete mode 100755 keyboard/umnt delete mode 120000 launch/chrome delete mode 100755 launch/tserv delete mode 100755 launch/virt create mode 100755 misc/verify create mode 100755 old/memuse create mode 100755 old/mnt create mode 100755 old/netstat create mode 100755 old/sb-internet create mode 100755 old/sinkold create mode 100755 old/umnt create mode 100755 old/virt delete mode 100755 sync/sinkold create mode 100755 x11/xclick create mode 100755 x11/xsudo diff --git a/bar/memuse b/bar/memuse deleted file mode 100755 index eb9ffde..0000000 --- a/bar/memuse +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/awk -f -function getvar(label) { - while (getline < meminfo && $1 != label":"); - return $2 -} - -BEGIN { - meminfo="/proc/meminfo" - - # Make sure these are in order of the output of /proc/meminfo - memtotal = getvar("MemTotal") - memfree = getvar("MemFree") - buffers = getvar("Buffers") - cached = getvar("Cached") - shmem = getvar("Shmem") - sreclaimable = getvar("SReclaimable") - - # Htop calculations - totalused = memtotal - memfree - totalcached = cached + sreclaimable - shmem - noncachenonbuf = totalused - (buffers + totalcached) - - # Print % of memory used - print int((noncachenonbuf * 100) / memtotal)"%" -} - -#BEGIN { -# cmd="free -b" -# cmd | getline -# cmd | getline -# print int($3*100/$2)"%" -#} -##awk '{ if(!total){ total = $2 } else if(!free){ free = $2 } else{ exit } } END{ print int(((total-free)*100)/total)"%" }' /proc/meminfo diff --git a/bar/netstat b/bar/netstat deleted file mode 100755 index e7b23c3..0000000 --- a/bar/netstat +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/awk -f - -BEGIN { -wifidev=ENVIRON["WIFIDEV"] -ethedev=ENVIRON["ETHEDEV"] -getline state < ("/sys/class/net/"ethedev"/operstate") -switch (state) { - case "up": - print "񂁭" - break - case "down": - getline state < ("/sys/class/net/"wifidev"/operstate") - switch (state) { - case "up": - # make this nicer, obviously - getline < "/proc/net/wireless" - getline < "/proc/net/wireless" - getline < "/proc/net/wireless" - sigstrength=int($3 * 100 / 70) - if (sigstrength > 70) { - print "񂁬 " sigstrength "%" - } - else if (sigstrength > 40) { - print "񂁫 " sigstrength "%" - } - else if (sigstrength > 10) { - print "񂁪 " sigstrength "%" - } - else { - print "񂁩 " sigstrength "%" - } - break - case "down": - print "񂁮" - break - default: - print "Device "wifidev" not found..." - break - } - break - default: - print "Device "ethedev" not found..." - break -} -} diff --git a/bar/sb-internet b/bar/sb-internet deleted file mode 100755 index ee1a160..0000000 --- a/bar/sb-internet +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -# Show wifi 📶 and percent strength or 📡 if none. -# Show 🌐 if connected to ethernet or ❎ if none. -# Show 🔒 if a vpn connection is active - -case $BLOCK_BUTTON in - 1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; - 3) notify-send "🌐 Internet module" "\- Click to connect -📡: no wifi connection -📶: wifi connection with quality -❎: no ethernet -🌐: ethernet working -🔒: vpn is active -" ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; -esac - -case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in - down) wifiicon="📡 " ;; - up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; -esac - -printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" 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/mnt b/keyboard/mnt deleted file mode 100755 index 7547912..0000000 --- a/keyboard/mnt +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# '/part\s*$\|rom\s*$/!d; s/\s*[^[:space:]]*\s*$/\)/; s/\s/ \(/' # More correct in my opinion, but slower -if partition=`lsblk -npro "name,size,type,mountpoint" | sed '/part $\|rom $/!d; s/ [a-z]* $/\)/; s/ / \(/' | dmenu -p "Choose drive to mount: " | cut -d' ' -f1` \ -&& [ -n "$partition" ] \ -&& mountpoint=`ls -d /media/mnt/slot*/ | dmenu -p "Choose mountpoint: "` \ -&& [ -n "$mountpoint" ] -then - doas mount "$partition" "$mountpoint"; user="$(whoami)"; ug="$(groups | cut -d' ' -f1)"; doas chown "$user":"$ug" "$mountpoint" \ - && notify-send --urgency low "Device Successfully Mounted" "Successfully Mounted partition \"$partition\" to mountpoint \"$mountpoint\"" \ - || notify-send --urgency low "Error Mounting Device" "Could not mount partition \"$partition\" to mountpoint \"$mountpoint\"" -fi 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/keyboard/umnt b/keyboard/umnt deleted file mode 100755 index 8191047..0000000 --- a/keyboard/umnt +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -exclude='\/efi$|\/boot$|\/home$|tbhdd$|\/$' -if mountedpartition=`lsblk --noheadings --paths --raw | awk "/part .+/ && !/$exclude/ "'{ print $1, "(on", $7 ")" }' | dmenu -p "Unmount Device... "` -then - doas umount -A "`echo $mountedpartition | sed 's/ .*//'`" \ - && notify-send --urgency low "Device Successfully Unmounted" "Partition \"$mountedpartition\" successfully unmounted" --time 120000 \ - || notify-send --urgency low "Error Unmounting Device" "Could not unmount partition \"$mountedpartition\"" -fi 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/launch/virt b/launch/virt deleted file mode 100755 index 9706106..0000000 --- a/launch/virt +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -virtdir=~/.local/share/virt - -halfram() { awk '/^MemTotal/ { printf "%dM\n", $2/2/1024 }' /proc/meminfo; } # Needs to be either in M or G according to man page -halfthreads() { echo $(( $(nproc) / 2 )); } -startvm() { - qemu-system-x86_64 \ - -enable-kvm \ - -cpu host \ - -m $(halfram) \ - -smp $(halfthreads) \ - -net nic \ - -display sdl,gl=on \ - -audiodev pa,id=pa1,server=/run/user/1000/pulse/native \ - -soundhw all \ - -boot menu=on \ - -drive file="$virtdir/$1.img" \ -; } - #-vga none \ - #-nographic \ - -vms="$(ls $virtdir)" - -[ -n "$1" ] && vm="$1" || vm=$(echo "$vms" | sed 's/\.img//' | dmenu -p "Choose Virtual Machine Image or Enter Name for New Virtual Machine") - -if echo "$vms" | grep "^$vm.img$" >/dev/null; then - startvm "$vm" -else - qemu-img create -f qcow2 "$virtdir/$vm.img" $(echo -n "4G\n8G\n16G\n32G" | dmenu -p "Choose Size of Virtual Machine \"$vm\"") -fi 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/old/memuse b/old/memuse new file mode 100755 index 0000000..eb9ffde --- /dev/null +++ b/old/memuse @@ -0,0 +1,33 @@ +#!/usr/bin/awk -f +function getvar(label) { + while (getline < meminfo && $1 != label":"); + return $2 +} + +BEGIN { + meminfo="/proc/meminfo" + + # Make sure these are in order of the output of /proc/meminfo + memtotal = getvar("MemTotal") + memfree = getvar("MemFree") + buffers = getvar("Buffers") + cached = getvar("Cached") + shmem = getvar("Shmem") + sreclaimable = getvar("SReclaimable") + + # Htop calculations + totalused = memtotal - memfree + totalcached = cached + sreclaimable - shmem + noncachenonbuf = totalused - (buffers + totalcached) + + # Print % of memory used + print int((noncachenonbuf * 100) / memtotal)"%" +} + +#BEGIN { +# cmd="free -b" +# cmd | getline +# cmd | getline +# print int($3*100/$2)"%" +#} +##awk '{ if(!total){ total = $2 } else if(!free){ free = $2 } else{ exit } } END{ print int(((total-free)*100)/total)"%" }' /proc/meminfo diff --git a/old/mnt b/old/mnt new file mode 100755 index 0000000..7547912 --- /dev/null +++ b/old/mnt @@ -0,0 +1,11 @@ +#!/bin/sh +# '/part\s*$\|rom\s*$/!d; s/\s*[^[:space:]]*\s*$/\)/; s/\s/ \(/' # More correct in my opinion, but slower +if partition=`lsblk -npro "name,size,type,mountpoint" | sed '/part $\|rom $/!d; s/ [a-z]* $/\)/; s/ / \(/' | dmenu -p "Choose drive to mount: " | cut -d' ' -f1` \ +&& [ -n "$partition" ] \ +&& mountpoint=`ls -d /media/mnt/slot*/ | dmenu -p "Choose mountpoint: "` \ +&& [ -n "$mountpoint" ] +then + doas mount "$partition" "$mountpoint"; user="$(whoami)"; ug="$(groups | cut -d' ' -f1)"; doas chown "$user":"$ug" "$mountpoint" \ + && notify-send --urgency low "Device Successfully Mounted" "Successfully Mounted partition \"$partition\" to mountpoint \"$mountpoint\"" \ + || notify-send --urgency low "Error Mounting Device" "Could not mount partition \"$partition\" to mountpoint \"$mountpoint\"" +fi diff --git a/old/netstat b/old/netstat new file mode 100755 index 0000000..e7b23c3 --- /dev/null +++ b/old/netstat @@ -0,0 +1,45 @@ +#!/usr/bin/awk -f + +BEGIN { +wifidev=ENVIRON["WIFIDEV"] +ethedev=ENVIRON["ETHEDEV"] +getline state < ("/sys/class/net/"ethedev"/operstate") +switch (state) { + case "up": + print "񂁭" + break + case "down": + getline state < ("/sys/class/net/"wifidev"/operstate") + switch (state) { + case "up": + # make this nicer, obviously + getline < "/proc/net/wireless" + getline < "/proc/net/wireless" + getline < "/proc/net/wireless" + sigstrength=int($3 * 100 / 70) + if (sigstrength > 70) { + print "񂁬 " sigstrength "%" + } + else if (sigstrength > 40) { + print "񂁫 " sigstrength "%" + } + else if (sigstrength > 10) { + print "񂁪 " sigstrength "%" + } + else { + print "񂁩 " sigstrength "%" + } + break + case "down": + print "񂁮" + break + default: + print "Device "wifidev" not found..." + break + } + break + default: + print "Device "ethedev" not found..." + break +} +} diff --git a/old/sb-internet b/old/sb-internet new file mode 100755 index 0000000..ee1a160 --- /dev/null +++ b/old/sb-internet @@ -0,0 +1,24 @@ +#!/bin/sh + +# Show wifi 📶 and percent strength or 📡 if none. +# Show 🌐 if connected to ethernet or ❎ if none. +# Show 🔒 if a vpn connection is active + +case $BLOCK_BUTTON in + 1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; + 3) notify-send "🌐 Internet module" "\- Click to connect +📡: no wifi connection +📶: wifi connection with quality +❎: no ethernet +🌐: ethernet working +🔒: vpn is active +" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in + down) wifiicon="📡 " ;; + up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; +esac + +printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" diff --git a/old/sinkold b/old/sinkold new file mode 100755 index 0000000..3022963 --- /dev/null +++ b/old/sinkold @@ -0,0 +1,48 @@ +#!/bin/sh + +printusage() { echo "Usage: $0 [ ...] (repos: all,`echo $repos | tr ' ' ','`) [up|down]" && exit; } + +repos="docs patches" + +oper=`echo $@ | sed 's/.* //'` # Get last argument +([ -z $2 ] || ([ "$oper" != "up" ] && [ "$oper" != "down" ])) && printusage + +# rync options +#fix this too +ropts="--archive --partial --progress --recursive --update --verbose" # Equivalent to: -aPrvu --delete +rdest="tjkrsync@tjkeller.xyz:" + +# Colors +BOLD="\033[1m" +NORM="\033[0m" +CYN="\033[0;36m" +RED="\033[0;31m" +GRN="\033[0;32m" + +printsyncmsg() { echo -n "$CYN[Syncing $SYNCNAME...]$NORM\n"; } +printsuccess() { echo -n "$BOLD$GRN[Successfully synced $SYNCNAME]\n"; } +printerror() { echo -n "$BOLD$RED[An error occured while syncing $SYNCNAME]\n"; } + +sync() { + [ $oper = "up" ] && SYNCNAME="$1$2 to $rdest$2" || SYNCNAME="$rdest$2 to $1$2" + printsyncmsg + (if [ $oper = "up" ]; then rsync $ropts $1$2 $rdest; else rsync $ropts --delete $rdest$2 $1; fi) \ + && printsuccess || printerror +} + +# arg1 = options + containing directory path, arg2 = file/directory name +syncdocs() { destdir="" && sync "/home/timmy/docs/" "school"; } +#syncsites() { destdir="" && sync "--exclude=pass /home/timmy/.local/src/" "sites"; } # Excludes password file +syncpatches() { destdir="" && sync "--exclude=.git /home/timmy/.local/src/programs/" "patches"; } # Excludes git files + +for arg in "$@"; do + case $arg in + all) $0 $repos $oper ;; + up|down) oper=$arg ;; + *) # Would like to use something like $repos) here but cant + for repo in $repos; do + [ "$arg" = "$repo" ] && sync$arg && break + done || printusage + ;; + esac +done diff --git a/old/umnt b/old/umnt new file mode 100755 index 0000000..8191047 --- /dev/null +++ b/old/umnt @@ -0,0 +1,8 @@ +#!/bin/sh +exclude='\/efi$|\/boot$|\/home$|tbhdd$|\/$' +if mountedpartition=`lsblk --noheadings --paths --raw | awk "/part .+/ && !/$exclude/ "'{ print $1, "(on", $7 ")" }' | dmenu -p "Unmount Device... "` +then + doas umount -A "`echo $mountedpartition | sed 's/ .*//'`" \ + && notify-send --urgency low "Device Successfully Unmounted" "Partition \"$mountedpartition\" successfully unmounted" --time 120000 \ + || notify-send --urgency low "Error Unmounting Device" "Could not unmount partition \"$mountedpartition\"" +fi diff --git a/old/virt b/old/virt new file mode 100755 index 0000000..6d9f252 --- /dev/null +++ b/old/virt @@ -0,0 +1,31 @@ +#!/bin/sh +virtdir=~/.local/share/virt + +halfram() { awk '/^MemTotal/ { printf "%dM\n", $2/2/1024 }' /proc/meminfo; } # Needs to be either in M or G according to man page +halfthreads() { echo $(( $(nproc) / 2 )); } +startvm() { + qemu-system-x86_64 \ + -enable-kvm \ + -cpu host \ + -m $(halfram) \ + -smp $(halfthreads) \ + -net nic \ + -display sdl,gl=on \ + -audiodev pa,id=pa1,server=/run/user/1000/pulse/native \ + -soundhw all \ + -boot menu=on \ + -drive file="$virtdir/$1.img" \ + -drive file=~/docs/oss/openbsd7.0.img \ +; } + #-vga none \ + #-nographic \ + +vms="$(ls $virtdir)" + +[ -n "$1" ] && vm="$1" || vm=$(echo "$vms" | sed 's/\.img//' | dmenu -p "Choose Virtual Machine Image or Enter Name for New Virtual Machine") + +if echo "$vms" | grep "^$vm.img$" >/dev/null; then + startvm "$vm" +else + qemu-img create -f qcow2 "$virtdir/$vm.img" $(echo -n "4G\n8G\n16G\n32G" | dmenu -p "Choose Size of Virtual Machine \"$vm\"") +fi 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: all,`echo $repos | tr ' ' ','`) [up|down]" && exit; } repos="docs patches" diff --git a/sync/sinkold b/sync/sinkold deleted file mode 100755 index 3022963..0000000 --- a/sync/sinkold +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -printusage() { echo "Usage: $0 [ ...] (repos: all,`echo $repos | tr ' ' ','`) [up|down]" && exit; } - -repos="docs patches" - -oper=`echo $@ | sed 's/.* //'` # Get last argument -([ -z $2 ] || ([ "$oper" != "up" ] && [ "$oper" != "down" ])) && printusage - -# rync options -#fix this too -ropts="--archive --partial --progress --recursive --update --verbose" # Equivalent to: -aPrvu --delete -rdest="tjkrsync@tjkeller.xyz:" - -# Colors -BOLD="\033[1m" -NORM="\033[0m" -CYN="\033[0;36m" -RED="\033[0;31m" -GRN="\033[0;32m" - -printsyncmsg() { echo -n "$CYN[Syncing $SYNCNAME...]$NORM\n"; } -printsuccess() { echo -n "$BOLD$GRN[Successfully synced $SYNCNAME]\n"; } -printerror() { echo -n "$BOLD$RED[An error occured while syncing $SYNCNAME]\n"; } - -sync() { - [ $oper = "up" ] && SYNCNAME="$1$2 to $rdest$2" || SYNCNAME="$rdest$2 to $1$2" - printsyncmsg - (if [ $oper = "up" ]; then rsync $ropts $1$2 $rdest; else rsync $ropts --delete $rdest$2 $1; fi) \ - && printsuccess || printerror -} - -# arg1 = options + containing directory path, arg2 = file/directory name -syncdocs() { destdir="" && sync "/home/timmy/docs/" "school"; } -#syncsites() { destdir="" && sync "--exclude=pass /home/timmy/.local/src/" "sites"; } # Excludes password file -syncpatches() { destdir="" && sync "--exclude=.git /home/timmy/.local/src/programs/" "patches"; } # Excludes git files - -for arg in "$@"; do - case $arg in - all) $0 $repos $oper ;; - up|down) oper=$arg ;; - *) # Would like to use something like $repos) here but cant - for repo in $repos; do - [ "$arg" = "$repo" ] && sync$arg && break - done || printusage - ;; - esac -done 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 -- cgit v1.2.3