termux-api.c: rand() -> arc4random()
[termux-packages] / packages / termux-api / termux-download
CommitLineData
cc1ae02e 1#!/bin/sh
59f0d218
FF
2set -e -u
3
8d6e165f 4SCRIPTNAME=termux-download
59f0d218 5show_usage () {
8d6e165f
FF
6 echo "Usage: $SCRIPTNAME [OPTIONS] <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 exit 0
59f0d218
FF
12}
13
8d6e165f
FF
14ARG_D=""
15OPT_D=""
16ARG_T=""
17OPT_T=""
18
19while getopts :hd:t: option
20do
21 case "$option" in
22 h) show_usage;;
23 d) ARG_D="--es description"; OPT_D="$OPTARG";;
24 t) ARG_T="--es title"; OPT_T="$OPTARG";;
25 ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
26 esac
59f0d218 27done
8d6e165f
FF
28shift $(($OPTIND-1))
29
30if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
31if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
32
33URL_TO_DOWNLOAD="$1"
59f0d218 34
8d6e165f
FF
35set --
36if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
37if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
38set -- "$@" $URL_TO_DOWNLOAD
59f0d218 39
8d6e165f 40@TERMUX_API@ Download "$@"