From d2672c131088b367188529702f3c140fe08fd334 Mon Sep 17 00:00:00 2001 From: Wendel Scardua Date: Mon, 14 May 2018 14:48:59 -0300 Subject: [PATCH 1/5] Prevent sensor names from being splitted when they contain spaces --- scripts/termux-sensor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 1c8bcb5..8257657 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -81,7 +81,7 @@ do a) set_flag $ALL_SENSORS_FLAG; PARAMS="-a sensors $PARAMS --ez all true" ;; c) set_flag $CLEANUP_FLAG; PARAMS="-a cleanup" ;; l) set_flag $LIST_FLAG; PARAMS="-a list" ;; - s) set_flag $SENSOR_FLAG; get_sensors $OPTARG; PARAMS="-a sensors --es sensors $OPTARG" ;; + s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS="-a sensors --es sensors $OPTARG" ;; d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS="$PARAMS --ei delay $OPTARG" ;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac From 1951f0e8388bd0d4897e5956eeff405a5c023ae7 Mon Sep 17 00:00:00 2001 From: Wendel Scardua Date: Thu, 7 Jun 2018 18:18:59 -0300 Subject: [PATCH 2/5] Actually fixes sensor arguments handling --- scripts/termux-sensor | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 8257657..0fb939d 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -38,7 +38,7 @@ handle_interrupt () { cleanup () { if [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) != 0 ]; then echo "Performing sensor cleanup" - call_api "-a cleanup" + call_api -a cleanup else echo "No cleanup necessary" fi @@ -59,7 +59,7 @@ get_delay () { } call_api () { - /data/data/com.termux/files/usr/libexec/termux-api Sensor $@ + /data/data/com.termux/files/usr/libexec/termux-api Sensor "$@" } set_flag () { @@ -73,31 +73,31 @@ usage_error () { } -PARAMS="" +PARAMS=() while getopts :h,a,c,l,s:d: option do - case "$option" in - h) show_usage ;; - a) set_flag $ALL_SENSORS_FLAG; PARAMS="-a sensors $PARAMS --ez all true" ;; - c) set_flag $CLEANUP_FLAG; PARAMS="-a cleanup" ;; - l) set_flag $LIST_FLAG; PARAMS="-a list" ;; - s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS="-a sensors --es sensors $OPTARG" ;; - d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS="$PARAMS --ei delay $OPTARG" ;; - ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; - esac + case "$option" in + h) show_usage ;; + a) set_flag $ALL_SENSORS_FLAG; PARAMS=('-a' 'sensors' '--ez' 'all' 'true');; + c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;; + l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;; + s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; + d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac done shift $((OPTIND -1)) # Validate options were set properly if [ $((FLAGS & CLEANUP_FLAG)) -ne 0 ] && [ $FLAGS -ne $CLEANUP_FLAG ]; then - usage_error "No other options should be specified with -c cleanup!" + usage_error "No other options should be specified with -c cleanup!" elif [ $((FLAGS & LIST_FLAG)) -ne 0 ] && [ $FLAGS -ne $LIST_FLAG ]; then - usage_error "No other options should be specified with -l list!" + usage_error "No other options should be specified with -l list!" elif [ $((FLAGS & DELAY_FLAG)) -ne 0 ] && [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) -eq 0 ]; then - usage_error "Use -s or -a option when using -d delay!" + usage_error "Use -s or -a option when using -d delay!" elif [ $((FLAGS & ALL_SENSORS_FLAG)) -ne 0 ] && [ $((FLAGS & SENSOR_FLAG)) -ne 0 ]; then - usage_error "Listed sensors will be ignored with -a all option!" + usage_error "Listed sensors will be ignored with -a all option!" fi -call_api $PARAMS +call_api "${PARAMS[@]}" From 55df207ebd568a2f347e3eaf0d3270b8eca59cdd Mon Sep 17 00:00:00 2001 From: Wendel Scardua Date: Thu, 7 Jun 2018 19:00:37 -0300 Subject: [PATCH 3/5] Fix case when -d is used before -a or -s --- scripts/termux-sensor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 0fb939d..cea1308 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -78,10 +78,10 @@ while getopts :h,a,c,l,s:d: option do case "$option" in h) show_usage ;; - a) set_flag $ALL_SENSORS_FLAG; PARAMS=('-a' 'sensors' '--ez' 'all' 'true');; + a) set_flag $ALL_SENSORS_FLAG; PARAMS+=('-a' 'sensors' '--ez' 'all' 'true');; c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;; l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;; - s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; + s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac From 8d7f7bcacf63d32df8fb07ff1440a313c401b7d3 Mon Sep 17 00:00:00 2001 From: Wendel Scardua Date: Fri, 8 Jun 2018 01:54:19 +0000 Subject: [PATCH 4/5] Restore tabs --- scripts/termux-sensor | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/termux-sensor b/scripts/termux-sensor index cea1308..17e34b3 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -59,7 +59,7 @@ get_delay () { } call_api () { - /data/data/com.termux/files/usr/libexec/termux-api Sensor "$@" + /data/data/com.termux/files/usr/libexec/termux-api Sensor "$@" } set_flag () { @@ -76,28 +76,28 @@ usage_error () { PARAMS=() while getopts :h,a,c,l,s:d: option do - case "$option" in - h) show_usage ;; - a) set_flag $ALL_SENSORS_FLAG; PARAMS+=('-a' 'sensors' '--ez' 'all' 'true');; - c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;; - l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;; - s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; - d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;; - ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; - esac + case "$option" in + h) show_usage ;; + a) set_flag $ALL_SENSORS_FLAG; PARAMS+=('-a' 'sensors' '--ez' 'all' 'true');; + c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;; + l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;; + s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; + d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac done shift $((OPTIND -1)) # Validate options were set properly if [ $((FLAGS & CLEANUP_FLAG)) -ne 0 ] && [ $FLAGS -ne $CLEANUP_FLAG ]; then - usage_error "No other options should be specified with -c cleanup!" + usage_error "No other options should be specified with -c cleanup!" elif [ $((FLAGS & LIST_FLAG)) -ne 0 ] && [ $FLAGS -ne $LIST_FLAG ]; then - usage_error "No other options should be specified with -l list!" + usage_error "No other options should be specified with -l list!" elif [ $((FLAGS & DELAY_FLAG)) -ne 0 ] && [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) -eq 0 ]; then - usage_error "Use -s or -a option when using -d delay!" + usage_error "Use -s or -a option when using -d delay!" elif [ $((FLAGS & ALL_SENSORS_FLAG)) -ne 0 ] && [ $((FLAGS & SENSOR_FLAG)) -ne 0 ]; then - usage_error "Listed sensors will be ignored with -a all option!" + usage_error "Listed sensors will be ignored with -a all option!" fi call_api "${PARAMS[@]}" From 9c89d588d61c45da4e642efd8c9a18691bd1972b Mon Sep 17 00:00:00 2001 From: Wendel Scardua Date: Fri, 8 Jun 2018 01:55:16 +0000 Subject: [PATCH 5/5] Remove unneeded single quotes --- scripts/termux-sensor | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 17e34b3..e024ca5 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -78,11 +78,11 @@ while getopts :h,a,c,l,s:d: option do case "$option" in h) show_usage ;; - a) set_flag $ALL_SENSORS_FLAG; PARAMS+=('-a' 'sensors' '--ez' 'all' 'true');; - c) set_flag $CLEANUP_FLAG; PARAMS=('-a' 'cleanup') ;; - l) set_flag $LIST_FLAG; PARAMS=('-a' 'list') ;; - s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=('-a' 'sensors' '--es' 'sensors' "$OPTARG") ;; - d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=('--ei' 'delay' $OPTARG) ;; + a) set_flag $ALL_SENSORS_FLAG; PARAMS+=(-a sensors --ez all true);; + c) set_flag $CLEANUP_FLAG; PARAMS=(-a cleanup) ;; + l) set_flag $LIST_FLAG; PARAMS=(-a list) ;; + s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=(-a sensors --es sensors "$OPTARG") ;; + d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=(--ei delay $OPTARG) ;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done