Align shell style all over the repo

This commit is contained in:
Lucas 2020-05-03 14:47:27 +00:00
parent afb13d9c9c
commit d5e71c46f7
16 changed files with 113 additions and 86 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# ZZZ # ZZZ
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -12,7 +12,7 @@
doas true || exit $? doas true || exit $?
printf "Hibernating in"; printf "Hibernating in"
for i in 3 2 1; do for i in 3 2 1; do
printf " %d..." $i printf " %d..." $i
sleep 1 sleep 1

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# credentials # credentials
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -63,25 +63,25 @@ get_service()
if [ $user = no ] && [ $pass = no ] && [ $sfa = no ]; then if [ $user = no ] && [ $pass = no ] && [ $sfa = no ]; then
sekrit has "services/$service/pass" || sekrit has "services/$service/pass" ||
err "Unknown service \"$service\"." err "unknown service $service"
pass=yes pass=yes
sekrit has services/"$service"/user && user=yes sekrit has "services/$service/user" && user=yes
sekrit has services/"$service"/2fa && sfa=yes sekrit has "services/$service/2fa" && sfa=yes
fi fi
if [ $user = check ]; then if [ $user = check ]; then
sekrit has services/"$service"/user || sekrit has "services/$service/user" ||
err "Service \"$service\" has no user." err "service $service has no user"
user=yes user=yes
fi fi
if [ $pass = check ]; then if [ $pass = check ]; then
sekrit has services/"$service"/pass || sekrit has "services/$service/pass" ||
err "Service \"$service\" has no pass." err "service $service has no pass"
pass=yes pass=yes
fi fi
if [ $sfa = check ]; then if [ $sfa = check ]; then
sekrit has services/"$service"/2fa || sekrit has "services/$service/2fa" ||
err "Service \"$service\" has no 2fa." err "service $service has no 2fa"
sfa=yes sfa=yes
fi fi
@ -94,7 +94,7 @@ get_raw()
{ {
key=$1 key=$1
sekrit has "$key" || err "Unknown key \"$key\"." sekrit has "$key" || err "unknown key $key"
printf "%s" "$key" printf "%s" "$key"
sekrit get "$key" | clip && printf "\n" sekrit get "$key" | clip && printf "\n"
@ -118,14 +118,14 @@ while getopts 2pru flag; do
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
[ $# -eq 1 ] && [ -n "$1" ] || usage [ $# -eq 1 ] && [ -n "$1" ] || usage
key=$1 key=$1
if [ $raw = yes ]; then if [ $raw = yes ]; then
if [ $sfa != no ] || [ $pass != no ] || [ $user != no ]; then if [ $sfa != no ] || [ $pass != no ] || [ $user != no ]; then
err "-r is mutually exclusive with -2pu." err "-r is mutually exclusive with -2pu"
fi fi
get_raw "$key" get_raw "$key"
else else

View File

@ -39,14 +39,14 @@ while getopts T flag; do
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
[ $# -gt 0 ] || usage [ $# -gt 0 ] || usage
: ${ARCHIVE_BASEDIR:=~/tmp/archive} : ${ARCHIVE_BASEDIR:=~/tmp/archive}
mkdir -p "$ARCHIVE_BASEDIR" mkdir -p "$ARCHIVE_BASEDIR"
everything=$ARCHIVE_BASEDIR/everything everything=$ARCHIVE_BASEDIR/everything
test -f "$everything" || touch "$everything" touch "$everything"
dir=$ARCHIVE_BASEDIR/$(date +%Y/%m/%d) dir=$ARCHIVE_BASEDIR/$(date +%Y/%m/%d)
mkdir -p "$dir" || exit 1 mkdir -p "$dir" || exit 1
@ -57,7 +57,7 @@ for url; do
outdir=$dir/$sha outdir=$dir/$sha
if grep -q "^$url\$" "$everything"; then if grep -q "^$url\$" "$everything"; then
printf "%s: \"%s\" already fetched.\n" "${0##*/}" "$url" >&2 printf "%s: already fetched %s\n" "${0##*/}" "$url" >&2
printf "%s/file\n" "$(find_dir "$sha")" printf "%s/file\n" "$(find_dir "$sha")"
continue continue
fi fi

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# imgresize # imgresize
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -29,13 +29,12 @@ err()
check_dimension_format() check_dimension_format()
{ {
printf "%s\n" "$1" | grep -q "^[0-9]*x[0-9]*\$" \ printf "%s\n" "$1" | grep -q "^[0-9]*x[0-9]*\$" && [ "$1" != "x" ]
&& [ "$1" != "x" ]
} }
[ $# -eq 3 ] && check_dimension_format "$1" || usage [ $# -eq 3 ] && check_dimension_format "$1" || usage
[ -n "$2" ] || err "Input file name can't be empty." [ -n "$2" ] || err "input file name can't be empty"
[ -n "$3" ] || err "Output file name can't be empty." [ -n "$3" ] || err "output file name can't be empty"
size=$1 size=$1
w=${size%x*} w=${size%x*}
@ -50,7 +49,7 @@ case $infile in
;; ;;
*.png) inprog=pngtopam *.png) inprog=pngtopam
;; ;;
*) err "Unknown input format." *) err "unknown input format"
;; ;;
esac esac
@ -61,10 +60,10 @@ case $outfile in
;; ;;
*.png) outprog=pamtopng *.png) outprog=pamtopng
;; ;;
*) err "Unknown output format." *) err "unknown output format"
;; ;;
esac esac
"$inprog" <"$infile" \ $inprog <"$infile" |
| pamscale ${w:+-width "$w"} ${h:+-height "$h"} \ pamscale ${w:+-width "$w"} ${h:+-height "$h"} |
| "$outprog" >"$outfile" $outprog >"$outfile"

