-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathtermux-nfc.in
52 lines (40 loc) · 1.52 KB
/
termux-nfc.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!@TERMUX_PREFIX@/bin/bash
set -e -u
show_usage() {
echo "Usage: termux-nfc [-r [short|full]] [-w] [-t [text for TAG] "
echo " read/write data from/to NDEF tag "
echo " -r, read tag "
echo " short, read short information from tag "
echo " full, read full information from tag "
echo " -w, write information on tag "
echo " -a, advanced write. \npass a base64 encoded string of bytes to -t, \nand a mime type to this argument.\nyou may also pass 'uri' as the mime type to write a raw uri\nfrom the -t arg."
echo " -t, text for tag"
exit 0
}
ARG_A=""
OPT_A=""
ARG_R=""
OPT_R=""
ARG_W=""
OPT_T=""
ARG_T=""
PARAM=""
if [ $# -eq 0 ];then show_usage;fi
while getopts ":r:t:a:w" opt
do
case "$opt" in
r) ARG_R="--es mode read"; OPT_R="--es param $OPTARG"; ;;
w) ARG_W="--es mode write";;
t) ARG_T="--es param text --es value"; OPT_T="$OPTARG"; ;;
a) ARG_A="--es mode mimeWrite --es mime"; OPT_A="$OPTARG"; ;;
?) echo "Error: unknown parameters: $opt $OPTARG;";show_usage; ;;
esac
done
shift $((OPTIND-1))
if [ "$#" != 0 ]; then echo "Error: too many parameters!"; show_usage;fi
if [ -n "$ARG_R" ]; then if [ -n "$ARG_W" ]; then echo "Error: Incompatible parameters! \"-r and \"-n";show_usage;fi;fi
if [ -n "$ARG_R" ]; then set -- "$@" $ARG_R $OPT_R;fi
if [ -n "$ARG_W" ]; then set -- "$@" $ARG_W;fi
if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T";fi
if [ -n "$ARG_A" ]; then set -- "$@" $ARG_A "$OPT_A";fi
@TERMUX_PREFIX@/libexec/termux-api Nfc "$@"