aboutsummaryrefslogtreecommitdiff
path: root/sbodl
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2023-12-05 03:22:37 -0500
committerB. Watson <urchlay@slackware.uk>2023-12-05 03:24:27 -0500
commit1295610ad7d9619a8d7fec98751f8df3c32ed928 (patch)
treeab27c8867a3112996930cea711dacf8713e5d836 /sbodl
parentefc3d0fad67604fb68351b1a088a5ba9f75d446b (diff)
downloadsbo-maintainer-tools-1295610ad7d9619a8d7fec98751f8df3c32ed928.tar.gz
sbodl: add -n option, use getopt for better option processing.
Diffstat (limited to 'sbodl')
-rwxr-xr-xsbodl78
1 files 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<sbodl> [--help] | [ --version ] | [-a | -f | -af ] [I<wget-options> ...]
+B<sbodl> [-h | --help]
+
+B<sbodl> [-m | --man ]
+
+B<sbodl> --version
+
+B<sbodl> [ [-a | --archive] | [-f | --force] | [-n | --no-content-disposition] ] [ -- I<wget-options> ...]
=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<NOTE>: Any arguments other than the options listed below are passed
-through to B<wget>(1) verbatim. Also, only the first argument may be
-a B<sbodl> option. This means you can't say B<-a -f>; use B<-af> or B<-fa> instead.
+B<NOTE>: Any arguments after B<--> are passed through to B<wget>(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<Content-Disposition> 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<wget>.
=item B<--help>, B<--doc>
@@ -125,12 +132,15 @@ md5sum failures. This is most noticeable with I<haskell/> 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<sbodl> 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<sbodl> 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<Well-written> 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