View File

@ -88,10 +88,10 @@ shift $((OPTIND - 1))
[ $# -eq 1 ] || usage [ $# -eq 1 ] || usage
url=$1 url=$1
known_site "$url" || err "Unknown site: $url" known_site "$url" || err "unknown site $url"
id=$(get_id "$url") id=$(get_id "$url")
[ ${#id} -eq 11 ] || err "invalid video ID" [ ${#id} -eq 11 ] || err "invalid video ID $id"
# XXX choose in some clever way # XXX choose in some clever way
itag=$(torsocks ftp -MVo - "$(api "/api/v1/videos/$id")" | itag=$(torsocks ftp -MVo - "$(api "/api/v1/videos/$id")" |

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# o # plumb
# Written in 2020 by Lucas # Written in 2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #

View File

@ -25,7 +25,7 @@ err()
check_prog() check_prog()
{ {
if ! command -v "$1" >/dev/null 2>&1; then if ! command -v "$1" >/dev/null 2>&1; then
printf "%s: Missing required program \"%s\"\n" \ printf "%s: missing required program %s\n" \
"${0##*/}" "$1" >&2 "${0##*/}" "$1" >&2
return 1 return 1
fi fi
@ -95,6 +95,6 @@ ix.io)
do_upload pst_ix_io "$@" do_upload pst_ix_io "$@"
;; ;;
*) *)
err "Unknown service \"$srv\"" err "unknown service $srv"
;; ;;
esac esac

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# rfcopen # rfcopen
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -38,7 +38,7 @@ while getopts T flag; do
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
[ $# -eq 1 ] && [ -n "$1" ] && n=$(tonumber "$1") || usage [ $# -eq 1 ] && [ -n "$1" ] && n=$(tonumber "$1") || usage
rfcfile=$RFCDIR/rfc$n.txt rfcfile=$RFCDIR/rfc$n.txt
@ -46,7 +46,6 @@ url=https://tools.ietf.org/rfc/rfc$n.txt
mkdir -p "$RFCDIR" mkdir -p "$RFCDIR"
if [ ! -f "$rfcfile" ]; then if [ ! -f "$rfcfile" ]; then
$torsocks ftp -Vo "$rfcfile" "$url" || err "Couldn't fetch RFC $n." $torsocks ftp -Vo "$rfcfile" "$url" || err "couldn't fetch RFC $n"
fi fi
${PAGER:-more} "$rfcfile" ${PAGER:-more} "$rfcfile"

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# screenshot # screenshot
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -31,14 +31,16 @@ err()
case $# in case $# in
0) set -- -root 0) set -- -root
;; ;;
1) [ "$1" = "-window" ] || err "Unknown option \"$1\"." 1) [ "$1" = "-window" ] || err "unknown option $1"
set -- set --
;; ;;
2) [ "$1" = "-id" ] || [ "$1" = "-name" ] || err "Unknown option \"$1\"." 2) [ "$1" = "-id" ] || [ "$1" = "-name" ] || err "unknown option $1"
[ -n "$2" ] || err "$1 expects a non-empty parameter." [ -n "$2" ] || err "$1 expects a non-empty parameter"
;; ;;
*) usage *) usage
;; ;;
esac esac
xwd -silent "$@" | xwdtopnm | pnmtopng >~/media/ss/"$(date +%Y%m%d-%H%M%S)".png : ${SCREENSHOTS:=~/media/ss}
xwd -silent "$@" | xwdtopnm |
pnmtopng >"$SCREENSHOTS/$(date +%Y%m%d-%H%M%S).png"

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# sekrit # sekrit
# Written in 2018-2019 by Lucas # Written in 2018-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -50,7 +50,7 @@ check_key()
{ {
case $1 in case $1 in
*/ | /* | ./* | */./* | */. | ../* | */../* | */..) */ | /* | ./* | */./* | */. | ../* | */../* | */..)
err "Key can not end in a slash." err "$1: invalid key"
;; ;;
esac esac
} }
@ -70,9 +70,10 @@ sekrit_add()
f=$SEKRIT_DIR/$key.gpg f=$SEKRIT_DIR/$key.gpg
mkdir -p "${f%/*}" mkdir -p "${f%/*}"
[ -f "$f" ] && err "Key \"$key\" already exists." [ -f "$f" ] && err "key $key already exists"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
# use all additional parameters as a single string
printf "%s\n" "$*" printf "%s\n" "$*"
else else
cat - cat -
@ -88,13 +89,13 @@ sekrit_gen()
while getopts l: flag; do while getopts l: flag; do
case "$flag" in case "$flag" in
l) len=$(to_number "$OPTARG") || l) len=$(to_number "$OPTARG") ||
err "Invalid password length." err "invalid password length"
;; ;;
*) usage *) usage
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
[ $# -le 1 ] || usage [ $# -le 1 ] || usage
@ -116,7 +117,7 @@ sekrit_get()
shift shift
f=$SEKRIT_DIR/$key.gpg f=$SEKRIT_DIR/$key.gpg
[ -f "$f" ] || err "No data for key \"$key\"." [ -f "$f" ] || err "no data for key $key"
gpg2 -qd "$f" gpg2 -qd "$f"
} }

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# env # env
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -16,19 +16,18 @@
: ${IMAGE_HEIGHT:=500} : ${IMAGE_HEIGHT:=500}
: ${IMAGE_WIDTH:=500} : ${IMAGE_WIDTH:=500}
pos_x=$((3 * $CANVAS_WIDTH / 4 - $IMAGE_WIDTH / 2)) pos_x=$((3 * CANVAS_WIDTH / 4 - IMAGE_WIDTH / 2))
pos_y=$(($CANVAS_HEIGHT / 2 - $IMAGE_HEIGHT / 2)) pos_y=$((CANVAS_HEIGHT / 2 - IMAGE_HEIGHT / 2))
if ! tmpfile=$(mktemp -t bg.XXXXXXXXXX); then if ! tmpfile=$(mktemp -t bg.XXXXXXXXXX); then
printf "%s: Can't create temporary file.\n" "${0##*/}" >&2 printf "%s: can't create temporary file\n" "${0##*/}" >&2
exit 1 exit 1
fi fi
trap 'rm -f "$tmpfile"' EXIT INT QUIT TERM trap 'rm -f "$tmpfile"' EXIT INT QUIT TERM
pngtopam -alphapam FreeHugsBSD.png \ pngtopam -alphapam FreeHugsBSD.png |
| pamscale -width="$IMAGE_WIDTH" -height="$IMAGE_HEIGHT" \ pamscale -width "$IMAGE_WIDTH" -height "$IMAGE_HEIGHT" >"$tmpfile"
>"$tmpfile" ppmmake "$CANVAS_BGCOLOR" "$CANVAS_WIDTH" "$CANVAS_HEIGHT" |
ppmmake "$CANVAS_BGCOLOR" "$CANVAS_WIDTH" "$CANVAS_HEIGHT" \ pamcomp -xoff "$pos_x" -yoff "$pos_y" "$tmpfile" |
| pamcomp -xoff="$pos_x" -yoff="$pos_y" "$tmpfile" \ pamtopng >FreeHugsBSD-bg.png
| pamtopng >FreeHugsBSD-bg.png

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# env # env
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -16,19 +16,18 @@
: ${IMAGE_HEIGHT:=768} : ${IMAGE_HEIGHT:=768}
: ${IMAGE_WIDTH:=1080} : ${IMAGE_WIDTH:=1080}
pos_x=$((($CANVAS_WIDTH - $IMAGE_WIDTH) / 2)) pos_x=$(((CANVAS_WIDTH - IMAGE_WIDTH) / 2))
pos_y=$((($CANVAS_HEIGHT - $IMAGE_HEIGHT) / 2)) pos_y=$(((CANVAS_HEIGHT - IMAGE_HEIGHT) / 2))
if ! tmpfile=$(mktemp -t bg.XXXXXXXXXX); then if ! tmpfile=$(mktemp -t bg.XXXXXXXXXX); then
printf "%s: Can't create temporary file.\n" "${0##*/}" >&2 printf "%s: can't create temporary file\n" "${0##*/}" >&2
exit 1 exit 1
fi fi
trap 'rm -f "$tmpfile"' EXIT INT QUIT TERM trap 'rm -f "$tmpfile"' EXIT INT QUIT TERM
pngtopam -alphapam cyberia-cafe-club.png \ pngtopam -alphapam cyberia-cafe-club.png |
| pamscale -width="$IMAGE_WIDTH" -height="$IMAGE_HEIGHT" \ pamscale -width "$IMAGE_WIDTH" -height "$IMAGE_HEIGHT" >"$tmpfile"
>"$tmpfile" ppmmake "$CANVAS_BGCOLOR" "$CANVAS_WIDTH" "$CANVAS_HEIGHT" |
ppmmake "$CANVAS_BGCOLOR" "$CANVAS_WIDTH" "$CANVAS_HEIGHT" \ pamcomp -xoff "$pos_x" -yoff "$pos_y" "$tmpfile" |
| pamcomp -xoff="$pos_x" -yoff="$pos_y" "$tmpfile" \ pamtopng >cyberia-cafe-club-bg.png
| pamtopng >cyberia-cafe-club-bg.png

