summaryrefslogtreecommitdiff
path: root/old
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 /old
parent32d34ac9c5e3b682800f65f24743f2f29af04347 (diff)
downloadscripts-1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68.tar.xz
scripts-1ffe58f3ee6eeb2d81729eb7c458a8979eb2df68.zip
moved many scripts around, small tweaks/rewrites, mounter verify xsudo and xclick scripts
Diffstat (limited to 'old')
-rwxr-xr-xold/memuse33
-rwxr-xr-xold/mnt11
-rwxr-xr-xold/netstat45
-rwxr-xr-xold/sb-internet24
-rwxr-xr-xold/sinkold48
-rwxr-xr-xold/umnt8
-rwxr-xr-xold/virt31
7 files changed, 200 insertions, 0 deletions
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> ...] (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