Initial import

This commit is contained in:
Lucas 2019-09-11 02:11:40 +00:00
commit 3779fdce2c
48 changed files with 2012 additions and 0 deletions

30
bin/Makefile Normal file
View file

@ -0,0 +1,30 @@
# env
# Written in 2019 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/>.
.POSIX:
.SUFFIXES:
.SUFFIXES: .sh .c
PREFIX= $(HOME)
BIN= ZZZ browser credentials fetch imgresize invidious rfcopen screenshot \
tor-browser w3m-copy-link xsekrit
all: $(BIN)
clean:
rm -f $(BIN)
install: all
mkdir -p $(PREFIX)/bin
cp -f $(BIN) $(PREFIX)/bin
cd $(PREFIX)/bin && chmod 555 $(BIN)
uninstall:
cd $(PREFIX)/bin && rm -f $(BIN)

23
bin/ZZZ.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/sh
# env
# Written in 2019 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/>.
doas true || exit $?
printf "Hibernating in";
for i in 3 2 1; do
printf " %d..." $i
sleep 1
done
printf " now!\n"
doas /usr/sbin/ZZZ "$@"
doas -L

15
bin/browser.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/sh
# env
# Written in 2019 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/>.
scp ~/.Xauthority _browser@localhost:
ssh -n _browser@localhost -- \
env DISPLAY=${DISPLAY:-:0} /usr/local/bin/firefox "$@"

109
bin/credentials.sh Normal file
View file

@ -0,0 +1,109 @@
#!/bin/sh
# env
# Written in 2019 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() {
cat - <<. >&2
Usage:
${0##*/} [-2pu] service
.
exit 1
}
clip() { xclip -q -r -l 1 -sel clip 2>/dev/null; }
get_user() {
echo user
sekrit get services/"$1"/user | clip
}
get_pass() {
echo pass
sekrit get services/"$1"/pass | clip
}
get_2fa() {
echo 2fa
otpcli_opts=
case $1 in
isnic) otpcli_opts="-H sha512 -d 8"
;;
esac
sekrit get services/"$1"/2fa | otpcli $otpcli_opts | clip
}
get_from_flags() {
user=$1
pass=$2
sfa=$3
s=$4
if [ $user = yes ] && ! sekrit has services/"$s"/user; then
printf "%s: service \"%s\" has no user.\n" \
"${0##*/}" "$s" >&2
exit 1
fi
if [ $pass = yes ] && ! sekrit has services/"$s"/pass; then
printf "%s: service \"%s\" has no pass.\n" \
"${0##*/}" "$s" >&2
exit 1
fi
if [ $sfa = yes ] && ! sekrit has services/"$s"/2fa; then
printf "%s: service \"%s\" has no 2fa.\n" \
"${0##*/}" "$s" >&2
exit 1
fi
[ $user = yes ] && get_user "$s"
[ $pass = yes ] && get_pass "$s"
[ $sfa = yes ] && get_2fa "$s"
}
get_all() {
s=$1
if ! sekrit has services/"$s"/pass; then
printf "%s: Unknown service \"%s\".\n" \
"${0##*/}" "$s" >&2
exit 1
fi
sekrit has services/"$s"/user && get_user "$s"
get_pass "$s"
sekrit has services/"$s"/2fa && get_2fa "$s"
}
sfa=no
pass=no
user=no
while getopts 2pu flag; do
case $flag in
2) sfa=yes
;;
p) pass=yes
;;
u) user=yes
;;
*) usage
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -ne 1 ] || [ -z "$1" ]; then
usage
fi
service=$1
if [ $sfa = yes ] || [ $pass = yes ] || [ $user = yes ]; then
get_from_flags $user $pass $sfa "$service"
else
get_all "$service"
fi

62
bin/fetch.sh Normal file
View file

@ -0,0 +1,62 @@
#!/bin/sh
# env
# Written in 2019 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() {
printf "Usage: %s [-T] URL [URLs...]\n" "${0##*/}">&2
exit 1
}
torsocks=torsocks
while getopts T flag; do
case $flag in
T) torsocks=
;;
*) usage
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
usage
fi
: ${ARCHIVE_BASEDIR:=~/tmp/archive}
mkdir -p "$ARCHIVE_BASEDIR"
everything=$ARCHIVE_BASEDIR/everything
test -f "$everything" || touch "$everything"
dir=$ARCHIVE_BASEDIR/$(date +%Y/%m/%d)
mkdir -p "$dir" || exit 1
rc=0
for url; do
sha=$(printf "%s" "$url" | sha256)
outdir=$dir/$sha
if grep -q "^$url\$" "$everything"; then
printf "%s: \"%s\" already fetched.\n" "${0##*/}" "$url" >&2
printf "%s\n" "$outdir/file"
continue
fi
mkdir -p "$outdir"
{
$torsocks ftp -o "$outdir/file" "$url" \
&& printf "%s\n" "$url" >"$outdir/url" \
&& printf "%s\n" "$name" >"$outdir/name" \
&& printf "%s\n" "$url" >>"$everything" \
&& printf "%s\n" "$outdir/file"
} || rc=1
done
exit $rc

74
bin/imgresize.sh Normal file
View file

