~dricottone/my-utils

8b4fb7404819b4ada8ac5429865a22d5570ef58b — Dominic Ricottone 3 years ago 14ef5bd
README formatting; refactor qemu-test; new git script
3 files changed, 102 insertions(+), 55 deletions(-)

M README.md
A src/git-set-remotes
M src/qemu-test
M README.md => README.md +48 -39
@@ 1,42 1,44 @@
# my-utils

A set of scripts that I use frequently. Written in a mix of shell (some POSIX sh, some bash), sed, awk, and so on. Any dependencies *beyond* the POSIX standard and inter-dependency are noted.

A set of scripts that I use frequently. Written in a mix of shell (some POSIX
sh, some bash), sed, awk, and so on. Any dependencies *beyond* the POSIX
standard and inter-dependency are noted.


## General-Use Scripts

Executable|Description                                                   |Extra Dependencies
:---------|:-------------------------------------------------------------|:------------------------------------------
check-x   |Check if an X11 server is running
ctdir     |Count entries in a target directory(ies)
debom     |Remove BOM from a target file                                 |`bash`
enumerate |Rename files in current directory into sequential numbers     |`bash`
epub      |Dumps HTML from an 'epub' e-book archive                      |`bash`, `zipinfo`, `unzip`, `w3m`
fw-status |Print current firewall status                                 |`ufw`
mkbak     |Create a backup of a target file                              |`bash`
mktar     |Wrapper around `tar` for easier compression                   |`bash` *
pingable  |Check if an address/name is ping-able                         |`ping`
rand      |Get a random number within an inclusive range                 |`bash`, `shuf`
rebom     |Add BOM to a target file
resetx    |Reset X server monitor configuration                          |`xrandr`
rmold     |Delete old files
rmtar     |Delete 'tar' archive files
rmzip     |Delete 'zip' archive files
start-at  |After a pattern is matched, re-print                          |GNU or New (AT&T) `awk`
stop-at   |Re-print until a pattern is matched                           |GNU or New (AT&T) `awk`
tarcat    |Print contents of `tar` archive file(s)                       |*
tarls     |List files within `tar` archive file(s)                       |*
unittest  |Wrapper around Python's `unittest` module                     |`python3`, GNU or New (AT&T) `awk`
untar     |Wrapper around `tar` for easier decompression                 |*
vimsplit  |Open two files in split windows                               |`nvim`
whichcat  |Print all lines from a program
whiched   |Open a program with your editor
whichhead |Print the first 10 lines from a program                       |`bash`
whichvi   |Open a program with your visual editor
whisper   |Wrapper around `espeak` to mirror `say` in macOS              |`espeak`
wttr      |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego`
zipls     |List files within `zip` archive file(s)                       |`zipinfo`
Executable      |Description                                                   |Extra Dependencies
:---------------|:-------------------------------------------------------------|:------------------------------------------
check-x         |Check if an X11 server is running
ctdir           |Count entries in a target directory(ies)
debom           |Remove BOM from a target file                                 |`bash`
enumerate       |Rename files in current directory into sequential numbers     |`bash`
epub            |Dumps HTML from an 'epub' e-book archive                      |`bash`, `zipinfo`, `unzip`, `w3m`
fw-status       |Print current firewall status                                 |`ufw`
git-set-remotes |Set all git remotes for my public repositories                |`git`
mkbak           |Create a backup of a target file                              |`bash`
mktar           |Wrapper around `tar` for easier compression                   |`bash` *
pingable        |Check if an address/name is ping-able                         |`ping`
rand            |Get a random number within an inclusive range                 |`bash`, `shuf`
rebom           |Add BOM to a target file
resetx          |Reset X server monitor configuration                          |`xrandr`
rmold           |Delete old files
rmtar           |Delete 'tar' archive files
rmzip           |Delete 'zip' archive files
start-at        |After a pattern is matched, re-print                          |GNU or New (AT&T) `awk`
stop-at         |Re-print until a pattern is matched                           |GNU or New (AT&T) `awk`
tarcat          |Print contents of `tar` archive file(s)                       |*
tarls           |List files within `tar` archive file(s)                       |*
unittest        |Wrapper around Python's `unittest` module                     |`python3`, GNU or New (AT&T) `awk`
untar           |Wrapper around `tar` for easier decompression                 |*
vimsplit        |Open two files in split windows                               |`nvim`
whichcat        |Print all lines from a program
whiched         |Open a program with your editor
whichhead       |Print the first 10 lines from a program                       |`bash`
whichvi         |Open a program with your visual editor
whisper         |Wrapper around `espeak` to mirror `say` in macOS              |`espeak`
wttr            |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego`
zipls           |List files within `zip` archive file(s)                       |`zipinfo`


## Emulator Scripts


@@ 89,21 91,28 @@ wg-test   |Check if Wireguard connection is on and working           |`wg`

