summaryrefslogtreecommitdiff
path: root/misc
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 /misc
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 'misc')
-rwxr-xr-xmisc/cprs2
-rwxr-xr-xmisc/lsdu12
-rwxr-xr-xmisc/mksh8
-rwxr-xr-xmisc/passwdgen2
-rwxr-xr-xmisc/setup2
-rwxr-xr-xmisc/verify60
6 files changed, 72 insertions, 14 deletions
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