diff options
| author | Tim Keller <tjkeller.xyz> | 2024-11-17 23:34:54 -0600 | 
|---|---|---|
| committer | Tim Keller <tjkeller.xyz> | 2024-11-17 23:34:54 -0600 | 
| commit | 09ada24d4ec23cf24ab136141b354953d1bbc2fa (patch) | |
| tree | 2c41e87c71ad3f3cd67a8bea0c1413efbab4087d /misc | |
| parent | 090a3a31683eb08b91351e4d1508a0a73a310a38 (diff) | |
| download | scripts-09ada24d4ec23cf24ab136141b354953d1bbc2fa.tar.xz scripts-09ada24d4ec23cf24ab136141b354953d1bbc2fa.zip  | |
reorganize scripts
Diffstat (limited to 'misc')
| -rwxr-xr-x | misc/dnfu | 10 | ||||
| -rwxr-xr-x | misc/enablecoredumps | 3 | ||||
| -rwxr-xr-x | misc/launch | 110 | ||||
| -rwxr-xr-x | misc/verifoo | 110 | ||||
| -rwxr-xr-x | misc/wmip | 2 | 
5 files changed, 112 insertions, 123 deletions
diff --git a/misc/dnfu b/misc/dnfu deleted file mode 100755 index 9f6a9cb..0000000 --- a/misc/dnfu +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -sudo ln -sf /bin/bash /bin/sh - -sudo dnf update $@ - -sudo dnf remove $@ --oldinstallonly --setopt installonly_limit=2 kernel - -sudo dnf autoremove $@ - -sudo ln -sf /bin/dash /bin/sh diff --git a/misc/enablecoredumps b/misc/enablecoredumps deleted file mode 100755 index e435cc7..0000000 --- a/misc/enablecoredumps +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -ulimit -c unlimited -sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t diff --git a/misc/launch b/misc/launch new file mode 100755 index 0000000..5947ae7 --- /dev/null +++ b/misc/launch @@ -0,0 +1,110 @@ +#!/bin/sh +awk=awk +me() { basename "$0"; } + +printhelp() { +cat << HELPDOC +Usage: +  $(me): [-gh] [COMMAND] [COMMAND ARGS]... + +Args: +  -g, --gen-cache : Force generate cache +  -h, --help      : show this help message + +Config Syntax: +  +host [HOSTNAME] +    Add a new host. Hosts can be referenced using their number starting with 1. +  [COMMAND] +    launch [COMMAND] will start the process specified for the specific hostname. Aliases are separated by |. +  [TAB][SHELL] +    Run this shell command when the above [COMMAND] is specified. In order of hostnames. Can be a number to reference to a hostname, a '-' to disregard this command for the specific host, or a '^' to reference the previous command. +HELPDOC +} + +# Make sure user is using GNU Awk (gawk) +checkawk() { +	if ! ($awk -V >/dev/null 2>/dev/null && $awk -V | grep "GNU Awk" >/dev/null); then +		if command -v gawk > /dev/null; then +			awk=gawk +		else +			echo "$(me) requires GNU Awk (gawk) to function properly. Please install GNU Awk and try again." +			exit 0 +		fi +	fi +} + +gencache() { +$awk ' +BEGIN { +	print "run=\"$1\"; shift" +	print "case \"$run\" in" +} +{ +	sub(/#.*/, "") # Remove comments +	if (!/^\s*$/) { +		if (/^\+host/) { +			sub(/\s*\+host\s*/, "") +			h++ +			hosts[h] = $0 +		} +		else { +			if (!/^\t/) { +				hostnum = 1 +				o++ +				opts[o] = $0 +			} +			else { +				sub(/^\t/, "") +				if ($0 == "^") +					$0 = cache +				else if ($0 ~ /^[0-9]*$/) +					$0 = cmds[hosts[$0]":"opts[o]] +				cmds[hosts[hostnum]":"opts[o]] = cache = $0 +				hostnum++ +			} +		} +	} +} +END { +	for (host in hosts) { +		if (hosts[host] != "'`hostname`'") +			continue +		for (cmd in cmds) { +			if (cmd ~ hosts[host] && cmds[cmd] && cmds[cmd] != "-") { +				i = cmd +				sub(/.*:/, "", cmd) +				print "\t"cmd") "cmds[i]" \"$@\" & ;;" +			} +		} +	} +	print "\t*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;" +	print "esac" +} +' $conf > $cache +chmod +x $cache +} + +# Config file setup +confdir=${XDG_CONFIG_HOME:-~/.config}/launch +conf=$confdir/config +if [ ! -e $conf ]; then +	mkdir -p $confdir +	echo "#HOSTS\n+host $(hostname)\n\n#OPTS\ntest\n\techo \"Tested!\"" > $conf +	echo "No config file exists! new config file created at $conf! Exiting\n" +	printhelp +	exit 1 +fi + +# Cache file setup +cachedir=${XDG_CACHE_HOME:-~/.cache}/launch +cache=$cachedir/cache +[ ! -e $cache ] && mkdir -p $cachedir && gencache +[ $conf -nt $cache ] && gencache + +# Command line options +checkawk +case "$1" in +	-g|--gen-cache) echo "Generating new cache: $cache"; gencache && cat $cache ;; +	-h|--help|'') printhelp ;; +	*) exec $cache "$@" ;; # Run +esac diff --git a/misc/verifoo b/misc/verifoo deleted file mode 100755 index 34089cb..0000000 --- a/misc/verifoo +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/sh - -help() { -cat << HELPDOC -usage: $(basename "$0") [options] [file]... - -OPTIONS: -  -h, --help                show this menu -  -c, --check               read and verify checksums from file -  -r, --recursive           produce a checksum for all files in a directory recursively -  --recursive-sum           produce a checksum for a directory. sensitive to filenames -  --recursive-sum-nopath    produce a checksum for a directory. not sensitive to filenames/placement -  -s, --silent              produce no output to stderr -  -v, --verbose             output a progress bar of hash progress if pv is avaliable (wip) - -MODES: -  -S, --sha                 use sha1sum for checksums -  -M, --md5                 use md5sum for checksums -  -X, --xxh                 use xxhsum for checksums (default if avaliable with sha1sum as fallback) -HELPDOC -} - -# set defaults -cat="pv -F'%r_[%b]_[%t]_[%e]_%p'" -! command -v pv >/dev/null && cat=cat - -hash=xxhsum -! command -v xxhsum >/dev/null && hash=sha1sum - -hashfiles="" -verbose=1 -recursive="" -outputfile="" - -while true; do -	case "$1" in -		-c|--check) [ -n "$2" ] && hashfiles="$hashfiles $2" && shift ;; -		-s|--silent)  verbose=0 ;; -		-v|--verbose) verbose=2 ;; -		--recursive|-r)         recursive=3 ;; -		--recursive-sum)        recursive=2 ;; -		--recursive-sum-nopath) recursive=1 ;; -		-S|--sha) hash=sha1sum ;; -		-M|--md5) hash=md5sum  ;; -		-X|--xxh) hash=xxhsum  ;; -		-h|--help) help; exit 0 ;; -		-*)        help; exit 1 ;; -		*) break ;; -	esac -	shift -done - -case $verbose in -	0) cat=cat ;; -	1) cat=cat ;; -esac - -# run hash -while [ -n "$1" ]; do -	if [ -d "$1" ]; then # is directory -		# check if using -r flag -		case "$recursive" in -			1) -				# get hash of all files, sort hashes, hash hashes -				# TODO make pv work in this mode - -				#catd="$cat" -				#if [ $verbose -ge 2 ] && [ "$catd" != "cat" ]; then -				#	total_files=$(du -a "$1" | wc -l) -				#	catd="pv -l -s$total_files -F'[%b/$total_files]_[%t]_[%e]_%p'" -				#fi -				#sum=`find "$1" -type f -print0 | xargs -r0 $hash | $catd | cut -d' ' -f1 | sort | $hash | cut -d' ' -f1` 2>/dev/null -				sum=`find "$1" -type f -print0 | xargs -r0 $hash | cut -d' ' -f1 | sort | $hash | cut -d' ' -f1` 2>/dev/null -				echo "r/$sum  $1" -			;; -			2) -				# hash sorted filenames -				# sort all filenames w/ full path and hash -				# hash those sums together -				# `tar -c -f - "$1" | $hash` is a good idea but it doesn't work since changes to the fs affect tar -				filehash=`find "$1" -type f -print0 | sort -z | xargs -r0 $cat | $hash | cut -d' ' -f1` -				pathhash=`find "$1" -printf "%P\0" | sort -z | $hash | cut -d' ' -f1` -				sum=`printf "$filehash$pathhash" | $hash | cut -d' ' -f1` -				echo "p/$sum  $1" -			;; -			3) -				# sort files and hash each one in sequence -				# TODO make pv work in this mode -				find "$1" -type f -print0 | sort -z | xargs -r0 $hash -			;; -			*) -				[ $verbose -ge 1 ] && echo "-r not specified for directory $1. Exiting" -				exit 1 -			;; -		esac -	else # is file -		if ! [ -f "$1" ]; then -			[ $verbose -gt 1 ] && echo "File $1 does not exist. Exiting" -			exit 1 -		fi -		files="$1" - -		while [ -f "$2" ]; do -			files="$files\0$2" -			shift -		done -		printf "$files" | xargs -r0 $hash -	fi -	shift -done diff --git a/misc/wmip b/misc/wmip new file mode 100755 index 0000000..56fe23d --- /dev/null +++ b/misc/wmip @@ -0,0 +1,2 @@ +#!/bin/sh +ip a | awk '!/ (lo|dummy|virbr)/ && /inet / { sub(/\/.*/, "", $2); printf "%-12s %s\n", $NF":", $2 }'  | 