## Notes

\* *While you **technically** won't run into an error, these scripts **do** expect `tar` to support Zstandard, which isn't necessarily POSIX standard.*
\* *While you **technically** won't run into an error, these scripts **do**
expect `tar` to support Zstandard, which isn't necessarily POSIX standard.*

*All* scripts support `-h` and `--help` for printing built-in documentation.

*Almost all* scripts do nothing if no input arguments are given. (The exceptions are `whisper` and `wttr`.)

*Almost all* scripts do nothing if no input arguments are given. (The
exceptions are `whisper` and `wttr`.)


## Development

These being re-used scripts, there's been a great deal of feature creep, bikeshedding, and over-engineering. That is to say, there's a lot of uncertainty as to how *reliable* these scripts are. To mitigate these concerns, `shellcheck` is a development dependency. A test suite is in the making, and hopefully new entrants to this repository will come with tests.

These being re-used scripts, there's been a great deal of feature creep,
bikeshedding, and over-engineering. That is to say, there's a lot of
uncertainty as to how *reliable* these scripts are. To mitigate these concerns,
`shellcheck` is a development dependency. A test suite is in the making, and
hopefully new entrants to this repository will come with tests.


## License

If you really want to use anything in this repository-and I need to stress *if you really want to*-just go right ahead. I'm licensing everything under GPL because I'd appreciate you letting me know I messed something up. But you *really* shouldn't try using anything here in production...
If you really want to use anything in this repository-and I need to stress
*if you really want to*-just go right ahead. I'm licensing everything under
GPL because I'd appreciate you letting me know I messed something up. But you
*really* shouldn't try using anything here in production...


A src/git-set-remotes => src/git-set-remotes +40 -0
@@ 0,0 1,40 @@
#!/bin/sh

name="git-set-remotes"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Set all git remotes for my public repositories
	Usage: git-set-remotes
	Options:
	 -h, --help     print this message and exit
	 -q, --quiet    suppress error messages
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

error_msg() {
  if [ "$quiet" -eq 0 ]; then
    (>&2 /usr/bin/printf "%s: %s\n" "$name" "$1")
  fi
}

git_add_or_set() {
  if ! git remote add "$1" "$2" >/dev/null 2>&1; then
    error_msg "remote '${1}' already exists; resetting the URL"
    git remote set-url "$1" "$2" >/dev/null 2>&1
  fi
}

if [ ! -d .git ]; then
  error_msg "not a git repository"
  exit 1
fi

NAME="$(basename "$(pwd)")"

git_add_or_set "origin" "git:${NAME}.git"
git_add_or_set "github" "git@github.com:dricottone/${NAME}.git"
git_add_or_set "gitweb" "deploy-aws2:/var/git/${NAME}.git"


M src/qemu-test => src/qemu-test +14 -16
@@ 1,7 1,7 @@
#!/bin/sh

name="qemu-test"
version="1.0"
version="1.1"
help_message=$(/usr/bin/cat <<-EOF
	Check if hardware and OS are capable of virtualization
	Usage: qemu-test


@@ 14,31 14,29 @@ EOF
. /usr/local/lib/myminiparse.sh

error_msg() {
  (>&2 /usr/bin/printf "%s: %s\n" "$name" "$1")
  if [ "$quiet" -eq 0 ]; then
    (>&2 /usr/bin/printf "%s: %s\n" "$name" "$1")
  fi
}

noisily_exec() {
  /usr/bin/printf "%s\n" "$1"
  $1
  if [ "$quiet" -eq 0 ]; then
    /usr/bin/printf "%s\n" "$1"
    $1
  fi
}

if ! LC_ALL=C lscpu | grep Virtualization >/dev/null 2>&1; then
  if [ "$quiet" -eq 0 ]; then
    error_msg "Virtualization is not supported by the CPU"
    noisily_exec "LC_ALL=C lscpu | grep Virtualization"
  fi
  error_msg "Virtualization is not supported by the CPU"
  noisily_exec "LC_ALL=C lscpu | grep Virtualization"
  exit 1
elif ! zgrep CONFIG_KVM /proc/config.gz >/dev/null 2>&1; then
  if [ "$quiet" -eq 0 ]; then
    error_msg "Virtualization is not supported by the kernel"
    noisily_exec "zgrep CONFIG_KVM /proc/config.gz"
  fi
  error_msg "Virtualization is not supported by the kernel"
  noisily_exec "zgrep CONFIG_KVM /proc/config.gz"
  exit 1
elif ! lsmod | grep kvm >/dev/null 2>&1; then
  if [ "$quiet" -eq 0 ]; then
    error_msg "Kernel modules for virtualization support are not loaded"
    noisily_exec "lsmod | grep kvm"
  fi
  error_msg "Kernel modules for virtualization support are not loaded"
  noisily_exec "lsmod | grep kvm"
  exit 1
fi
exit 0