summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-11-10 14:41:38 -0500
committerJesse Luehrs <doy@tozt.net>2018-11-10 14:43:14 -0500
commit09366721b4a5405ccd24e21c9f0c4edd25d51196 (patch)
treefd72dec2d55f51aecc1b76b01dd7ed18c1be9d87 /bin
parent12d2a797346af8fc2908bf5d7873414811a7e9cc (diff)
downloadconf-09366721b4a5405ccd24e21c9f0c4edd25d51196.tar.gz
conf-09366721b4a5405ccd24e21c9f0c4edd25d51196.zip
various script cleanups
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cryptdir27
-rwxr-xr-xbin/fm22avi7
-rwxr-xr-xbin/git/git-file-size2
-rwxr-xr-xbin/history-stats (renamed from bin/history_stats)0
-rwxr-xr-xbin/hostcert9
-rwxr-xr-xbin/hush/kill-focused (renamed from bin/hush/kill_focused)0
-rwxr-xr-xbin/hush/numkeys2
-rwxr-xr-xbin/hush/setup-inputs4
-rwxr-xr-xbin/hush/svdn8
-rwxr-xr-xbin/hush/svget4
-rwxr-xr-xbin/hush/svkill4
-rwxr-xr-xbin/hush/svlog4
-rwxr-xr-xbin/hush/svnuke4
-rwxr-xr-xbin/hush/svre4
-rwxr-xr-xbin/hush/svst4
-rwxr-xr-xbin/hush/svstop4
-rwxr-xr-xbin/hush/svup4
-rwxr-xr-xbin/hush/update-mail8
-rwxr-xr-xbin/hush/volume4
-rwxr-xr-xbin/hush/webcam3
-rwxr-xr-xbin/mem-usage5
-rwxr-xr-xbin/mem_usage3
-rwxr-xr-xbin/p76
-rwxr-xr-xbin/pdfcat8
-rwxr-xr-xbin/pick-music (renamed from bin/pick_music)2
-rwxr-xr-xbin/pt6
-rwxr-xr-xbin/rand-music (renamed from bin/rand_music)4
-rwxr-xr-xbin/rand_line7
-rwxr-xr-xbin/ringtone21
-rwxr-xr-xbin/setfont4
-rwxr-xr-xbin/show-colors (renamed from bin/show_colors)11
-rwxr-xr-xbin/sum8
-rwxr-xr-xbin/t6
-rwxr-xr-xbin/tozt/learn_spam18
-rwxr-xr-xbin/vimmanpager3
35 files changed, 137 insertions, 151 deletions
diff --git a/bin/cryptdir b/bin/cryptdir
index 4434e6e..3fb858f 100755
--- a/bin/cryptdir
+++ b/bin/cryptdir
@@ -1,13 +1,15 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
-if [[ -e /dev/mapper/cryptdir ]]; then
+if [ -e /dev/mapper/cryptdir ]; then
echo "only one instance can run at a time" 1>&2
exit 1
fi
sudo -v || exit 1
-if [[ -z $1 ]]; then
+if [ -z "${1:-}" ]; then
size='16M'
else
size=$1
@@ -18,20 +20,21 @@ cryptdir=$(mktemp -d)
pass=$(dd if=/dev/urandom bs=1 count=80 | base64)
cleanup () {
+ set +e
cd
- sudo umount $cryptdir
+ sudo umount "$cryptdir"
sudo cryptsetup close cryptdir
- rm -f $cryptfile
- rmdir $cryptdir
+ rm -f "$cryptfile"
+ rmdir "$cryptdir"
}
trap cleanup EXIT
-dd if=/dev/urandom of=$cryptfile bs=$size count=1
-echo $pass | sudo cryptsetup luksFormat $cryptfile -
-echo $pass | sudo cryptsetup open $cryptfile cryptdir --key-file -
+dd if=/dev/urandom of="$cryptfile" bs="$size" count=1
+echo "$pass" | sudo cryptsetup luksFormat "$cryptfile" -
+echo "$pass" | sudo cryptsetup open "$cryptfile" cryptdir --key-file -
sudo mkfs.ext2 /dev/mapper/cryptdir
-sudo mount /dev/mapper/cryptdir $cryptdir
-sudo chown $USER $cryptdir
-cd $cryptdir
+sudo mount /dev/mapper/cryptdir "$cryptdir"
+sudo chown "$USER" "$cryptdir"
+cd "$cryptdir"
$SHELL
diff --git a/bin/fm22avi b/bin/fm22avi
index 5d11d58..eebfb4f 100755
--- a/bin/fm22avi
+++ b/bin/fm22avi
@@ -1,3 +1,8 @@
#!/bin/bash
+set -eu
+set -o pipefail
-fceux --playmov $1.fm2 --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 $2 --videolog "mencoder - -o $1.avi -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS"
+movie="$1"
+rom="$2"
+
+fceux --playmov "$movie" --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 "$rom" --videolog "mencoder - -o ${movie/.fm2/.avi} -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS"
diff --git a/bin/git/git-file-size b/bin/git/git-file-size
index 2a90373..0e7d00d 100755
--- a/bin/git/git-file-size
+++ b/bin/git/git-file-size
@@ -1,3 +1,5 @@
#!/bin/sh
+set -eu
+set -o pipefail
git ls-files -z | xargs -0 du -b | sum
diff --git a/bin/history_stats b/bin/history-stats
index b289f97..b289f97 100755
--- a/bin/history_stats
+++ b/bin/history-stats
diff --git a/bin/hostcert b/bin/hostcert
index 561244c..545167a 100755
--- a/bin/hostcert
+++ b/bin/hostcert
@@ -1,3 +1,8 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
-openssl s_client -connect "$1" < /dev/null 2>/dev/null | perl -nle 'print if /BEGIN CERTIFICATE/../END CERTIFICATE/' | openssl x509 -text | perl -nle 'print unless /BEGIN CERTIFICATE/../END CERTIFICATE/'
+host="$1"
+port="${2:-443}"
+
+openssl s_client -connect "$host:$port" < /dev/null 2>/dev/null | perl -nle 'print if /BEGIN CERTIFICATE/../END CERTIFICATE/' | openssl x509 -text | perl -nle 'print unless /BEGIN CERTIFICATE/../END CERTIFICATE/'
diff --git a/bin/hush/kill_focused b/bin/hush/kill-focused
index 37271ac..37271ac 100755
--- a/bin/hush/kill_focused
+++ b/bin/hush/kill-focused
diff --git a/bin/hush/numkeys b/bin/hush/numkeys
index ab9dc14..9d037f5 100755
--- a/bin/hush/numkeys
+++ b/bin/hush/numkeys
@@ -1,4 +1,6 @@
#!/bin/sh
+set -eu
+set -o pipefail
on() {
xmodmap -e 'keycode 10 = exclam 1'
diff --git a/bin/hush/setup-inputs b/bin/hush/setup-inputs
index 6aaa19f..94e8e7f 100755
--- a/bin/hush/setup-inputs
+++ b/bin/hush/setup-inputs
@@ -1,9 +1,11 @@
#!/bin/sh
+set -eu
+set -o pipefail
# key bindings
setxkbmap -option ctrl:nocaps
setxkbmap -option compose:caps
-xmodmap $HOME/.Xmodmap
+xmodmap "$HOME"/.Xmodmap
"$(dirname "$0")"/numkeys on
# trackpad settings
diff --git a/bin/hush/svdn b/bin/hush/svdn
index ce6f4c4..9e0fa0b 100755
--- a/bin/hush/svdn
+++ b/bin/hush/svdn
@@ -1,13 +1,15 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svst "$1" && svstop "$1"
svst "$1" && sleep 1
svst "$1" && svstop "$1"
-for i in 1..5; do
+for _ in $(seq 1 5); do
svst "$1" && sleep 1
done
svst "$1" && svstop "$1"
-for i in 1..10; do
+for _ in $(seq 1 10); do
svst "$1" && sleep 1
done
svst "$1" && svkill "$1"
diff --git a/bin/hush/svget b/bin/hush/svget
index 77c18f4..0eab9bf 100755
--- a/bin/hush/svget
+++ b/bin/hush/svget
@@ -1,3 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svstat "$HOME/.services/enabled/$1"
diff --git a/bin/hush/svkill b/bin/hush/svkill
index 060d2c7..a84e1a2 100755
--- a/bin/hush/svkill
+++ b/bin/hush/svkill
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svc -k "$HOME/.services/enabled/$1"
svget "$1"
diff --git a/bin/hush/svlog b/bin/hush/svlog
index 436b25a..201ce9b 100755
--- a/bin/hush/svlog
+++ b/bin/hush/svlog
@@ -1,3 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
tail -F "$HOME/.log/$1/current" | tai64nlocal
diff --git a/bin/hush/svnuke b/bin/hush/svnuke
index 6a383ce..309a1d5 100755
--- a/bin/hush/svnuke
+++ b/bin/hush/svnuke
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svdn "$1"
svdn "$1/log"
diff --git a/bin/hush/svre b/bin/hush/svre
index e57576e..159b017 100755
--- a/bin/hush/svre
+++ b/bin/hush/svre
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svdn "$1"
svup "$1"
diff --git a/bin/hush/svst b/bin/hush/svst
index 92d20c1..4d0c6ce 100755
--- a/bin/hush/svst
+++ b/bin/hush/svst
@@ -1,3 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svget "$1" | grep -q ": up ("
diff --git a/bin/hush/svstop b/bin/hush/svstop
index 36c0132..649ec26 100755
--- a/bin/hush/svstop
+++ b/bin/hush/svstop
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svc -d "$HOME/.services/enabled/$1"
svget "$1"
diff --git a/bin/hush/svup b/bin/hush/svup
index c49a99e..3772fdb 100755
--- a/bin/hush/svup
+++ b/bin/hush/svup
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
svc -u "$HOME/.services/enabled/$1"
svget "$1"
diff --git a/bin/hush/update-mail b/bin/hush/update-mail
index b909d9f..8149a8d 100755
--- a/bin/hush/update-mail
+++ b/bin/hush/update-mail
@@ -1,9 +1,11 @@
#!/bin/sh
+set -eu
+set -o pipefail
stat=$(svstat "$HOME/.services/enabled/offlineimap")
-if echo $stat | grep -q "offlineimap: down"; then
+if echo "$stat" | grep -q "offlineimap: down"; then
echo "no offlineimap process running" >&2
exit 1
fi
-pid=$(echo $stat | sed 's/.*offlineimap: up (pid \([[:digit:]]\+\)).*/\1/')
-kill -USR1 $pid
+pid=$(echo "$stat" | sed 's/.*offlineimap: up (pid \([[:digit:]]\+\)).*/\1/')
+kill -USR1 "$pid"
diff --git a/bin/hush/volume b/bin/hush/volume
index e4c81fb..a0df2d3 100755
--- a/bin/hush/volume
+++ b/bin/hush/volume
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
case $1 in
up)
diff --git a/bin/hush/webcam b/bin/hush/webcam
index 48ee3f3..fdac5f8 100755
--- a/bin/hush/webcam
+++ b/bin/hush/webcam
@@ -1,2 +1,5 @@
#!/bin/sh
+set -eu
+set -o pipefail
+
mpv av://v4l2:/dev/video0
diff --git a/bin/mem-usage b/bin/mem-usage
new file mode 100755
index 0000000..19e8c32
--- /dev/null
+++ b/bin/mem-usage
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+ps -eo rss,ucmd | sort -rn | head -n"${1:-20}"
diff --git a/bin/mem_usage b/bin/mem_usage
deleted file mode 100755
index 038009e..0000000
--- a/bin/mem_usage
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-ps -eo rss,ucmd | sort -rn | head -n$([ -z "$1" ] && echo 20 || echo $1)
diff --git a/bin/p b/bin/p
deleted file mode 100755
index a52ba1e..0000000
--- a/bin/p
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/bash
-
-_clean () {
- git clean -dfx
- ctags *.c *.h
-}
-
-_configure () {
- # XXX breaks when building Compress::Raw::Zlib, nobody else can reproduce?
- # ./Configure -des -Dusedevel -DDEBUGGING -Dusethreads -Uversiononly -Accflags="-Wall -Wextra" -Doptimize="-g -O0 -ggdb3"
- # can't do this with -Werror, not everything (external modules, say) is
- # -Werror clean
- # ./Configure -des -Dusedevel -Accflags="-Wall -Wextra"
- ./Configure -des -Dusedevel -DDEBUGGING
-}
-
-_make () {
- if [[ ! -e Makefile ]]; then
- _configure
- fi
- # -Werror at configure time seems to confuse Configure, so do it here
- make -j9 OPTIMIZE="-g -Werror"
-}
-
-_test () {
- if [[ ! -e perl ]]; then
- _make
- fi
- export TEST_JOBS=9
- if [ -n "$*" ]; then
- make test_harness TEST_FILES="$*"
- else
- make test_harness
- fi
-}
-
-_test_porting () {
- if [[ ! -e perl ]]; then
- _make
- fi
- export TEST_JOBS=9
- if [ -n "$*" ]; then
- make test_porting TEST_FILES="$*"
- else
- make test_porting
- fi
-}
-
-cmd=$1
-shift
-
-case $cmd in
- cl|clean)
- _clean $@
- ;;
- c|conf|configure)
- _configure $@
- ;;
- m|make)
- _make $@
- ;;
- t|test)
- _test $@
- ;;
- tp|test_porting)
- _test_porting $@
- ;;
- a|all)
- _clean
- _test
- ;;
- *)
- echo "Usage: p <command> [args...]" 1>&2
- exit 1
- ;;
-esac
diff --git a/bin/pdfcat b/bin/pdfcat
index 663f0af..ff4edaa 100755
--- a/bin/pdfcat
+++ b/bin/pdfcat
@@ -1,5 +1,7 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
-local out=$1
+out="$1"
shift
-gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$out $*
+gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$out" "$@"
diff --git a/bin/pick_music b/bin/pick-music
index fe65dbc..8c406f7 100755
--- a/bin/pick_music
+++ b/bin/pick-music
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
set -eu
set -o pipefail
diff --git a/bin/pt b/bin/pt
index a69df1b..c5ca9b9 100755
--- a/bin/pt
+++ b/bin/pt
@@ -1,6 +1,8 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
-if [[ -d blib ]]; then
+if [ -d blib ]; then
prove -Mlib::require::all=blib/lib,blib/arch -b "$@" t
else
prove -Mlib::require::all=lib -l "$@" t
diff --git a/bin/rand_music b/bin/rand-music
index ecf6666..6e9bccc 100755
--- a/bin/rand_music
+++ b/bin/rand-music
@@ -1,8 +1,8 @@
-#!/bin/bash
+#!/bin/sh
set -eu
set -o pipefail
-if [[ "${1:-}" == '--old' ]]; then
+if [ "${1:-}" = '--old' ]; then
extra_args="--exclude yearly --include all"
shift
else
diff --git a/bin/rand_line b/bin/rand_line
deleted file mode 100755
index 7eba7ab..0000000
--- a/bin/rand_line
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/perl
-
-my $save = '';
-while (<>) {
- $save = $_ if !int rand $.;
-}
-print $save;
diff --git a/bin/ringtone b/bin/ringtone
index 5c8cfe1..19dddb6 100755
--- a/bin/ringtone
+++ b/bin/ringtone
@@ -1,4 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
if [ $# -lt 3 ]; then
echo "usage: ringtone <input> <output> <fake_video_file>"
@@ -7,11 +9,12 @@ if [ $# -lt 3 ]; then
exit 1
fi
-mencoder -ovc frameno \
- -oac mp3lame \
- -lameopts cbr:br=64 \
- -of rawaudio \
- -o $2 \
- -audiofile $1 \
- -endpos 256kb \
- $3
+mencoder \
+ -ovc frameno \
+ -oac mp3lame \
+ -lameopts cbr:br=64 \
+ -of rawaudio \
+ -o "$2" \
+ -audiofile "$1" \
+ -endpos 256kb \
+ "$3"
diff --git a/bin/setfont b/bin/setfont
index 50b4b78..d3e9f2a 100755
--- a/bin/setfont
+++ b/bin/setfont
@@ -1,3 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
printf '\e]710;%s\007\e]711;%s\007' "$1" "$1"
diff --git a/bin/show_colors b/bin/show-colors
index 35c5374..be1a489 100755
--- a/bin/show_colors
+++ b/bin/show-colors
@@ -1,4 +1,7 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
+
############################################################
# Nico Golde <nico(at)ngolde.de> Homepage: http://www.ngolde.de
# Last change: Mon Feb 16 16:24:41 CET 2004
@@ -6,7 +9,7 @@
for attr in 0 1 2 3 4 5 6 7 ; do
echo "----------------------------------------------------------------"
- printf "ESC[%s;Foreground;Background - \n" $attr
+ printf 'ESC[%s;Foreground;Background - \n' $attr
for fore in 30 31 32 33 34 35 36 37; do
for back in 40 41 42 43 44 45 46 47; do
printf '\033[%s;%s;%sm %02s;%02s ' $attr $fore $back $fore $back
@@ -18,8 +21,8 @@ done
printf '\n'
for color in $(seq 0 255); do
- printf '\033[%s;%s;%sm \033[m' 48 5 $color
- if [[ $color -eq 15 || $(echo "scale = 0; ($color - 15) % 36" | bc) -eq 0 ]]; then
+ printf '\033[%s;%s;%sm \033[m' 48 5 "$color"
+ if [ "$color" -eq 15 ] || [ "$(echo "scale = 0; ($color - 15) % 36" | bc)" -eq 0 ]; then
printf '\n'
fi
done
diff --git a/bin/sum b/bin/sum
index df7cd81..cf21bfd 100755
--- a/bin/sum
+++ b/bin/sum
@@ -1,4 +1,8 @@
#!/usr/bin/env perl
-use 5.010;
+use strict;
+use warnings;
+use 5.014;
+
use List::Util 'sum';
-say sum map { s/^((?:\d|[-+\.])+).*/$1/; $_ } <>;
+
+say sum map { s/^([-+\.\d]+).*/$1/r } <>;
diff --git a/bin/t b/bin/t
index beffa0e..b6c065a 100755
--- a/bin/t
+++ b/bin/t
@@ -1,6 +1,8 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
-if [[ -d blib ]]; then
+if [ -d blib ]; then
perl -Mblib "$@"
else
perl -Ilib "$@"
diff --git a/bin/tozt/learn_spam b/bin/tozt/learn_spam
index ab5603a..128ca9a 100755
--- a/bin/tozt/learn_spam
+++ b/bin/tozt/learn_spam
@@ -1,10 +1,12 @@
-#!/bin/bash
+#!/bin/sh
+set -eu
+set -o pipefail
MAILDIR=~/Maildir
OPTS="--no-sync"
SALEARN=/usr/bin/vendor_perl/sa-learn
-if [[ "$1" == "-q" ]]; then
+if [ "$1" = "-q" ]; then
OPTS="$OPTS"
OUTFILE="/dev/null"
else
@@ -12,25 +14,25 @@ else
OUTFILE="/dev/stdout"
fi
-if [[ ! "$1" == "-q" ]]; then
+if [ ! "$1" = "-q" ]; then
echo "$(date): Learning ham..."
fi
nice find $MAILDIR -type f | \
perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && !m{/(\.old|\.spam)/} && $ts > $now - 60*60*24*30' | \
- xargs -n1000 -0 $SALEARN $OPTS --ham > $OUTFILE
+ xargs -n1000 -0 $SALEARN "$OPTS" --ham > $OUTFILE
-if [[ ! "$1" == "-q" ]]; then
+if [ ! "$1" = "-q" ]; then
echo "$(date): Learning spam..."
fi
nice find $MAILDIR -type f | \
perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && m{/\.spam/} && $ts > $now - 60*60*24*30' | \
- xargs -n1000 -0 $SALEARN $OPTS --spam > $OUTFILE
+ xargs -n1000 -0 $SALEARN "$OPTS" --spam > $OUTFILE
-if [[ ! "$1" == "-q" ]]; then
+if [ ! "$1" = "-q" ]; then
echo "$(date): Syncing..."
fi
nice $SALEARN --sync > $OUTFILE
-if [[ ! "$1" == "-q" ]]; then
+if [ ! "$1" = "-q" ]; then
echo "$(date): Done!"
fi
diff --git a/bin/vimmanpager b/bin/vimmanpager
index 9df7f94..d33e4f9 100755
--- a/bin/vimmanpager
+++ b/bin/vimmanpager
@@ -1,4 +1,7 @@
#!/bin/sh
+set -eu
+set -o pipefail
+
sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -b | \
vim \
-c 'let no_plugin_maps = 1' \