@ -0,0 +1,74 @@
#!/bin/sh
# env
# Written in 2019 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() {
cat - <<. >&2
Usage:
${0##*/} size in-file out-file
"size" is WxH or Wx or xH.
.
exit 1
}
check_dimension_format() {
printf "%s\n" "$1" | grep -q "^[0-9]*x[0-9]*\$" \
&& [ "$1" != "x" ]
}
if [ $# -ne 3 ] || ! check_dimension_format "$1"; then
usage
fi
if [ -z "$2" ]; then
printf "%s: Input file name can't be empty.\n" \
"${0##*/}" >&2
exit 1
fi
if [ -z "$3" ]; then
printf "%s: Output file name can't be empty.\n" \
"${0##*/}" >&2
exit 1
fi
size=$1
w=${size#x*}
h=${size%*x}
infile=$2
outfile=$3
inprog=
case $infile in
*.jpg | *.jpeg)
inprog=jpegtopnm
;;
*.png) inprog=pngtopam
;;
*) printf "%s: Unknown input format.\n" "${0##*/}" >&2
exit 1
;;
esac
outprog=
case $outfile in
*.jpg | *.jpeg)
outprog=pnmtojpeg
;;
*.png) outprog=pamtopng
;;
*) printf "%s: Unknown output format.\n" "${0##*/}" >&2
exit 1
;;
esac
"$inprog" <"$infile" \
| pamscale ${w:+-width "$w"} ${h:+-height "$h"} \
| "$outprog" >"$outfile"

54
bin/invidious.sh Normal file
View file

@ -0,0 +1,54 @@
#!/bin/sh
# env
# Written in 2019 by Leslie
# Modified in 2019 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() {
printf "Usage: %s url\n" "${0##*/}" >&2
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
case $1 in
"https://invidio.us/watch?v="*)
;;
*) printf "%s: Not an invidio.us url.\n" "${0##*/}" >&2
exit 1
esac
video_id=
for param in $(printf "%s\n" "${1##*"?"}" | tr "&" "\n"); do
k=${param%%=*}
[ "$k" = v ] || continue
v=${param#*=}
if [ ${#v} -ne 11 ]; then
printf "%s: "%s": not a video id.\n" "${0##*/}" "$v" >&2
continue
fi
video_id=$v
break
done
if [ -z "$video_id" ]; then
printf "%s: no video ID in URL.\n" "${0##*/}" >&2
exit 1
fi
dl_option=$(ftp -o - "$1" 2>/dev/null \
| grep "<option value='{" \
| head -n 1 | cut -d "\"" -f 8)
printf "https://invidio.us/latest_version?id=%s&itag=%s\n" \
"$video_id" "$dl_option"

49
bin/rfcopen.sh Normal file
View file

@ -0,0 +1,49 @@
#!/bin/sh
# env
# Written in 2019 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() {
printf "Usage: %s [-T] rfc-number\n" "${0##*/}" >&2
exit 1
}
tonumber() {
printf "%u" "$1" 2>/dev/null
}
: ${RFCDIR:=~/doc/rfc}
torsocks=torsocks
while getopts T flag; do
case $flag in
T) torsocks=
;;
*) usage
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -ne 1 ] || [ -z "$1" ] || ! n=$(tonumber "$1"); then
usage
fi
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
fi
${PAGER:-more} "$rfcfile"

52
bin/screenshot.sh Normal file
View file

@ -0,0 +1,52 @@
#!/bin/sh
# env
# Written in 2019 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() {
cat - <<. >&2
Usage:
${0##*/}
${0##*/} -id id
${0##*/} -name name
${0##*/} -window
.
exit 1
}
save_screenshot() {
xwdtopnm | pnmtopng >~/media/ss/"$(date +%Y%m%d-%H%M%S)".png
}
case $# in
0) xwd -silent -root | save_screenshot
;;
1) if [ "$1" != "-window" ]; then
printf "%s: Unknown option \"%s\".\n" \
"${0##*/}" "$1" >&2
exit 1
fi
xwd -silent | save_screenshot
;;
2) if [ "$1" != "-id" ] && [ "$1" != "-name" ]; then
printf "%s: Unknown option \"%s\".\n" \
"${0##*/}" "$1" >&2
exit 1
fi
if [ -z "$2" ]; then
printf "%s: %s expects a non-empty parameter.\n" \
"${0##*/}" "$1" >&2
exit 1
fi
xwd -silent "$1" "$2" | save_screenshot
;;
*) usage
;;
esac

15
bin/tor-browser.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/sh
# env
# Written in 2019 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/>.
scp ~/.Xauthority _browser@localhost:
ssh -n _browser@localhost -- \
env DISPLAY=${DISPLAY:-:0} /usr/local/bin/tor-browser "$@"

13
bin/w3m-copy-link.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/sh
# env
# Written in 2019 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/>.
printf "%s" "$*" | xclip -sel clip

23
bin/xsekrit.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/sh
# env
# Written in 2019 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/>.
clip() { xclip -q -l 1 -sel clip 2>/dev/null; }
if [ $# -ne 1 ] || [ -z "$1" ]; then
printf "Usage: %s key\n" "${0##*/}" >&2
exit 1
fi
if ! sekrit has "$1"; then
printf "%s: Unknown key \"%s\".\n" "${0##*/}" "$1" >&2
exit 1
fi
sekrit get "$1" | clip