From 1295610ad7d9619a8d7fec98751f8df3c32ed928 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 5 Dec 2023 03:22:37 -0500 Subject: sbodl: add -n option, use getopt for better option processing. --- sbodl | 78 +++++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/sbodl b/sbodl index 5cc2c09..9d62ed8 100755 --- a/sbodl +++ b/sbodl @@ -19,7 +19,13 @@ sbodl - download and/or check md5sums for SlackBuilds.org source files. =head1 SYNOPSIS -B [--help] | [ --version ] | [-a | -f | -af ] [I ...] +B [-h | --help] + +B [-m | --man ] + +B --version + +B [ [-a | --archive] | [-f | --force] | [-n | --no-content-disposition] ] [ -- I ...] =head1 DESCRIPTION @@ -35,8 +41,8 @@ creating a tarball of your SlackBuild directory for upload, without losing the actual files. It also allows builds that use the same source files to share them (no need to re-download). -By default, B<--content-disposition> is used. If you want to disable it, use -the B<--no-content-disposition> wget option. +By default, B<--content-disposition> is used. If you want to disable +it, use the B<-n>, B<--no-content-disposition> option. If you need to download files for a different architecture (e.g. 32-bit files when running on a 64-bit OS), you can override ARCH @@ -46,26 +52,27 @@ file(s). This only matters if there's a DOWNLOAD_x86_64 URL in the =head1 OPTIONS -B: Any arguments other than the options listed below are passed -through to B(1) verbatim. Also, only the first argument may be -a B option. This means you can't say B<-a -f>; use B<-af> or B<-fa> instead. +B: Any arguments after B<--> are passed through to B(1) verbatim. =over 4 -=item B<-a> +=item B<-a>, B<--archive> Download from the SBo Source Archive (sbosrcarch) rather than the original URL(s). Use this if the original site is down or the file has gone 404. See ENVIRONMENT, if you need to change the sbosrcarch URL. -=item B<-f> +=item B<-f>, B<--force> Force downloading the file(s), even if they already exist in the current directory or in the cache. -=item B<-af>, B<-fa> +=item B<-n>, B<--no-content-disposition> -Combine the above two options (B<-a> and B<-f>). +Ignore the I header; save the file using the +filename in the URL rather than the name suggested in the HTTP +headers. This option just passes B<--no-content-disposition> to +B. =item B<--help>, B<--doc> @@ -125,12 +132,15 @@ md5sum failures. This is most noticeable with I builds, with filenames like B<1.cabal>, B<2.cabal>, etc. At some point this will be fixed. For now, if this happens, use the B<-f> option. -Also, since --content-disposition is used, occasionally the downloaded -filename won't match the filename in the URL, and B will warn -that it can't find the downloaded file. Again, this will be fixed -soonish. I left this enabled specifically to detect URLs that have -this problem (mostly, these are github URLs and there's a way to -rewrite them to work either way). +Not really a bug: since B<--content-disposition> is used, occasionally +the downloaded filename won't match the filename in the URL, and +B will warn that it can't find the downloaded file. I left this +enabled specifically to detect URLs that have this problem: mostly, +these are github URLs and there's a way to rewrite them to work either +way. B SlackBuild scripts that deal with URLs like this +can handle either possible filename, or else they use a URL that uses +the same filename either way. If you have to, use B<-n> to ignore +content disposition. =head1 AUTHOR @@ -163,17 +173,29 @@ die() { exit 1 } -[ -d "$CACHEDIR/" ] || mkdir -p $CACHEDIR || die "Can't create $CACHEDIR" +CONTDISP="--content-disposition" + +# 20231205 bkw: fancy argument checking. note that getopt is part of +# util-linux; do not confuse it with bash's built-in getopts (with an "s"). +OPTS=$( getopt -n 1.sh -o vmhafn -l help,man,doc,version,archive,force,no-content-disposition -- "$@" ) +eval set -- "$OPTS" +while true; do + case "$1" in + -h|--help|--doc) exec perldoc "$0" ;; + -m|--man) exec pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION "$0" ;; + -v|--version) echo $VERSION ; exit 0 ;; + -a|--archive) USEARCHIVE="yes" ; shift ; continue ;; + -f|--force) FORCEDL="yes" ; shift ; continue ;; + -n) CONTDISP="--no-content-disposition" ; shift ; continue ;; + --) shift; break ;; + esac +done + +if [ "$*" != "" ]; then + echo -e "${YELLOW}Passing extra arguments to wget: ${RED}$@${COLOR_OFF}" +fi -# check for our one argument -case "$1" in - -v|--version) echo $VERSION ; exit 0 ;; - -h|--help|--doc) exec perldoc "$0" ;; - --man) exec pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION "$0" ;; - -f) FORCEDL="yes" ; shift ;; - -a) USEARCHIVE="yes" ; shift ;; - -fa|-af) FORCEDL="yes" ; USEARCHIVE="yes" ; shift ;; -esac +[ -d "$CACHEDIR/" ] || mkdir -p $CACHEDIR || die "Can't create $CACHEDIR" source ./$( basename $( pwd ) ).info \ || die "No .info file, are you sure this is a SBo directory? Try '$SELF --help'" @@ -218,9 +240,9 @@ for dl in $DL; do dl="$ARCHIVE/by-md5/$a/$b/$1/$file" fi - EXTRAWGETARGS="--content-disposition " + EXTRAWGETARGS="$CONTDISP" case "$dl" in - *sourceforge.net/*|*.sf.net/*) EXTRAWGETARGS="--user-agent wget" ;; + *sourceforge.net/*|*.sf.net/*) EXTRAWGETARGS="$EXTRAWGETARGS --user-agent wget" ;; *) ;; esac -- cgit v1.2.3