Unify shell script style

This commit is contained in:
Lucas 2019-12-08 18:14:46 +00:00
parent 8d3ae231bb
commit c84c0e3a99
11 changed files with 81 additions and 83 deletions

View file

@ -1,5 +1,5 @@
#!/bin/sh
# env
# rfcopen
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
@ -10,12 +10,20 @@
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() {
usage()
{
printf "Usage: %s [-T] rfc-number\n" "${0##*/}" >&2
exit 1
}
tonumber() {
err()
{
printf "%s: %s\n" "${0##*/}" "$*" >&2
exit 1
}
tonumber()
{
printf "%u" "$1" 2>/dev/null
}
@ -32,18 +40,13 @@ while getopts T flag; do
done
shift $(($OPTIND - 1))
if [ $# -ne 1 ] || [ -z "$1" ] || ! n=$(tonumber "$1"); then
usage
fi
[ $# -eq 1 ] && [ -n "$1" ] && n=$(tonumber "$1") || usage
rfcfile=$RFCDIR/rfc$n.txt
url=https://tools.ietf.org/rfc/rfc$n.txt
mkdir -p "$RFCDIR"
if [ ! -f "$rfcfile" ]; then
if ! $torsocks ftp -Vo "$rfcfile" "$url"; then
printf "%s: Couldn't fetch RFC %u\n" "${0##*/}" "$n" >&2
exit 1
fi
$torsocks ftp -Vo "$rfcfile" "$url" || err "Couldn't fetch RFC $n."
fi
${PAGER:-more} "$rfcfile"