Fredrik Fornwall
9 years ago
5 changed files with 50 additions and 30 deletions
@ -1,30 +1,40 @@ |
|||||
#!/bin/sh |
#!/bin/sh |
||||
|
|
||||
set -e -u |
set -e -u |
||||
|
|
||||
SCRIPTNAME=$0 |
SCRIPTNAME=termux-download |
||||
show_usage () { |
show_usage () { |
||||
echo "usage: termux-download <uri-to-download>" |
echo "Usage: $SCRIPTNAME [OPTIONS] <url-to-download>" |
||||
echo " Download a resource using the system download manager." |
echo "Download a resource using the system download manager." |
||||
echo " -d, --description Description for the download request notification" |
echo "" |
||||
echo " -t, --title Title for the download request notification" |
echo " -d <description> description for the download request notification" |
||||
|
echo " -t <title> title for the download request notification" |
||||
|
exit 0 |
||||
} |
} |
||||
|
|
||||
PARAMS="" |
ARG_D="" |
||||
O=`busybox getopt -q -l description: -l title: -l help -- d:t:h "$@"` |
OPT_D="" |
||||
if [ $? != 0 ] ; then show_usage; exit 1 ; fi |
ARG_T="" |
||||
eval set -- "$O" |
OPT_T="" |
||||
while true; do |
|
||||
case "$1" in |
while getopts :hd:t: option |
||||
-h|--help) show_usage; exit 0;; |
do |
||||
-d|--description) PARAMS="$PARAMS --es description '$2'"; shift 2;; |
case "$option" in |
||||
-t|--title) PARAMS="$PARAMS --es title '$2'"; shift 2;; |
h) show_usage;; |
||||
--) shift; break;; |
d) ARG_D="--es description"; OPT_D="$OPTARG";; |
||||
*) echo Error; exit 1;; |
t) ARG_T="--es title"; OPT_T="$OPTARG";; |
||||
esac |
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; |
||||
|
esac |
||||
done |
done |
||||
|
shift $(($OPTIND-1)) |
||||
|
|
||||
|
if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi |
||||
|
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
||||
|
|
||||
|
URL_TO_DOWNLOAD="$1" |
||||
|
|
||||
# Too many arguments: |
set -- |
||||
if [ $# != 1 ]; then show_usage; exit 1; fi |
if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi |
||||
|
if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi |
||||
|
set -- "$@" $URL_TO_DOWNLOAD |
||||
|
|
||||
eval @TERMUX_API@ Download $PARAMS $1 |
@TERMUX_API@ Download "$@" |
||||
|
Loading…
Reference in new issue