config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 07b8a3f0e0dd226e11ecc5c653f0ae11350a83e9
parent 0b9081fa538de6b5f995a68f8a6f05f5f1df17cf
Author: Jacob R. Edwards <n/a>
Date:   Wed, 23 Nov 2022 17:12:49 -0600

Add a host of mostly useful scripts

Excluding snapfs, all of these were written some time ago. Their
quality is... dubious in places. Some description:

- books -- Search books
- epubnoimage -- Remove images from epub files
- play -- Play audio
- revf -- Reverse order of fields (useful for reversing order of
  lines, which is the default)
- snapfs -- Store away
- torrent -- Download torrent (currently uses aria2c as a backend)
- tz -- Set timezone using zic
- urls -- Allows selection of a saved url to copy to the clipboard
- varfs -- Mount var host with good default sshfs(1) options (should
  be updated to allow different hosts)
- whodb -- Mess with my "who" database (working status unknown)
  (should be expanded to convert to and from vcf files)

Diffstat:
Alocal/bin/bin/books | 3+++
Alocal/bin/bin/epubnoimage | 11+++++++++++
Alocal/bin/bin/play | 36++++++++++++++++++++++++++++++++++++
Alocal/bin/bin/revf | 9+++++++++
Alocal/bin/bin/snapfs | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alocal/bin/bin/torrent | 3+++
Alocal/bin/bin/tz | 3+++
Alocal/bin/bin/urls | 10++++++++++
Alocal/bin/bin/varfs | 9+++++++++
Alocal/bin/bin/whodb | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 234 insertions(+), 0 deletions(-)

