Skip to content

Commit 1951f0e

Browse files
committed
Actually fixes sensor arguments handling
1 parent d2672c1 commit 1951f0e

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

scripts/termux-sensor

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ handle_interrupt () {
3838
cleanup () {
3939
if [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) != 0 ]; then
4040
echo "Performing sensor cleanup"
41-
call_api "-a cleanup"
41+
call_api -a cleanup
4242
else
4343
echo "No cleanup necessary"
4444
fi
@@ -59,7 +59,7 @@ get_delay () {
5959
}
6060

6161
call_api () {
62-
/data/data/com.termux/files/usr/libexec/termux-api Sensor $@
62+
/data/data/com.termux/files/usr/libexec/termux-api Sensor "$@"
6363
}
6464

6565
set_flag () {
@@ -73,31 +73,31 @@ usage_error () {
7373
}
7474

7575

76-
PARAMS=""
76+
PARAMS=()
7777
while getopts :h,a,c,l,s:d: option
7878
do
79-
case "$option" in
80-
h) show_usage ;;
81-
a) set_flag $ALL_SENSORS_FLAG; PARAMS="-a sensors $PARAMS --ez all true" ;;
82-
c) set_flag $CLEANUP_FLAG; PARAMS="-a cleanup" ;;
83-
l) set_flag $LIST_FLAG; PARAMS="-a list" ;;
84-
s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS="-a sensors --es sensors $OPTARG" ;;
85-
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS="$PARAMS --ei delay $OPTARG" ;;
86-
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
87-
esac
79+
case "$option" in
80+
h) show_usage ;;
81+
a) set_flag $ALL_SENSORS_FLAG; PARAMS=('-a' 'sensors' '--ez' 'all' 'true');;
82+
c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;;
83+
l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;;
84+
s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;;
85+
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;;
86+
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
87+
esac
8888
done
8989
shift $((OPTIND -1))
9090

9191
# Validate options were set properly
9292

9393
if [ $((FLAGS & CLEANUP_FLAG)) -ne 0 ] && [ $FLAGS -ne $CLEANUP_FLAG ]; then
94-
usage_error "No other options should be specified with -c cleanup!"
94+
usage_error "No other options should be specified with -c cleanup!"
9595
elif [ $((FLAGS & LIST_FLAG)) -ne 0 ] && [ $FLAGS -ne $LIST_FLAG ]; then
96-
usage_error "No other options should be specified with -l list!"
96+
usage_error "No other options should be specified with -l list!"
9797
elif [ $((FLAGS & DELAY_FLAG)) -ne 0 ] && [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) -eq 0 ]; then
98-
usage_error "Use -s <sensors> or -a option when using -d delay!"
98+
usage_error "Use -s <sensors> or -a option when using -d delay!"
9999
elif [ $((FLAGS & ALL_SENSORS_FLAG)) -ne 0 ] && [ $((FLAGS & SENSOR_FLAG)) -ne 0 ]; then
100-
usage_error "Listed sensors will be ignored with -a all option!"
100+
usage_error "Listed sensors will be ignored with -a all option!"
101101
fi
102102

103-
call_api $PARAMS
103+
call_api "${PARAMS[@]}"

0 commit comments

Comments
 (0)