termux-api: Cleanup and improve consistency
[termux-packages] / packages / termux-api / termux-download
1 #!/bin/sh
2 set -e -u
3
4 SCRIPTNAME=termux-download
5 show_usage () {
6 echo "Usage: $SCRIPTNAME [-d description] [-t title] url-to-download"
7 echo "Download a resource using the system download manager."
8 echo ""
9 echo " -d description description for the download request notification"
10 echo " -t title title for the download request notification"
11 echo ""
12 exit 0
13 }
14
15 ARG_D=""
16 OPT_D=""
17 ARG_T=""
18 OPT_T=""
19
20 while getopts :hd:t: option
21 do
22 case "$option" in
23 h) show_usage;;
24 d) ARG_D="--es description"; OPT_D="$OPTARG";;
25 t) ARG_T="--es title"; OPT_T="$OPTARG";;
26 ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
27 esac
28 done
29 shift $(($OPTIND-1))
30
31 if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
32 if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
33
34 URL_TO_DOWNLOAD="$1"
35
36 set --
37 if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
38 if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
39 set -- "$@" $URL_TO_DOWNLOAD
40
41 @TERMUX_API@ Download "$@"