chiark / gitweb /
vim: Use sensible.vim as system vimrc
[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 "  -d description  description for the download request notification"
9     echo "  -t title        title for the download request notification"
10     exit 0
11 }
12
13 ARG_D=""
14 OPT_D=""
15 ARG_T=""
16 OPT_T=""
17
18 while getopts :hd:t: option
19 do
20     case "$option" in
21         h) show_usage;;
22         d) ARG_D="--es description"; OPT_D="$OPTARG";;
23         t) ARG_T="--es title"; OPT_T="$OPTARG";;
24         ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
25     esac
26 done
27 shift $(($OPTIND-1))
28
29 if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
30 if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
31
32 URL_TO_DOWNLOAD="$1"
33
34 set --
35 if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
36 if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
37 set -- "$@" $URL_TO_DOWNLOAD
38
39 @TERMUX_API@ Download "$@"