View File

@ -1,4 +1,15 @@
#!/bin/sh #!/bin/sh
# env
# Written in 2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() usage()
{ {
printf "Usage: %s [-c curve] [-d days] domain\n" "${0##*/}" >&2 printf "Usage: %s [-c curve] [-d days] domain\n" "${0##*/}" >&2
@ -28,7 +39,7 @@ shift $((OPTIND - 1))
domain=$1 domain=$1
if [ -f "$domain.key" ]; then if [ -f "$domain.key" ]; then
printf "%s: key for %s already exists; reusing it.\n" \ printf "%s: key for %s already exists; reusing it\n" \
"${0##*/}" "$domain" >&2 "${0##*/}" "$domain" >&2
else else
(umask 0377 && (umask 0377 &&

View File

@ -1,4 +1,15 @@
#!/bin/sh #!/bin/sh
# env
# Written in 2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() usage()
{ {
printf "Usage: %s newkey\n" "${0##*/}" >&2 printf "Usage: %s newkey\n" "${0##*/}" >&2
@ -18,21 +29,21 @@ newsekrit()
[ $# -eq 1 ] || usage [ $# -eq 1 ] || usage
newkey=$1 newkey=$1
gpg2 -k "$newkey" >/dev/null || err "Can't find key \"$newkey\"" gpg2 -k "$newkey" >/dev/null || err "can't find key $newkey"
umask 077 umask 077
newdir=$(mktemp -dt sekrit-XXXXXXXXXX) || newdir=$(mktemp -dt sekrit-XXXXXXXXXX) ||
err "Failed to create temporary directory" err "failed to create temporary directory"
scratch=$(mktemp -tp "$newdir" .sekrit-scratch-XXXXXXXXXX) || scratch=$(mktemp -tp "$newdir" .sekrit-scratch-XXXXXXXXXX) ||
err "Failed to create scratch file" err "failed to create scratch file"
trap 'rm -fr -- "$scratch" "$newdir"' INT QUIT TERM trap 'rm -fr -- "$scratch" "$newdir"' INT QUIT TERM
for entry in $(sekrit ls | grep -v ^DONE); do for entry in $(sekrit ls | grep -v ^DONE); do
printf "%s... " "$entry" printf "%s... " "$entry"
sekrit get "$entry" >|"$scratch" || sekrit get "$entry" >|"$scratch" ||
err "Failed to export entry \"$entry\"" err "failed to export entry $entry"
newsekrit add "$entry" <"$scratch" || newsekrit add "$entry" <"$scratch" ||
err "Failed to import entry \"$entry\"" err "failed to import entry $entry"
printf "OK\n" printf "OK\n"
done done
rm -f "$scratch" rm -f "$scratch"

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# env # env
# Written in 2019 by Lucas # Written in 2019-2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
# To the extent possible under law, the author(s) have dedicated all # To the extent possible under law, the author(s) have dedicated all
@ -22,7 +22,7 @@ tput rev
printf " bg on fg " printf " bg on fg "
tput sgr0 tput sgr0
for i in 0 1 2 3 4 5 6 7; do for i in 0 1 2 3 4 5 6 7; do
tput setab $(($i + 8)) 0 0 tput setab $((i + 8)) 0 0
printf " " printf " "
done done
printf "\n" printf "\n"

View File

@ -1,4 +1,15 @@
#!/bin/sh #!/bin/sh
# env
# Written in 2020 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() usage()
{ {
printf "Usage: %s version\n" "${0##*/}" >&2 printf "Usage: %s version\n" "${0##*/}" >&2
@ -16,19 +27,14 @@ isversion()
printf "%s\n" "$*" | grep -Eq "^v[0-9]+\.[0-9]+\.[0-9]+$" printf "%s\n" "$*" | grep -Eq "^v[0-9]+\.[0-9]+\.[0-9]+$"
} }
if [ -z "${RIOT_WEB_UI_DIR:-}" ]; then [ -n "${RIOT_WEB_UI_DIR:-}" ] || err "environment var RIOT_WEB_UI_DIR unset"
err "Environment RIOT_WEB_UI_DIR unset" [ $# -eq 1 ] && isversion "$1" || usage
fi
if [ $# -ne 1 ] || ! isversion "$1"; then
usage
fi
ver=$1 ver=$1
GH_BASE_URL=https://github.com/vector-im/riot-web/releases/download GH_BASE_URL=https://github.com/vector-im/riot-web/releases/download
cd "$RIOT_WEB_UI_DIR" || err "Can't cd to web UI directory" cd "$RIOT_WEB_UI_DIR" || err "can't cd to web UI directory"
ftp -o - "$GH_BASE_URL/$ver/riot-$ver.tar.gz" | pax -rz || ftp -o - "$GH_BASE_URL/$ver/riot-$ver.tar.gz" | pax -rz ||
err "Can't fetch and extract release" err "can't fetch and extract release"
rm -f riot && ln -s "riot-$ver" riot || rm -f riot && ln -s "riot-$ver" riot ||
err "Can't point web UI directory to new release" err "can't point web UI directory to new release"