Skip to content

Commit 34b8d6a

Browse files
authored
Script for run Nfc activity from Termux:API (#113)
1 parent 70bd13b commit 34b8d6a

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

scripts/termux-nfc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!@TERMUX_PREFIX@/bin/bash
2+
3+
set -e -u
4+
5+
show_usage() {
6+
echo "Usage: termux-nfc [-r [short|full]] [-w] [-t [text for TAG] "
7+
echo " read/write data from/to NDEF tag "
8+
echo " -r, read tag "
9+
echo " short, read short information from tag "
10+
echo " full, read full information from tag "
11+
echo " -w, write information on tag "
12+
echo " -t, text for tag"
13+
exit 0
14+
}
15+
16+
ARG_R=""
17+
OPT_R=""
18+
ARG_W=""
19+
OPT_T=""
20+
ARG_T=""
21+
22+
PARAM=""
23+
24+
if [ $# -eq 0 ];then show_usage;fi
25+
26+
while getopts ":r:t:w" opt
27+
do
28+
case "$opt" in
29+
r) ARG_R="--es mode read"; OPT_R="--es param $OPTARG"; ;;
30+
w) ARG_W="--es mode write";;
31+
t) ARG_T="--es param text --es value"; OPT_T="$OPTARG"; ;;
32+
?) echo "Error: unknown parameters: $opt $OPTARG;";show_usage; ;;
33+
esac
34+
done
35+
36+
37+
shift $((OPTIND-1))
38+
39+
if [ "$#" != 0 ]; then echo "Error: too many parameters!"; show_usage;fi
40+
if [ -n "$ARG_R" ]; then if [ -n "$ARG_W" ]; then echo "Error: Incompatible parameters! \"-r and \"-n";show_usage;fi;fi
41+
42+
43+
44+
if [ -n "$ARG_R" ]; then set -- "$@" $ARG_R $OPT_R;fi
45+
if [ -n "$ARG_W" ]; then set -- "$@" $ARG_W;fi
46+
if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T";fi
47+
@TERMUX_PREFIX@/libexec/termux-api Nfc "$@"

0 commit comments

Comments
 (0)