diff --git a/local/bin/bin/books b/local/bin/bin/books @@ -0,0 +1,3 @@ +#!/bin/sh + +find "$HOME"/books -type f | egrep "$@" diff --git a/local/bin/bin/epubnoimage b/local/bin/bin/epubnoimage @@ -0,0 +1,11 @@ +#!/bin/sh + +cleanup() + rm -rf "$tmp" + +tmp="$(mktemp -td epniXXXXXX)" +trap cleanup 0 + +(cd "$tmp" && 9 unzip -s) +find "$tmp" -type f -and '(' -name '*.jpg' -or -name '*.png' ')' -delete +(cd "$tmp" && 9 zip .) diff --git a/local/bin/bin/play b/local/bin/bin/play @@ -0,0 +1,36 @@ +#!/bin/sh +# Copyright 2021, 2022 Jacob R. Edwards + +playfile() { + ffplay -autoexit -nodisp -loglevel error "$1" 2>&1 | nobs 2>&1 +} + +playfile2() ( + case "$(file -bi "$1")" in + ("audio/mpeg") + exec mpg123 "$1" ;; + # Not really needed, + # but have you looked at libsndfile sources? + (audio/ogg | application/ogg | audio/flac | audio/x-flac) + exec ogg123 "$1" ;; + (*) + exec sndfile-play "$1" ;; + esac </dev/null >/dev/null 2>&1 +) + +if test $# -eq 0 +then + tr '\n' '\0' | xargs -0r play +else + for a in "$@" + do + if test -d "$a" + then + find "$a" -type f | play + else + echo "$a" + playfile "$a" || + echo "unable to play '$a'" + fi + done +fi diff --git a/local/bin/bin/revf b/local/bin/bin/revf @@ -0,0 +1,9 @@ +#!/usr/bin/awk -f +# Copyright 2022 Jacob R. Edwards +# Reverse order of fields + +BEGIN { + OFS = FS +} + +{x[NR]=$0}END{for(i=NR;i>0;--i){print(x[i])}} diff --git a/local/bin/bin/snapfs b/local/bin/bin/snapfs @@ -0,0 +1,88 @@ +#!/bin/sh +# Copyright Nov 2022 Jacob R. Edwards +# Store or copy snapshots of the filesystem away. +# +# Currently lacks the flexability of allowing multiple operands to +# each command. Easily fixed. + +list() { + find "${1:?no directory}" -maxdepth 1 -mindepth 1 | sed 's/^\.\///' +} +ts() date +%F.%H%M%S +getfiles() { + awk -F ' ' -v name="$1" 'name == $1 { + args=$2 + exit + } + END { + if (args) + print args + else { + printf "'\''%s'\'': Entry not found\n", name > "/dev/stderr" + exit 1 + } + }' < "$config" +} +save() { + name="$1"; shift + files="$(getfiles "$name")" || + exit 1 + + file="$name/$name-$(ts).tar.bz2" + mkdir -p "$data/$name" + pax -w $files | bzip2 > "$data/$file" || { + rm "$archive" + exit 1 + } + echo "$file" +} +getarc() { + if test -d "$data/$1"; then + (cd "$data" && list "$1" | sed -n '$p') + else + echo "$1" + fi +} +restore() { + name="$(getarc "$1")"; shift + bunzip2 < "$data/$name" | pax -r + echo "$name" +} + +config="${XDG_CONFIG_HOME:-"$HOME"/.config}"/snapfs +data="${XDG_DATA_HOME:-"$HOME"/.share}"/snapfs + +set -eu + +cd + +if test $# -eq 0 +then + cut -f1 "$config" + exit +fi + +com="$1"; shift +case "$com" in +(list) (cd "$data" && list "${1:-.}") ;; +(save) save "$1" ;; +(restore) restore "$1" ;; +(store) + save "$1" || + exit 1 + rm -rf $(getfiles "$1") + ;; +(unstore) + if ! test -f "$data"/"$1"; then + echo 'Must explicitly specify snapshot to unstore' 1>&2 + exit 1 + fi + + restore "$1" || + exit 1 + rm -f "$data"/"$1" + ;; +(*) + echo "$2: Unknown command" 1>&2 + exit 1 ;; +esac diff --git a/local/bin/bin/torrent b/local/bin/bin/torrent @@ -0,0 +1,3 @@ +#!/bin/sh + +aria2c --enable-color=false "$@" diff --git a/local/bin/bin/tz b/local/bin/bin/tz @@ -0,0 +1,3 @@ +#!/bin/sh + +zic -l "/usr/share/zoneinfo/${2:-America}/${1:-Los_Angeles}" diff --git a/local/bin/bin/urls b/local/bin/bin/urls @@ -0,0 +1,10 @@ +#!/usr/local/plan9/bin/rc -e +# Copyright 2021 Jacob R. Edwards + +cd $home^/etc/urls + +if (~ $#* 0) + * = * +awk '{ gsub("\\]", "", FILENAME); printf "[%s] %s\n", FILENAME, $0 }' \ + `{ find . -type f | cut -c3- } | dmenu | \ + sed -E 's/^\[[^]]+\] //' | xgrab diff --git a/local/bin/bin/varfs b/local/bin/bin/varfs @@ -0,0 +1,9 @@ +#!/bin/sh + +options=reconnect,allow_other,uid=1001,identityfile=/home/jacob/.ssh/keys/var/jacob +test "$1" = -o && { + options="$options,$2" + shift 2 +} + +exec sshfs -o "$options" var:/mnt "${1:-/mnt}" diff --git a/local/bin/bin/whodb b/local/bin/bin/whodb @@ -0,0 +1,62 @@ +#!/bin/sh -eu +# Copyright 2022 Jacob R. Edwards + +validkeys='name nick address phone email' +export validkeys + +IFS=' +' +whodb="$HOME"/own/who +test $# -gt 1 && + path="$whodb"/"$2" + +case "${1:-}" in +(edit) + "$EDITOR" "$path" + if test ! -s "$path" + then + rm -f "$path" + elif ! awk -F ': ' 'BEGIN { + split(ENVIRON["validkeys"], tmp, " "); + for (i in tmp) + valid[tmp[i]] = 1; + } + ! valid[$1] && ! /^ *#/ { + printf "%s: Not a valid key\n", $1; + invalid = 1; + } + END { + exit invalid; + }' < "$path" + then + echo 'Valid keys are:' $validkeys + echo -n "Revise? [y] " 1>&2 + test "$(sed 's/^$/y/; s/^[Yy].*/y/; q')" = y && + exec "$0" "$@" + fi + ;; +(new) + mkdir -p "$(dirname "$path")" + shift + "$0" edit "$@" + ;; +(show) + test $# -le 1 && + exec "$0" "$@" '' + if test -d "$path" + then + find "$path" -type f -not -name README | cut -c$(expr ${#whodb} + 2)- + else + cat "$path" + fi + ;; +(search) + regex="$2" + shift 2 + grep -Ri "$regex" $("$0" show "$@") + ;; +(*) + echo 'Invalid command (only edit, new, show, and search accepted)' 1>&2 + exit 1 + ;; +esac