diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-08-26 08:06:20 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-08-26 08:06:20 -0400 |
| commit | 784058f6b11d4b4056c78d8e6ad239dd54aac0f8 (patch) | |
| tree | 350fb38ac1842da5813fd8ea8d7d4398f0104140 | |
| parent | 19eb1593f804710870362f8a4ac15d164e084cfa (diff) | |
| download | misc-scripts-784058f6b11d4b4056c78d8e6ad239dd54aac0f8.tar.gz | |
litterbox: check external binary paths, pluralize (e.g. 1 hour, 2 hours).
| -rwxr-xr-x | litterbox | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -23,9 +23,13 @@ info() { [ "$VERBOSE" = "1" ] && echo "$SELF: info: $@" 1>&2 } +check_path() { + type -p "$1" &>/dev/null +} + usage() { - if ! type -p perldoc &>/dev/null; then - echo "$SELF: can't find perldoc on PATH, printing raw POD." 1>&2 + if ! check_path perldoc; then + warn "can't find perldoc on PATH, printing raw POD." exec sed -n '/^=pod/,/^=cut/p' $0 fi @@ -36,6 +40,11 @@ manpage() { exec pod2man --stderr -s1 -c"UrchlaysStuff" -r$VERSION "$0" } +pluralize() { + echo -n "$1 $2" + [ "$1" != 1 ] && echo -n "s" +} + set_expiration() { case "$1" in 1|12|24|72) ;; # OK @@ -54,7 +63,7 @@ add_url() { } copy_urls() { - if ! xsel --version &>/dev/null; then + if ! check_path; then warn "xsel not found in PATH, not copying URL(s) to clipboard" return fi @@ -67,6 +76,7 @@ copy_urls() { echo -n "$URLS" | xsel -i } +# compress_file() gets called on both files and directories. compress_file() { local ext local basefile @@ -180,6 +190,10 @@ if [ "$1" = "--help" ]; then usage ; exit 0 fi +if ! check_path curl; then + die "can't find curl on PATH (PATH is \"$PATH\")" +fi + while getopts ":e:gzcvdo:" OPT; do case "$OPT" in e) set_expiration "$OPTARG"; opt_e=1 ;; @@ -198,6 +212,20 @@ shift $(($OPTIND - 1)) [ "$GZIP" = 1 -a "$ZIP" = 1 ] && die "can't give both -g and -z" [ "$GZIP" = 1 -o "$ZIP" = 1 ] && COMPRESS=1 +if [ "$ZIP" = 1 ] && ! check_path zip; then + warn "can't find zip on PATH, disabling -z option" + ZIP=0 +fi + +if [ "$GZIP" = 1 ] && ! check_path gzip; then + warn "can't find gzip on PATH, disabling -g option" + GZIP=0 +fi + +if [ "$DOWNLOAD" = 1 -o "$ENC" = 1 ]; then + check_path openssl || die "can't find openssl on path, -c/-d won't work" +fi + if [ "$DOWNLOAD" = 1 ]; then [ "$GZIP" = 1 ] && warn "-g option ignored when using -d" [ "$ZIP" = 1 ] && warn "-z option ignored when using -d" @@ -212,7 +240,7 @@ else [ "$DLOUT" != "" ] && warn "-o option ignored when not using -d" fi -info "expire time set to $EXPIRE hour(s)" +info "expire time set to $( pluralize $EXPIRE hour )" [ "$1" = "" ] && set -- - for arg; do @@ -249,7 +277,7 @@ fi echo "$URLS" copy_urls -info "$UPLOAD_COUNT file(s) uploaded" +info "$( pluralize $UPLOAD_COUNT file ) uploaded" exit 0 |
