From 3f68215d12c8addebd98a6b707eca82be5371091 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Thu, 8 Aug 2019 01:18:44 +0200 Subject: [PATCH 01/68] notification: do not allow empty id with --ongoing Ongoing notifications can only be removed with termux-notification-remove, which requires the notification id. An ongoing notification without an id requires a reboot to be removed. This commit forbids creating such an "unremovable" notification. --- scripts/termux-notification | 6 ++++++ 1 file changed, 6 insertions(+) mode change 100644 => 100755 scripts/termux-notification diff --git a/scripts/termux-notification b/scripts/termux-notification old mode 100644 new mode 100755 index 6ad3358..fff6708 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -114,6 +114,12 @@ done if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi +if [ "$OPT_ONGOING" == true ] && [ -z "$OPT_ID" ]; then + echo "Ongoing notifications without an ID are not removable." + echo "Please set an id with --id \"string\"." + exit 1 +fi + set -- if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi if [ -n "$OPT_ALERT_ONCE" ]; then set -- "$@" --ez alert-once "$OPT_ALERT_ONCE"; fi From 5a477124e8e6a3b1a57943c20076df99e0bc7968 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Thu, 8 Aug 2019 11:05:27 +0200 Subject: [PATCH 02/68] termux-job-scheduler: fix doc --- scripts/termux-job-scheduler | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 3e6e82f..558a4aa 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -6,9 +6,9 @@ SCRIPTNAME=termux-job-scheduler show_usage () { echo "Usage: termux-job-scheduler [options]" echo "Schedule a script to run at specified intervals." - echo " --pending list pending jobs and exit (default false)" - echo " --cancel-all boolean cancel all pending jobs and exit (default false)" - echo " --cancel boolean cancel given job-id and exit (default false)" + echo " --pending list pending jobs and exit" + echo " --cancel-all cancel all pending jobs and exit" + echo " --cancel cancel given job-id and exit" echo "Options for scheduling:" echo " --script text path to the script to be called" echo " --job-id int job id (will overwrite any previous job with the same id)" From 93ae63b9057d8af97afcf37d66f5d22bffec7eba Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Thu, 8 Aug 2019 15:01:00 +0200 Subject: [PATCH 03/68] termux-notification: specify -c/stdin precedence -c/--content takes precedence over stdin to set the notification's content --- scripts/termux-notification | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index fff6708..654fb94 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -4,7 +4,7 @@ set -e -u -f SCRIPTNAME=termux-notification show_usage () { echo "Usage: termux-notification [options]" - echo "Display a system notification. Content text is read from stdin or specified using --content." + echo "Display a system notification. Content text is specified using -c/--content or read from stdin ." echo " --action action action to execute when pressing the notification" echo " --alert-once do not alert when the notification is edited" echo " --button1 text text to show on the first notification button" From bb832a5182ade6b1ea4f9dc59ecd632524cab5fc Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Thu, 8 Aug 2019 15:01:45 +0200 Subject: [PATCH 04/68] termux-notification: document one-letter options --- scripts/termux-notification | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index 654fb94..4c24c6f 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -13,9 +13,10 @@ show_usage () { echo " --button2-action action action to execute on the second notification button" echo " --button3 text text to show on the third notification button" echo " --button3-action action action to execute on the third notification button" - echo " --content content content to show in the notification. Will take precedence over stdin." + echo " -c/--content content content to show in the notification. Will take precedence over stdin." echo " --group group notification group (notifications with the same group are shown together)" - echo " --id id notification id (will overwrite any previous notification with the same id)" + echo " -h/--help show this help" + echo " -i/--id id notification id (will overwrite any previous notification with the same id)" echo " --image-path path absolute path to an image which will be shown in the notification" echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)" @@ -24,7 +25,7 @@ show_usage () { echo " --ongoing pin the notification" echo " --priority prio notification priority (high/low/max/min/default)" echo " --sound play a sound with the notification" - echo " --title title notification title to show" + echo " -t/--title title notification title to show" echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200" echo " --type type notification style to use (default/media)" echo "Media actions (available with --type \"media\"):" From 60af0488db1d0fa99785139e8a5785d04a9ec195 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Thu, 8 Aug 2019 15:28:48 +0200 Subject: [PATCH 05/68] termux-notification: add --help-actions fixes #37 --- scripts/termux-notification | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index 4c24c6f..ba13019 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -4,7 +4,8 @@ set -e -u -f SCRIPTNAME=termux-notification show_usage () { echo "Usage: termux-notification [options]" - echo "Display a system notification. Content text is specified using -c/--content or read from stdin ." + echo "Display a system notification. Content text is specified using -c/--content or read from stdin." + echo "Please read --help-actions for help with action arguments." echo " --action action action to execute when pressing the notification" echo " --alert-once do not alert when the notification is edited" echo " --button1 text text to show on the first notification button" @@ -16,6 +17,7 @@ show_usage () { echo " -c/--content content content to show in the notification. Will take precedence over stdin." echo " --group group notification group (notifications with the same group are shown together)" echo " -h/--help show this help" + echo " --help-actions show the help for actions" echo " -i/--id id notification id (will overwrite any previous notification with the same id)" echo " --image-path path absolute path to an image which will be shown in the notification" echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" @@ -36,6 +38,28 @@ show_usage () { exit 0 } +show_help_actions () { + echo "This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next." + echo + echo "All these commands take an action string as their argument, which is fed to \`dash -c\`." + echo "A few important things must be kept in mind when using actions:" + echo + echo "You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"." + echo "Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")." + echo + echo "Running more than one command in a single action is as easy as" + echo "--action \"command1; command2; command3\"" + echo "or" + echo "--action \"if [ -e file ]; then termux-toast yes; else termux-toast no; fi\"." + echo + echo "For anything more complex, you should put your script in a file, make it executable, and use that as the action:" + echo "--action ~/bin/script" + echo + echo "The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:" + echo " - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")" + echo " - or use something like --action \"bash -l -c 'command1; command2'\")." +} + OPT_ACTION="" OPT_ALERT_ONCE="" OPT_BUTTON1_ACTION="" @@ -70,7 +94,7 @@ TEMP=`busybox getopt \ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ -content:,group:,help,id:,image-path:\ +content:,group:,help,help-actions,id:,image-path:\ led-color:,led-on:,led-off:,\ media-previous:,media-next:,media-play:,media-pause:,\ on-delete:,ongoing,\ @@ -93,6 +117,7 @@ while true; do -c | --content) OPT_CONTENT="$2"; shift 2;; --group) OPT_GROUP="$2"; shift 2;; -h | --help) show_usage;; + --help-actions) show_help_actions; exit 0;; -i | --id) OPT_ID="$2"; shift 2;; --image-path) OPT_IMAGE_PATH="$2"; shift 2;; --led-color) OPT_LED_COLOR="$2"; shift 2;; From edc4faf2f5577270c3450bc9cb24739c6589281e Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sun, 11 Aug 2019 15:32:46 +0200 Subject: [PATCH 06/68] job-scheduler: document minimum for period-ms Since Android N, period-ms cannot be lower than 900.000 (15 minutes) --- scripts/termux-job-scheduler | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 558a4aa..6cdbf21 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -12,7 +12,8 @@ show_usage () { echo "Options for scheduling:" echo " --script text path to the script to be called" echo " --job-id int job id (will overwrite any previous job with the same id)" - echo " --period-ms int schedule job approximately every period-ms milliseconds (default 0 means once)" + echo " --period-ms int schedule job approximately every period-ms milliseconds (default 0 means once)." + echo " Note that since Android N, the minimum period is 900.000ms (15 minutes)." echo " --network text run only when this type of network available (default any): any|unmetered|cellular|not_roaming|none" echo " --battery-not-low boolean run only when battery is not low, default true (at least Android O)" echo " --storage-not-low boolean run only when storage is not low, default false (at least Android O)" From abe3241d14f63585a96ec5b80ba7651f3bd2023d Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sun, 11 Aug 2019 16:59:52 +0200 Subject: [PATCH 07/68] Setup issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 23 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 15 +++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..af3698a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Create a report to help us improve termux-api-package +title: '' +labels: '' +assignees: '' + +--- + + + +**Problem description** +A clear and concise description of what the problem with termux-api-package is. You may post screenshots or paste error messages in addition to description. + +**Steps to reproduce** +Please post all steps that are needed to reproduce the issue. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Additional information** +Post output of command `termux-info`. +If you are rooted or have access to adb then capture a logcat with `logcat -d "*:W"`, from a adb or root shell. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..d44d4db --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,15 @@ +--- +name: Feature request +about: Suggest a new feature in termux-api-package +title: '' +labels: '' +assignees: '' + +--- + +**Feature description** +Describe the feature and why you want it. + +**Background information** +Have you checked if the feature is accessible through the android API? +Do you know of other open-source apps that has a similar feature as the one you want? (Provide links) From 4c53f71dd545cc0cb54f8d6c35633457a359c623 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sun, 11 Aug 2019 22:40:48 +0200 Subject: [PATCH 08/68] termux-job-scheduler: document one-letter options --- scripts/termux-job-scheduler | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 6cdbf21..ff450a5 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -6,11 +6,11 @@ SCRIPTNAME=termux-job-scheduler show_usage () { echo "Usage: termux-job-scheduler [options]" echo "Schedule a script to run at specified intervals." - echo " --pending list pending jobs and exit" + echo " -p/--pending list pending jobs and exit" echo " --cancel-all cancel all pending jobs and exit" echo " --cancel cancel given job-id and exit" echo "Options for scheduling:" - echo " --script text path to the script to be called" + echo " -s/--script path path to the script to be called" echo " --job-id int job id (will overwrite any previous job with the same id)" echo " --period-ms int schedule job approximately every period-ms milliseconds (default 0 means once)." echo " Note that since Android N, the minimum period is 900.000ms (15 minutes)." From 48b9273dcabcf48a508c97a005ef901db0707d2a Mon Sep 17 00:00:00 2001 From: AgentConDier Date: Sat, 24 Aug 2019 16:58:44 +0200 Subject: [PATCH 09/68] Add missing comma to fix --led-color Fixes 'unrecognized option: led-color' errors (Unable to test; led and vibration have never worked for me [Android 9; EMUI 9.1.0]) --- scripts/termux-notification | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index ba13019..2b5c8a1 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -94,7 +94,7 @@ TEMP=`busybox getopt \ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ -content:,group:,help,help-actions,id:,image-path:\ +content:,group:,help,help-actions,id:,image-path:,\ led-color:,led-on:,led-off:,\ media-previous:,media-next:,media-play:,media-pause:,\ on-delete:,ongoing,\ From 82ec2e34f0fb60c083cbaafb8c120be7016f9b6c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 24 Sep 2019 17:54:48 +0200 Subject: [PATCH 10/68] Add title, description, subtitle and cancel text options in termux-fingerprint (#81) --- scripts/termux-fingerprint | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/termux-fingerprint b/scripts/termux-fingerprint index 48d421b..dee437f 100755 --- a/scripts/termux-fingerprint +++ b/scripts/termux-fingerprint @@ -3,24 +3,37 @@ set -e -u SCRIPTNAME=termux-fingerprint show_usage () { - echo "Usage: $SCRIPTNAME" + echo "Usage: $SCRIPTNAME [-t title] [-d description] [-s subtitle] [-c cancel]" echo "Use fingerprint sensor on device to check for authentication" echo "NOTE: Only available on Marshmallow and later" exit 0 } -while getopts :h option +ARG_T="" +OPT_T="" +ARG_D="" +OPT_D="" +ARG_S="" +OPT_S="" +ARG_C="" +OPT_C="" + +while getopts :ht:d:s:c: option do case "$option" in h) show_usage;; + t) ARG_T="--es title";OPT_T="$OPTARG";; + d) ARG_D="--es description";OPT_D="$OPTARG";; + s) ARG_S="--es subtitle";OPT_S="$OPTARG";; + c) ARG_C="--es cancel";OPT_C="$OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) -if [ $# -ne 0 ]; then - echo "$SCRIPTNAME takes no arguments" - exit 1 -fi +set -- +if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi +if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi +if [ -n "$ARG_S" ]; then set -- "$@" $ARG_S "$OPT_S"; fi +if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi -/data/data/com.termux/files/usr/libexec/termux-api Fingerprint +/data/data/com.termux/files/usr/libexec/termux-api Fingerprint "$@" From e19c3ca3fa695e223954f509cf339faeb24c72ad Mon Sep 17 00:00:00 2001 From: Boundary Effect Date: Sun, 6 Oct 2019 10:29:44 +0200 Subject: [PATCH 11/68] Add a USB API compatible with libusb --- Makefile | 1 + scripts/termux-usb | 57 ++++++++++++++++++++++++++++++++++++++++++++++ termux-api.c | 38 +++++++++++++++++++++++++++---- termux-callback | 4 ++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100755 scripts/termux-usb create mode 100755 termux-callback diff --git a/Makefile b/Makefile index ce7868e..09e96cf 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ termux-api: termux-api.c install: termux-api mkdir -p $(PREFIX)/bin/ $(PREFIX)/libexec/ install termux-api $(PREFIX)/libexec/ + install termux-callback $(PREFIX)/libexec/ install scripts/* $(PREFIX)/bin/ .PHONY: install diff --git a/scripts/termux-usb b/scripts/termux-usb new file mode 100755 index 0000000..5200b7a --- /dev/null +++ b/scripts/termux-usb @@ -0,0 +1,57 @@ +#!/data/data/com.termux/files/usr/bin/bash +set -e -u + +SCRIPTNAME=termux-usb +show_usage () { + echo "Usage: $SCRIPTNAME [-l | [-r] [-e command] device]" + echo "List or access USB devices. Devices cannot be accessed directly," + echo " only using $SCRIPTNAME." + echo " -l list available devices" + echo " -r show permission request dialog if necessary" + echo " -e command execute the specified command with a file descriptor" + echo " referring to the device as its argument" + exit 0 +} + +ACTION="permission" +PARAMS="" +MASK=0 +while getopts :hlre: option +do + case "$option" in + h) show_usage;; + l) ACTION="list"; ((MASK |= 1));; + r) PARAMS="$PARAMS --ez request true"; ((MASK |= 2));; + e) ACTION="open"; export TERMUX_CALLBACK="$OPTARG"; ((MASK |= 2));; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $(($OPTIND-1)) + +if [ $MASK -eq 3 ]; then echo "$SCRIPTNAME: -l cannot be combined with other options"; exit 1; fi + +if [ "$ACTION" == "list" ] +then + if [ $# -gt 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi +else + if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi + if [ $# -lt 1 ]; then echo "$SCRIPTNAME: missing -l or device path"; exit 1; fi + PARAMS="$PARAMS --es device $1" +fi + +CMD="/data/data/com.termux/files/usr/libexec/termux-api Usb -a $ACTION $PARAMS" + +if [ "$ACTION" == "permission" ] +then + if [ "$($CMD)" == "yes" ] + then + echo "Access granted." + exit 0 + else + echo "Access denied." + exit 1 + fi +else + $CMD +fi + diff --git a/termux-api.c b/termux-api.c index 115c450..de4125b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -66,6 +66,15 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_stri exit(1); } +_Noreturn void exec_callback(int fd) +{ + char *fds; + if(asprintf(&fds, "%d", fd) == -1) { perror("asprintf"); } + execl("/data/data/com.termux/files/usr/libexec/termux-callback", "termux-callback", fds, NULL); + perror("execl(\"/data/data/com.termux/files/usr/libexec/termux-callback\")"); + exit(1); +} + void generate_uuid(char* str) { sprintf(str, "%x%x-%x-%x-%x-%x%x%x", arc4random(), arc4random(), // Generates a 64-bit Hex number @@ -93,13 +102,32 @@ void* transmit_stdin_to_socket(void* arg) { } // Main thread function which reads from input socket and writes to stdout. -void transmit_socket_to_stdout(int input_socket_fd) { +int transmit_socket_to_stdout(int input_socket_fd) { ssize_t len; char buffer[1024]; - while ((len = read(input_socket_fd, &buffer, sizeof(buffer))) > 0) { + char cbuf[256]; + struct iovec io = { .iov_base = buffer, .iov_len = sizeof(buffer) }; + struct msghdr msg = { 0 }; + int fd = -1; // An optional file descriptor received through the socket + msg.msg_iov = &io; + msg.msg_iovlen = 1; + msg.msg_control = cbuf; + msg.msg_controllen = sizeof(cbuf); + while ((len = recvmsg(input_socket_fd, &msg, 0)) > 0) { + struct cmsghdr * cmsg = CMSG_FIRSTHDR(&msg); + if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) { + if (cmsg->cmsg_type == SCM_RIGHTS) { + fd = *((int *) CMSG_DATA(cmsg)); + } + } + // A file descriptor must be accompanied by a non-empty message, + // so we use "@" when we don't want any output. + if (fd != -1 && len == 1 && buffer[0] == '@') { len = 0; } write(STDOUT_FILENO, buffer, len); + msg.msg_controllen = sizeof(cbuf); } - if (len < 0) perror("read()"); + if (len < 0) perror("recvmsg()"); + return fd; } int main(int argc, char** argv) { @@ -149,7 +177,9 @@ int main(int argc, char** argv) { pthread_t transmit_thread; pthread_create(&transmit_thread, NULL, transmit_stdin_to_socket, &output_server_socket); - transmit_socket_to_stdout(input_client_socket); + int fd = transmit_socket_to_stdout(input_client_socket); + close(input_client_socket); + if (fd != -1) { exec_callback(fd); } return 0; } diff --git a/termux-callback b/termux-callback new file mode 100755 index 0000000..86c1a77 --- /dev/null +++ b/termux-callback @@ -0,0 +1,4 @@ +#!/data/data/com.termux/files/usr/bin/bash +set -e -u +$TERMUX_CALLBACK "$@" + From b21388c32c499e63354cea14ff52cb71127de482 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Fri, 25 Oct 2019 23:32:05 +0200 Subject: [PATCH 12/68] termux-wallpaper: rewrite - allow spaces in the option -f - fix shellcheck errors fixes termux/termux-api#298 --- scripts/termux-wallpaper | 71 +++++++++++++++------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/scripts/termux-wallpaper b/scripts/termux-wallpaper index 58fbdb4..4db6918 100755 --- a/scripts/termux-wallpaper +++ b/scripts/termux-wallpaper @@ -3,11 +3,10 @@ set -e SCRIPTNAME=termux-wallpaper - show_usage () { echo "Change wallpaper on your device" echo - echo "Usage: $SCRIPTNAME cmd [args]" + echo "Usage: $SCRIPTNAME [options]" echo "-h show this help" echo "-f set wallpaper from file" echo "-u set wallpaper from url resource" @@ -15,57 +14,39 @@ show_usage () { exit 1 } -call_api() { - /data/data/com.termux/files/usr/libexec/termux-api Wallpaper "$@" -} - -usage_error () { - echo "ERROR: $@" - show_usage -} - -LOCKSCREEN_FLAG=1 -RESOURCE_FLAG=2 - -FLAGS=0 - -set_single () { - if [ $((FLAGS & $1)) -ne 0 ]; then - usage_error "Option already set" - fi - FLAGS=$((FLAGS | $1)) - PARAMS="$PARAMS $2" -} - -set_resource () { - if [ $((FLAGS & $RESOURCE_FLAG)) -ne 0 ]; then - usage_error "More than one image resource specified!" - fi - set_single $RESOURCE_FLAG "$1" -} - -set_file () { - if [ ! -f $1 ]; then - usage_error "'$1' is not a file!" - fi - set_resource "--es file "$(realpath $1)"" -} +OPT_LS="" +OPT_FILE="" +OPT_URL="" while getopts :h,:l,f:,u: option do case "$option" in h) show_usage ;; - l) set_single $LOCKSCREEN_FLAG "--ez lockscreen true" ;; - f) set_file $OPTARG ;; - u) set_resource "--es url $OPTARG" ;; + l) OPT_LS="true" ;; + f) path="$(realpath "$OPTARG")" + if [[ ! -f "$path" ]]; then + echo "$SCRIPTNAME: $path is not a file!" + exit 1 + fi + OPT_FILE="$path" ;; + u) OPT_URL="$OPTARG" ;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1 ;; esac done -shift $((OPTIND - 1)) - -if [ $((FLAGS & RESOURCE_FLAG)) -eq 0 ]; then - usage_error "No file or url provided!" +if [[ -z "$OPT_FILE""$OPT_URL" ]]; then + echo "$SCRIPTNAME: you must specify either -f or -u" + exit 1 +elif [[ -n "$OPT_FILE" ]] && [[ -n "$OPT_URL" ]]; then + echo "$SCRIPTNAME: you must specify either -f or -u, but not both" + exit 1 fi -call_api $PARAMS +shift $((OPTIND - 1)) +if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi + +set -- +[ -n "$OPT_LS" ] && set -- "$@" --ez lockscreen "$OPT_LS" +[ -n "$OPT_FILE" ] && set -- "$@" --es file "$OPT_FILE" +[ -n "$OPT_URL" ] && set -- "$@" --es url "$OPT_URL" +/data/data/com.termux/files/usr/libexec/termux-api Wallpaper "$@" From ab186403432ecd2b8edfbedab3a78806e45694ca Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Fri, 25 Oct 2019 23:33:35 +0200 Subject: [PATCH 13/68] shellcheck most scripts one thing left to do is unifying and standardizing the way the argument string for the final call to termux-api is built. --- scripts/termux-audio-info | 2 +- scripts/termux-battery-status | 2 +- scripts/termux-brightness | 2 +- scripts/termux-call-log | 2 +- scripts/termux-camera-info | 2 +- scripts/termux-camera-photo | 4 ++-- scripts/termux-clipboard-get | 2 +- scripts/termux-clipboard-set | 2 +- scripts/termux-contact-list | 2 +- scripts/termux-dialog | 20 ++++++++++---------- scripts/termux-download | 4 ++-- scripts/termux-infrared-frequencies | 2 +- scripts/termux-infrared-transmit | 2 +- scripts/termux-location | 6 +++--- scripts/termux-media-scan | 4 ++-- scripts/termux-notification-list | 2 +- scripts/termux-notification-remove | 4 ++-- scripts/termux-sensor | 6 +++--- scripts/termux-share | 4 ++-- scripts/termux-sms-list | 2 +- scripts/termux-sms-send | 4 ++-- scripts/termux-speech-to-text | 2 +- scripts/termux-storage-get | 4 ++-- scripts/termux-telephony-call | 2 +- scripts/termux-telephony-cellinfo | 2 +- scripts/termux-telephony-deviceinfo | 2 +- scripts/termux-toast | 4 ++-- scripts/termux-torch | 4 ++-- scripts/termux-tts-engines | 2 +- scripts/termux-tts-speak | 4 ++-- scripts/termux-usb | 2 +- scripts/termux-vibrate | 2 +- scripts/termux-wifi-connectioninfo | 2 +- scripts/termux-wifi-enable | 2 +- scripts/termux-wifi-scaninfo | 2 +- 35 files changed, 58 insertions(+), 58 deletions(-) diff --git a/scripts/termux-audio-info b/scripts/termux-audio-info index 63444af..25525b8 100755 --- a/scripts/termux-audio-info +++ b/scripts/termux-audio-info @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-battery-status b/scripts/termux-battery-status index 9e0614c..e540723 100755 --- a/scripts/termux-battery-status +++ b/scripts/termux-battery-status @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-brightness b/scripts/termux-brightness index 7ec8647..a0a9baf 100755 --- a/scripts/termux-brightness +++ b/scripts/termux-brightness @@ -17,7 +17,7 @@ if ! [[ $1 =~ ^([0-9]+)|auto$ ]]; then show_usage fi -if [ $1 == auto ]; then +if [ "$1" == auto ]; then ARGS="--ez auto true" else ARGS="--ei brightness $1 --ez auto false" diff --git a/scripts/termux-call-log b/scripts/termux-call-log index 40e3162..14e48a2 100755 --- a/scripts/termux-call-log +++ b/scripts/termux-call-log @@ -24,7 +24,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-camera-info b/scripts/termux-camera-info index 437d556..f59f9f9 100755 --- a/scripts/termux-camera-info +++ b/scripts/termux-camera-info @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-camera-photo b/scripts/termux-camera-photo index 645853d..ec094af 100755 --- a/scripts/termux-camera-photo +++ b/scripts/termux-camera-photo @@ -19,12 +19,12 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi if [ $# != 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -touch $1 +touch "$1" PARAMS="$PARAMS --es file `realpath $1`" /data/data/com.termux/files/usr/libexec/termux-api CameraPhoto $PARAMS diff --git a/scripts/termux-clipboard-get b/scripts/termux-clipboard-get index 8a19581..edb9ff4 100755 --- a/scripts/termux-clipboard-get +++ b/scripts/termux-clipboard-get @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-clipboard-set b/scripts/termux-clipboard-set index 45aa84d..c043679 100755 --- a/scripts/termux-clipboard-set +++ b/scripts/termux-clipboard-set @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) CMD="/data/data/com.termux/files/usr/libexec/termux-api Clipboard -e api_version 2 --ez set true" if [ $# = 0 ]; then diff --git a/scripts/termux-contact-list b/scripts/termux-contact-list index 1dc8014..2779ec7 100755 --- a/scripts/termux-contact-list +++ b/scripts/termux-contact-list @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 92a4d15..1347cd6 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -142,7 +142,7 @@ list_widgets() { echo for w in "${widgets[@]}"; do - widget_usage $w + widget_usage "$w" echo done } @@ -183,14 +183,14 @@ parse_options() { options_error () { echo -e "ERROR: Invalid option(s) detected for '$1'\n" echo "Usage '$1'" - widget_usage $1 + widget_usage "$1" exit 1 } if [ $# -eq 0 ]; then WIDGET=$DEFAULT_WIDGET # First argument wasn't a widget -elif ! has_widget $1; then +elif ! has_widget "$1"; then # we didn't receive a widget as an argument, check to see if we # at least options (even if they're illegal) if ! [[ $1 =~ -[a-z] ]]; then @@ -211,35 +211,35 @@ case "$WIDGET" in # Text (default) if no widget specified "text") if [ $((FLAGS & (RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi if [ $((FLAGS & MULTI_LINE_FLAG)) -ne 0 ] && [ $((FLAGS & NUM_FLAG)) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; "confirm") if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; "counter") if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; "speech") if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; "date" | "time") if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; @@ -250,7 +250,7 @@ case "$WIDGET" in fi if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | NUM_FLAG))) -ne 0 ]; then - options_error $WIDGET + options_error "$WIDGET" fi ;; diff --git a/scripts/termux-download b/scripts/termux-download index afff2ac..ae5ad86 100755 --- a/scripts/termux-download +++ b/scripts/termux-download @@ -24,7 +24,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi @@ -34,6 +34,6 @@ URL_TO_DOWNLOAD="$1" set -- if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi -set -- "$@" $URL_TO_DOWNLOAD +set -- "$@" "$URL_TO_DOWNLOAD" /data/data/com.termux/files/usr/libexec/termux-api Download "$@" diff --git a/scripts/termux-infrared-frequencies b/scripts/termux-infrared-frequencies index ab6b6f4..63bd57f 100755 --- a/scripts/termux-infrared-frequencies +++ b/scripts/termux-infrared-frequencies @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-infrared-transmit b/scripts/termux-infrared-transmit index 8f6fcdb..a0544f3 100755 --- a/scripts/termux-infrared-transmit +++ b/scripts/termux-infrared-transmit @@ -18,7 +18,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ -z "$FREQUENCY" ]; then echo "$SCRIPTNAME: No frequency specified"; exit 1; fi diff --git a/scripts/termux-location b/scripts/termux-location index b02956e..024e21f 100755 --- a/scripts/termux-location +++ b/scripts/termux-location @@ -36,12 +36,12 @@ while getopts :hr:p: option do case "$option" in h) show_usage;; - r) validate_request $OPTARG; PARAMS="$PARAMS --es request $OPTARG";; - p) validate_provider $OPTARG; PARAMS="$PARAMS --es provider $OPTARG";; + r) validate_request "$OPTARG"; PARAMS="$PARAMS --es request $OPTARG";; + p) validate_provider "$OPTARG"; PARAMS="$PARAMS --es provider $OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-media-scan b/scripts/termux-media-scan index f2d8c2f..8ac54fb 100755 --- a/scripts/termux-media-scan +++ b/scripts/termux-media-scan @@ -18,7 +18,7 @@ get_paths() { if [[ "$ARG" =~ ^/ ]]; then echo "$ARG" else - echo "`pwd`/$ARG" + echo "$(pwd)/$ARG" fi fi done @@ -34,7 +34,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi diff --git a/scripts/termux-notification-list b/scripts/termux-notification-list index ef2de02..d332f15 100755 --- a/scripts/termux-notification-list +++ b/scripts/termux-notification-list @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-notification-remove b/scripts/termux-notification-remove index 8146ed2..9098f64 100755 --- a/scripts/termux-notification-remove +++ b/scripts/termux-notification-remove @@ -15,8 +15,8 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 1 ]; then echo "$SCRIPTNAME: no notification id specified"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id $1 +/data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id "$1" diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 2dc73b0..9f93d2b 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -77,7 +77,7 @@ set_flag () { } usage_error () { - echo "ERROR: $@" + echo "ERROR: $*" show_usage exit 1 } @@ -92,8 +92,8 @@ do 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) ;; - n) set_flag $LIMIT_FLAG; get_limit $OPTARG; PARAMS+=(--ei limit $OPTARG) ;; + d) set_flag $DELAY_FLAG; get_delay "$OPTARG"; PARAMS+=(--ei delay "$OPTARG") ;; + n) set_flag $LIMIT_FLAG; get_limit "$OPTARG"; PARAMS+=(--ei limit "$OPTARG") ;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done diff --git a/scripts/termux-share b/scripts/termux-share index 7c33ef2..e2b674e 100755 --- a/scripts/termux-share +++ b/scripts/termux-share @@ -30,14 +30,14 @@ while getopts :ha:c:dt: option do case "$option" in h) show_usage;; - a) validate_share $OPTARG; PARAMS="$PARAMS --es action $OPTARG";; + a) validate_share "$OPTARG"; PARAMS="$PARAMS --es action $OPTARG";; c) PARAMS="$PARAMS --es content-type $OPTARG";; d) PARAMS="$PARAMS --ez default-receiver true";; t) PARAMS="$PARAMS --es title $OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list index 1f4e1fc..e765905 100755 --- a/scripts/termux-sms-list +++ b/scripts/termux-sms-list @@ -33,7 +33,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-sms-send b/scripts/termux-sms-send index 33d9da4..6d1228d 100755 --- a/scripts/termux-sms-send +++ b/scripts/termux-sms-send @@ -18,7 +18,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ -z "$RECIPIENTS" ]; then echo "$SCRIPTNAME: no recipient number given"; exit 1; @@ -28,5 +28,5 @@ CMD="/data/data/com.termux/files/usr/libexec/termux-api SmsSend $RECIPIENTS" if [ $# = 0 ]; then $CMD else - echo $@ | $CMD + echo "$@" | $CMD fi diff --git a/scripts/termux-speech-to-text b/scripts/termux-speech-to-text index 5a200ba..7c01cdb 100755 --- a/scripts/termux-speech-to-text +++ b/scripts/termux-speech-to-text @@ -17,7 +17,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-storage-get b/scripts/termux-storage-get index 4ec9977..8690ae2 100755 --- a/scripts/termux-storage-get +++ b/scripts/termux-storage-get @@ -16,9 +16,9 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no output file specified"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api StorageGet --es file "`realpath "$1"`" +/data/data/com.termux/files/usr/libexec/termux-api StorageGet --es file "$(realpath "$1")" diff --git a/scripts/termux-telephony-call b/scripts/termux-telephony-call index 8b42277..0b8cfaa 100755 --- a/scripts/termux-telephony-call +++ b/scripts/termux-telephony-call @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# = 1 ]; then /data/data/com.termux/files/usr/libexec/termux-api TelephonyCall --es number "$1" diff --git a/scripts/termux-telephony-cellinfo b/scripts/termux-telephony-cellinfo index 1d394b8..f3e91c4 100755 --- a/scripts/termux-telephony-cellinfo +++ b/scripts/termux-telephony-cellinfo @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-telephony-deviceinfo b/scripts/termux-telephony-deviceinfo index 4f303ad..50b435e 100755 --- a/scripts/termux-telephony-deviceinfo +++ b/scripts/termux-telephony-deviceinfo @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-toast b/scripts/termux-toast index 95bd865..6ef1313 100755 --- a/scripts/termux-toast +++ b/scripts/termux-toast @@ -26,12 +26,12 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS" if [ $# = 0 ]; then $CMD else - echo $@ | $CMD + echo "$@" | $CMD fi diff --git a/scripts/termux-torch b/scripts/termux-torch index 73b93b7..d9ea675 100755 --- a/scripts/termux-torch +++ b/scripts/termux-torch @@ -16,9 +16,9 @@ fi PARAMS="" -if [ $1 = 'on' ]; then +if [ "$1" = on ]; then PARAMS="--ez enabled true" -elif [ $1 = 'off' ]; then +elif [ "$1" = off ]; then PARAMS="--ez enabled false" else echo "Illegal parameter: $1" diff --git a/scripts/termux-tts-engines b/scripts/termux-tts-engines index e62fbc1..e9d5dd5 100755 --- a/scripts/termux-tts-engines +++ b/scripts/termux-tts-engines @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-tts-speak b/scripts/termux-tts-speak index 4bfafa6..7d701ff 100755 --- a/scripts/termux-tts-speak +++ b/scripts/termux-tts-speak @@ -38,12 +38,12 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) CMD="/data/data/com.termux/files/usr/libexec/termux-api TextToSpeech $PARAMS" if [ $# = 0 ]; then $CMD else - echo $@ | $CMD + echo "$@" | $CMD fi diff --git a/scripts/termux-usb b/scripts/termux-usb index 5200b7a..98e2d3f 100755 --- a/scripts/termux-usb +++ b/scripts/termux-usb @@ -26,7 +26,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $MASK -eq 3 ]; then echo "$SCRIPTNAME: -l cannot be combined with other options"; exit 1; fi diff --git a/scripts/termux-vibrate b/scripts/termux-vibrate index 74896c9..f8a630d 100755 --- a/scripts/termux-vibrate +++ b/scripts/termux-vibrate @@ -21,7 +21,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-wifi-connectioninfo b/scripts/termux-wifi-connectioninfo index b1a6c58..371ace9 100755 --- a/scripts/termux-wifi-connectioninfo +++ b/scripts/termux-wifi-connectioninfo @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi diff --git a/scripts/termux-wifi-enable b/scripts/termux-wifi-enable index dd6cea3..38f5a28 100644 --- a/scripts/termux-wifi-enable +++ b/scripts/termux-wifi-enable @@ -18,4 +18,4 @@ case $1 in *) show_usage;; esac -/data/data/com.termux/files/usr/libexec/termux-api WifiEnable --ez enabled $1 \ No newline at end of file +/data/data/com.termux/files/usr/libexec/termux-api WifiEnable --ez enabled "$1" diff --git a/scripts/termux-wifi-scaninfo b/scripts/termux-wifi-scaninfo index 646579d..32812a7 100755 --- a/scripts/termux-wifi-scaninfo +++ b/scripts/termux-wifi-scaninfo @@ -15,7 +15,7 @@ do ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi From 666646ab1853e064f2cfb3bf2ef63bbdee75fc6e Mon Sep 17 00:00:00 2001 From: pim Date: Fri, 3 Jan 2020 22:18:25 +0100 Subject: [PATCH 14/68] termux-job-scheduler: Add --persisted option, see termux/termux-api#316 --- scripts/termux-job-scheduler | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index ff450a5..33594da 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -18,6 +18,7 @@ show_usage () { echo " --battery-not-low boolean run only when battery is not low, default true (at least Android O)" echo " --storage-not-low boolean run only when storage is not low, default false (at least Android O)" echo " --charging boolean run only when charging, default false" + echo " --persisted boolean should the job survive reboots, default false" echo " --trigger-content-uri text (at least Android N)" echo " --trigger-content-flag int default 1, (at least Android N)" exit 0 @@ -34,6 +35,7 @@ OPT_NETWORK="" OPT_BATTERY_NOT_LOW="" OPT_STORAGE_NOT_LOW="" OPT_CHARGING="" +OPT_PERSISTED="" OPT_TRIGGER_CONTENT_URI="" OPT_TRIGGER_CONTENT_FLAG="" @@ -45,7 +47,7 @@ job-id:,pending,\ cancel,cancel-all,\ period-ms:,network:,\ battery-not-low:,storage-not-low:,\ -charging:,help,\ +charging:,persisted:,help,\ trigger_content_flag:,trigger-content-uri: \ -s bash \ -- "$@"` @@ -63,6 +65,7 @@ while true; do --battery-not-low) OPT_BATTERY_NOT_LOW="$2"; shift 2;; --storage-not-low) OPT_STORAGE_NOT_LOW="$2"; shift 2;; --charging) OPT_CHARGING="$2"; shift 2;; + --persisted) OPT_PERSISTED="$2"; shift 2;; --trigger-content-flag) OPT_TRIGGER_CONTENT_FLAG="$2"; shift 2;; --trigger-content-uri) OPT_TRIGGER_CONTENT_URI="$2"; shift 2;; -h | --help) show_usage;; @@ -83,6 +86,7 @@ if [ -n "$OPT_NETWORK" ]; then set -- "$@" --es network "$OPT_NETWORK"; fi if [ -n "$OPT_BATTERY_NOT_LOW" ]; then set -- "$@" --ez battery_not_low "$OPT_BATTERY_NOT_LOW"; fi if [ -n "$OPT_STORAGE_NOT_LOW" ]; then set -- "$@" --ez storage_not_low "$OPT_STORAGE_NOT_LOW"; fi if [ -n "$OPT_CHARGING" ]; then set -- "$@" --ez charging "$OPT_CHARGING"; fi +if [ -n "$OPT_PERSISTED" ]; then set -- "$@" --ez persisted "$OPT_PERSISTED"; fi if [ -n "$OPT_TRIGGER_CONTENT_URI" ]; then set -- "$@" --es trigger_content_uri "$OPT_TRIGGER_CONTENT_URI"; fi if [ -n "$OPT_TRIGGER_CONTENT_FLAG" ]; then set -- "$@" --ez trigger_content_flag "$OPT_TRIGGER_CONTENT_FLAG"; fi From c72a9a958d48beefe0aa2f71241f05a0c9887e55 Mon Sep 17 00:00:00 2001 From: Ben Moran Date: Sun, 12 Jan 2020 11:34:48 +0000 Subject: [PATCH 15/68] termux-notification --help-actions update for direct reply (termux-api #320) --- scripts/termux-notification | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/termux-notification b/scripts/termux-notification index 2b5c8a1..9d5375a 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -58,6 +58,14 @@ show_help_actions () { echo "The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:" echo " - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")" echo " - or use something like --action \"bash -l -c 'command1; command2'\")." + echo + echo "On Android N or above, you can use the special variable \$REPLY in your actions to use Android's Direct Reply feature." + echo "This prompts the user to enter some text directly in the notification, which is then substituted into your action." + echo " - termux-notification --button1 \"Answer\" --button1-action \"termux-toast \\\$REPLY\"" + echo "will call the action:" + echo " - termux-toast \"Some text entered by the user\"" + echo "Be careful to escape shell commands correctly for single or double quotes, e.g." + echo " --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\"" } OPT_ACTION="" From a5d5b276c9d84c3c2abfaebe057d839bce382811 Mon Sep 17 00:00:00 2001 From: Kittinan <144775+kittinan@users.noreply.github.com> Date: Wed, 18 Mar 2020 23:18:40 +0700 Subject: [PATCH 16/68] Fix 900.000 ms to 900,000 ms --- scripts/termux-job-scheduler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 33594da..87e884d 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -13,7 +13,7 @@ show_usage () { echo " -s/--script path path to the script to be called" echo " --job-id int job id (will overwrite any previous job with the same id)" echo " --period-ms int schedule job approximately every period-ms milliseconds (default 0 means once)." - echo " Note that since Android N, the minimum period is 900.000ms (15 minutes)." + echo " Note that since Android N, the minimum period is 900,000ms (15 minutes)." echo " --network text run only when this type of network available (default any): any|unmetered|cellular|not_roaming|none" echo " --battery-not-low boolean run only when battery is not low, default true (at least Android O)" echo " --storage-not-low boolean run only when storage is not low, default false (at least Android O)" From ff691f19679cfd0ecf109cb00daf08547467a4fe Mon Sep 17 00:00:00 2001 From: Yuri Mataev Date: Thu, 23 Apr 2020 04:46:07 -0400 Subject: [PATCH 17/68] Add --icon and --icon-list commands to termux-notification --- scripts/termux-notification | 337 +++++++++++++++++++++++++++++++++++- 1 file changed, 336 insertions(+), 1 deletion(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index 9d5375a..c8ca592 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -19,6 +19,9 @@ show_usage () { echo " -h/--help show this help" echo " --help-actions show the help for actions" echo " -i/--id id notification id (will overwrite any previous notification with the same id)" + echo " --icon icon-name set the icon that shows up in the status bar. View available icons using" + echo " termux-notification --icon-list; (default icon: event_note)" + echo " --icon-list show list of status bar icons available to termux-notification" echo " --image-path path absolute path to an image which will be shown in the notification" echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)" @@ -68,6 +71,333 @@ show_help_actions () { echo " --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\"" } +icon_list () { + echo "Here is the list of icons available to termux-notification. These are based on the Google Material Design Icons." + echo "We are unable to show a preview of the icons inside the terminal, but they can be previewed on the web at:" + echo "https://material.io/resources/icons/" + echo + echo "3d_rotation filter_center_focus photo_camera" + echo "ac_unit filter_drama photo_filter" + echo "access_alarm filter_frames photo_library" + echo "access_alarms filter_hdr photo_size_select_actual" + echo "access_time filter_list photo_size_select_large" + echo "accessibility filter_none photo_size_select_small" + echo "accessible filter_tilt_shift picture_as_pdf" + echo "account_balance filter_vintage picture_in_picture_alt" + echo "account_balance_wallet find_in_page picture_in_picture" + echo "account_box find_replace pie_chart" + echo "account_circle fingerprint pie_chart_outlined" + echo "adb first_page pin_drop" + echo "add_a_photo fitness_center place" + echo "add_alarm flag play_arrow" + echo "add_alert flare play_circle_filled" + echo "add flash_auto play_circle_outline" + echo "add_box flash_off play_for_work" + echo "add_circle flash_on playlist_add" + echo "add_circle_outline flight playlist_add_check" + echo "add_location flight_land playlist_play" + echo "add_shopping_cart flight_takeoff plus_one" + echo "add_to_photos flip poll" + echo "add_to_queue flip_to_back polymer" + echo "adjust flip_to_front pool" + echo "airline_seat_flat_angled folder portable_wifi_off" + echo "airline_seat_flat folder_open portrait" + echo "airline_seat_individual_suite folder_shared power" + echo "airline_seat_legroom_extra folder_special power_input" + echo "airline_seat_legroom_normal font_download power_settings_new" + echo "airline_seat_legroom_reduced format_align_center pregnant_woman" + echo "airline_seat_recline_extra format_align_justify present_to_all" + echo "airline_seat_recline_normal format_align_left print" + echo "airplanemode_active format_align_right priority_high" + echo "airplanemode_inactive format_bold public" + echo "airplay format_clear publish" + echo "airport_shuttle format_color_fill query_builder" + echo "alarm_add format_color_reset question_answer" + echo "alarm format_color_text queue" + echo "alarm_off format_indent_decrease queue_music" + echo "alarm_on format_indent_increase queue_play_next" + echo "album format_italic radio" + echo "all_inclusive format_line_spacing radio_button_checked" + echo "all_out format_list_bulleted radio_button_unchecked" + echo "android format_list_numbered rate_review" + echo "announcement format_paint receipt" + echo "apps format_quote recent_actors" + echo "archive format_shapes record_voice_over" + echo "arrow_back format_size redeem" + echo "arrow_downward format_strikethrough redo" + echo "arrow_drop_down format_textdirection_l_to_r refresh" + echo "arrow_drop_down_circle format_textdirection_r_to_l remove" + echo "arrow_drop_up format_underlined remove_circle" + echo "arrow_forward forum remove_circle_outline" + echo "arrow_upward forward_10 remove_from_queue" + echo "art_track forward_30 remove_red_eye" + echo "aspect_ratio forward_5 remove_shopping_cart" + echo "assessment forward reorder" + echo "assignment free_breakfast repeat" + echo "assignment_ind fullscreen repeat_one" + echo "assignment_late fullscreen_exit replay_10" + echo "assignment_return functions replay_30" + echo "assignment_returned g_translate replay_5" + echo "assignment_turned_in gamepad replay" + echo "assistant games reply_all" + echo "assistant_photo gavel reply" + echo "attach_file gesture report" + echo "attach_money get_app report_problem" + echo "attachment gif restaurant" + echo "audiotrack golf_course restaurant_menu" + echo "autorenew gps_fixed restore" + echo "av_timer gps_not_fixed restore_page" + echo "backspace gps_off ring_volume" + echo "backup grade room" + echo "battery_20 gradient room_service" + echo "battery_30 grain rotate_90_degrees_ccw" + echo "battery_50 graphic_eq rotate_left" + echo "battery_60 grid_off rotate_right" + echo "battery_80 grid_on rounded_corner" + echo "battery_90 group_add router" + echo "battery_alert group rowing" + echo "battery_charging_20 group_work rss_feed" + echo "battery_charging_30 hd rv_hookup" + echo "battery_charging_50 hdr_off satellite" + echo "battery_charging_60 hdr_on save" + echo "battery_charging_80 hdr_strong scanner" + echo "battery_charging_90 hdr_weak schedule" + echo "battery_charging_full headset school" + echo "battery_full headset_mic screen_lock_landscape" + echo "battery_std healing screen_lock_portrait" + echo "battery_unknown hearing screen_lock_rotation" + echo "beach_access help screen_rotation" + echo "beenhere help_outline screen_share" + echo "block high_quality sd_card" + echo "bluetooth_audio highlight sd_storage" + echo "bluetooth highlight_off search" + echo "bluetooth_connected history security" + echo "bluetooth_disabled home select_all" + echo "bluetooth_searching hot_tub send" + echo "blur_circular hotel sentiment_dissatisfied" + echo "blur_linear hourglass_empty sentiment_neutral" + echo "blur_off hourglass_full sentiment_satisfied" + echo "blur_on http sentiment_very_dissatisfied" + echo "book https sentiment_very_satisfied" + echo "bookmark image_aspect_ratio settings_applications" + echo "bookmark_border image settings_backup_restore" + echo "border_all import_contacts settings" + echo "border_bottom import_export settings_bluetooth" + echo "border_clear important_devices settings_brightness" + echo "border_color inbox settings_cell" + echo "border_horizontal indeterminate_check_box settings_ethernet" + echo "border_inner info settings_input_antenna" + echo "border_left info_outline settings_input_component" + echo "border_outer input settings_input_composite" + echo "border_right insert_chart settings_input_hdmi" + echo "border_style insert_comment settings_input_svideo" + echo "border_top insert_drive_file settings_overscan" + echo "border_vertical insert_emoticon settings_phone" + echo "branding_watermark insert_invitation settings_power" + echo "brightness_1 insert_link settings_remote" + echo "brightness_2 insert_photo settings_system_daydream" + echo "brightness_3 invert_colors settings_voice" + echo "brightness_4 invert_colors_off share" + echo "brightness_5 iso shop" + echo "brightness_6 keyboard_arrow_down shop_two" + echo "brightness_7 keyboard_arrow_left shopping_basket" + echo "brightness_auto keyboard_arrow_right shopping_cart" + echo "brightness_high keyboard_arrow_up short_text" + echo "brightness_low keyboard_backspace show_chart" + echo "brightness_medium keyboard shuffle" + echo "broken_image keyboard_capslock signal_cellular_0_bar" + echo "brush keyboard_hide signal_cellular_1_bar" + echo "bubble_chart keyboard_return signal_cellular_2_bar" + echo "bug_report keyboard_tab signal_cellular_3_bar" + echo "build keyboard_voice signal_cellular_4_bar" + echo "burst_mode kitchen signal_cellular_connected_no_internet_0_bar" + echo "business label signal_cellular_connected_no_internet_1_bar" + echo "business_center label_outline signal_cellular_connected_no_internet_2_bar" + echo "cached landscape signal_cellular_connected_no_internet_3_bar" + echo "cake language signal_cellular_connected_no_internet_4_bar" + echo "call laptop signal_cellular_no_sim" + echo "call_end laptop_chromebook signal_cellular_null" + echo "call_made laptop_mac signal_cellular_off" + echo "call_merge laptop_windows signal_wifi_0_bar" + echo "call_missed last_page signal_wifi_1_bar" + echo "call_missed_outgoing launch signal_wifi_1_bar_lock" + echo "call_received layers signal_wifi_2_bar" + echo "call_split layers_clear signal_wifi_2_bar_lock" + echo "call_to_action leak_add signal_wifi_3_bar" + echo "camera_alt leak_remove signal_wifi_3_bar_lock" + echo "camera lens signal_wifi_4_bar" + echo "camera_enhance library_add signal_wifi_4_bar_lock" + echo "camera_front library_books signal_wifi_off" + echo "camera_rear library_music sim_card_alert" + echo "camera_roll lightbulb_outline sim_card" + echo "cancel line_style skip_next" + echo "card_giftcard line_weight skip_previous" + echo "card_membership linear_scale slideshow" + echo "card_travel link slow_motion_video" + echo "casino linked_camera smartphone" + echo "cast list smoke_free" + echo "cast_connected live_help smoking_rooms" + echo "center_focus_strong live_tv sms" + echo "center_focus_weak local_activity sms_failed" + echo "change_history local_airport snooze" + echo "chat local_atm sort" + echo "chat_bubble local_bar sort_by_alpha" + echo "chat_bubble_outline local_cafe spa" + echo "check local_car_wash space_bar" + echo "check_box local_convenience_store speaker" + echo "check_box_outline_blank local_dining speaker_group" + echo "check_circle local_drink speaker_notes" + echo "chevron_left local_florist speaker_notes_off" + echo "chevron_right local_gas_station speaker_phone" + echo "child_care local_grocery_store spellcheck" + echo "child_friendly local_hospital star" + echo "chrome_reader_mode local_hotel star_border" + echo "class local_laundry_service star_half" + echo "clear_all local_library stars" + echo "clear local_mall stay_current_landscape" + echo "close local_movies stay_current_portrait" + echo "closed_caption local_offer stay_primary_landscape" + echo "cloud local_parking stay_primary_portrait" + echo "cloud_circle local_pharmacy stop" + echo "cloud_done local_phone stop_screen_share" + echo "cloud_download local_pizza storage" + echo "cloud_off local_play store" + echo "cloud_queue local_post_office store_mall_directory" + echo "cloud_upload local_printshop straighten" + echo "code local_see streetview" + echo "collections local_shipping strikethrough_s" + echo "collections_bookmark local_taxi style" + echo "color_lens location_city subdirectory_arrow_left" + echo "colorize location_disabled subdirectory_arrow_right" + echo "comment location_off subject" + echo "compare_arrows location_on subscriptions" + echo "compare location_searching subtitles" + echo "computer lock subway" + echo "confirmation_number lock_open supervisor_account" + echo "contact_mail lock_outline surround_sound" + echo "contact_phone looks_3 swap_calls" + echo "contacts looks_4 swap_horiz" + echo "content_copy looks_5 swap_vert" + echo "content_cut looks_6 swap_vertical_circle" + echo "content_paste looks switch_camera" + echo "control_point looks_one switch_video" + echo "control_point_duplicate looks_two sync" + echo "copyright loop sync_disabled" + echo "create loupe sync_problem" + echo "create_new_folder low_priority system_update_alt" + echo "credit_card loyalty system_update" + echo "crop_16_9 mail tab" + echo "crop_3_2 mail_outline tab_unselected" + echo "crop_5_4 map tablet_android" + echo "crop_7_5 markunread tablet" + echo "crop markunread_mailbox tablet_mac" + echo "crop_din memory tag_faces" + echo "crop_free menu tap_and_play" + echo "crop_landscape merge_type terrain" + echo "crop_original message text_fields" + echo "crop_portrait mic text_format" + echo "crop_rotate mic_none textsms" + echo "crop_square mic_off texture" + echo "dashboard mms theaters" + echo "data_usage mode_comment thumb_down" + echo "date_range mode_edit thumb_up" + echo "dehaze monetization_on thumbs_up_down" + echo "delete money_off time_to_leave" + echo "delete_forever monochrome_photos timelapse" + echo "delete_sweep mood_bad timeline" + echo "description mood timer_10" + echo "desktop_mac more timer_3" + echo "desktop_windows more_horiz timer" + echo "details more_vert timer_off" + echo "developer_board motorcycle title" + echo "developer_mode mouse toc" + echo "device_hub move_to_inbox today" + echo "devices movie toll" + echo "devices_other movie_creation tonality" + echo "dialer_sip movie_filter touch_app" + echo "dialpad multiline_chart toys" + echo "directions_bike music_note track_changes" + echo "directions music_video traffic" + echo "directions_boat my_location train" + echo "directions_bus nature tram" + echo "directions_car nature_people transfer_within_a_station" + echo "directions_railway navigate_before transform" + echo "directions_run navigate_next translate" + echo "directions_subway navigation trending_down" + echo "directions_transit near_me trending_flat" + echo "directions_walk network_cell trending_up" + echo "disc_full network_check tune" + echo "dns network_locked turned_in" + echo "do_not_disturb_alt network_wifi turned_in_not" + echo "do_not_disturb new_releases tv" + echo "do_not_disturb_off next_week unarchive" + echo "do_not_disturb_on nfc undo" + echo "dock no_encryption unfold_less" + echo "domain no_sim unfold_more" + echo "done_all not_interested update" + echo "done note_add usb" + echo "donut_large note verified_user" + echo "donut_small notifications_active vertical_align_bottom" + echo "drafts notifications vertical_align_center" + echo "drag_handle notifications_none vertical_align_top" + echo "drive_eta notifications_off vibration" + echo "dvr notifications_paused video_call" + echo "edit offline_pin video_label" + echo "edit_location ondemand_video video_library" + echo "eject opacity videocam" + echo "email open_in_browser videocam_off" + echo "enhanced_encryption open_in_new videogame_asset" + echo "equalizer open_with view_agenda" + echo "error pages view_array" + echo "error_outline pageview view_carousel" + echo "euro_symbol palette view_column" + echo "ev_station pan_tool view_comfy" + echo "event_available panorama view_compact" + echo "event panorama_fish_eye view_day" + echo "event_busy panorama_horizontal view_headline" + echo "event_note panorama_vertical view_list" + echo "event_seat panorama_wide_angle view_module" + echo "exit_to_app party_mode view_quilt" + echo "expand_less pause view_stream" + echo "expand_more pause_circle_filled view_week" + echo "explicit pause_circle_outline vignette" + echo "explore payment visibility" + echo "exposure people visibility_off" + echo "exposure_neg_1 people_outline voice_chat" + echo "exposure_neg_2 perm_camera_mic voicemail" + echo "exposure_plus_1 perm_contact_calendar volume_down" + echo "exposure_plus_2 perm_data_setting volume_mute" + echo "exposure_zero perm_device_information volume_off" + echo "extension perm_identity volume_up" + echo "face perm_media vpn_key" + echo "fast_forward perm_phone_msg vpn_lock" + echo "fast_rewind perm_scan_wifi wallpaper" + echo "favorite person_add warning" + echo "favorite_border person watch" + echo "featured_play_list person_outline watch_later" + echo "featured_video person_pin wb_auto" + echo "feedback person_pin_circle wb_cloudy" + echo "fiber_dvr personal_video wb_incandescent" + echo "fiber_manual_record pets wb_iridescent" + echo "fiber_new phone_android wb_sunny" + echo "fiber_pin phone wc" + echo "fiber_smart_record phone_bluetooth_speaker web_asset" + echo "file_download phone_forwarded web" + echo "file_upload phone_in_talk weekend" + echo "filter_1 phone_iphone whatshot" + echo "filter_2 phone_locked widgets" + echo "filter_3 phone_missed wifi" + echo "filter_4 phone_paused wifi_lock" + echo "filter_5 phonelink wifi_tethering" + echo "filter_6 phonelink_erase work" + echo "filter_7 phonelink_lock wrap_text" + echo "filter_8 phonelink_off youtube_searched_for" + echo "filter_9 phonelink_ring zoom_in" + echo "filter_9_plus phonelink_setup zoom_out" + echo "filter_b_and_w photo_album zoom_out_map" + echo "filter photo" +} + OPT_ACTION="" OPT_ALERT_ONCE="" OPT_BUTTON1_ACTION="" @@ -79,6 +409,7 @@ OPT_BUTTON3_TEXT="" OPT_CONTENT="" OPT_GROUP="" OPT_ID="" +OPT_ICON="" OPT_IMAGE_PATH="" OPT_LED_COLOR="" OPT_LED_OFF="" @@ -102,7 +433,8 @@ TEMP=`busybox getopt \ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ -content:,group:,help,help-actions,id:,image-path:,\ +content:,group:,help,help-actions,\ +id:,icon:,icon-list,image-path:,\ led-color:,led-on:,led-off:,\ media-previous:,media-next:,media-play:,media-pause:,\ on-delete:,ongoing,\ @@ -127,6 +459,8 @@ while true; do -h | --help) show_usage;; --help-actions) show_help_actions; exit 0;; -i | --id) OPT_ID="$2"; shift 2;; + --icon) OPT_ICON="$2"; shift 2;; + --icon-list) icon_list; exit 0;; --image-path) OPT_IMAGE_PATH="$2"; shift 2;; --led-color) OPT_LED_COLOR="$2"; shift 2;; --led-off) OPT_LED_OFF="$2"; shift 2;; @@ -165,6 +499,7 @@ if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUT if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi if [ -n "$OPT_GROUP" ]; then set -- "$@" --es group "$OPT_GROUP"; fi if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi +if [ -n "$OPT_ICON" ]; then set -- "$@" --es icon "$OPT_ICON"; fi if [ -n "$OPT_IMAGE_PATH" ]; then set -- "$@" --es image-path "$OPT_IMAGE_PATH"; fi if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi From b34d4c85d067c3ae172a51e64b53c8f3fa3b84b2 Mon Sep 17 00:00:00 2001 From: Alessandro Caputo Date: Sat, 25 Apr 2020 15:45:29 +0200 Subject: [PATCH 18/68] suggestion: remove long icon list --- scripts/termux-notification | 335 +----------------------------------- 1 file changed, 3 insertions(+), 332 deletions(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index c8ca592..bf7ee89 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -19,9 +19,8 @@ show_usage () { echo " -h/--help show this help" echo " --help-actions show the help for actions" echo " -i/--id id notification id (will overwrite any previous notification with the same id)" - echo " --icon icon-name set the icon that shows up in the status bar. View available icons using" - echo " termux-notification --icon-list; (default icon: event_note)" - echo " --icon-list show list of status bar icons available to termux-notification" + echo " --icon icon-name set the icon that shows up in the status bar. View available icons at" + echo " https://material.io/resources/icons/ (default icon: event_note)" echo " --image-path path absolute path to an image which will be shown in the notification" echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)" @@ -71,333 +70,6 @@ show_help_actions () { echo " --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\"" } -icon_list () { - echo "Here is the list of icons available to termux-notification. These are based on the Google Material Design Icons." - echo "We are unable to show a preview of the icons inside the terminal, but they can be previewed on the web at:" - echo "https://material.io/resources/icons/" - echo - echo "3d_rotation filter_center_focus photo_camera" - echo "ac_unit filter_drama photo_filter" - echo "access_alarm filter_frames photo_library" - echo "access_alarms filter_hdr photo_size_select_actual" - echo "access_time filter_list photo_size_select_large" - echo "accessibility filter_none photo_size_select_small" - echo "accessible filter_tilt_shift picture_as_pdf" - echo "account_balance filter_vintage picture_in_picture_alt" - echo "account_balance_wallet find_in_page picture_in_picture" - echo "account_box find_replace pie_chart" - echo "account_circle fingerprint pie_chart_outlined" - echo "adb first_page pin_drop" - echo "add_a_photo fitness_center place" - echo "add_alarm flag play_arrow" - echo "add_alert flare play_circle_filled" - echo "add flash_auto play_circle_outline" - echo "add_box flash_off play_for_work" - echo "add_circle flash_on playlist_add" - echo "add_circle_outline flight playlist_add_check" - echo "add_location flight_land playlist_play" - echo "add_shopping_cart flight_takeoff plus_one" - echo "add_to_photos flip poll" - echo "add_to_queue flip_to_back polymer" - echo "adjust flip_to_front pool" - echo "airline_seat_flat_angled folder portable_wifi_off" - echo "airline_seat_flat folder_open portrait" - echo "airline_seat_individual_suite folder_shared power" - echo "airline_seat_legroom_extra folder_special power_input" - echo "airline_seat_legroom_normal font_download power_settings_new" - echo "airline_seat_legroom_reduced format_align_center pregnant_woman" - echo "airline_seat_recline_extra format_align_justify present_to_all" - echo "airline_seat_recline_normal format_align_left print" - echo "airplanemode_active format_align_right priority_high" - echo "airplanemode_inactive format_bold public" - echo "airplay format_clear publish" - echo "airport_shuttle format_color_fill query_builder" - echo "alarm_add format_color_reset question_answer" - echo "alarm format_color_text queue" - echo "alarm_off format_indent_decrease queue_music" - echo "alarm_on format_indent_increase queue_play_next" - echo "album format_italic radio" - echo "all_inclusive format_line_spacing radio_button_checked" - echo "all_out format_list_bulleted radio_button_unchecked" - echo "android format_list_numbered rate_review" - echo "announcement format_paint receipt" - echo "apps format_quote recent_actors" - echo "archive format_shapes record_voice_over" - echo "arrow_back format_size redeem" - echo "arrow_downward format_strikethrough redo" - echo "arrow_drop_down format_textdirection_l_to_r refresh" - echo "arrow_drop_down_circle format_textdirection_r_to_l remove" - echo "arrow_drop_up format_underlined remove_circle" - echo "arrow_forward forum remove_circle_outline" - echo "arrow_upward forward_10 remove_from_queue" - echo "art_track forward_30 remove_red_eye" - echo "aspect_ratio forward_5 remove_shopping_cart" - echo "assessment forward reorder" - echo "assignment free_breakfast repeat" - echo "assignment_ind fullscreen repeat_one" - echo "assignment_late fullscreen_exit replay_10" - echo "assignment_return functions replay_30" - echo "assignment_returned g_translate replay_5" - echo "assignment_turned_in gamepad replay" - echo "assistant games reply_all" - echo "assistant_photo gavel reply" - echo "attach_file gesture report" - echo "attach_money get_app report_problem" - echo "attachment gif restaurant" - echo "audiotrack golf_course restaurant_menu" - echo "autorenew gps_fixed restore" - echo "av_timer gps_not_fixed restore_page" - echo "backspace gps_off ring_volume" - echo "backup grade room" - echo "battery_20 gradient room_service" - echo "battery_30 grain rotate_90_degrees_ccw" - echo "battery_50 graphic_eq rotate_left" - echo "battery_60 grid_off rotate_right" - echo "battery_80 grid_on rounded_corner" - echo "battery_90 group_add router" - echo "battery_alert group rowing" - echo "battery_charging_20 group_work rss_feed" - echo "battery_charging_30 hd rv_hookup" - echo "battery_charging_50 hdr_off satellite" - echo "battery_charging_60 hdr_on save" - echo "battery_charging_80 hdr_strong scanner" - echo "battery_charging_90 hdr_weak schedule" - echo "battery_charging_full headset school" - echo "battery_full headset_mic screen_lock_landscape" - echo "battery_std healing screen_lock_portrait" - echo "battery_unknown hearing screen_lock_rotation" - echo "beach_access help screen_rotation" - echo "beenhere help_outline screen_share" - echo "block high_quality sd_card" - echo "bluetooth_audio highlight sd_storage" - echo "bluetooth highlight_off search" - echo "bluetooth_connected history security" - echo "bluetooth_disabled home select_all" - echo "bluetooth_searching hot_tub send" - echo "blur_circular hotel sentiment_dissatisfied" - echo "blur_linear hourglass_empty sentiment_neutral" - echo "blur_off hourglass_full sentiment_satisfied" - echo "blur_on http sentiment_very_dissatisfied" - echo "book https sentiment_very_satisfied" - echo "bookmark image_aspect_ratio settings_applications" - echo "bookmark_border image settings_backup_restore" - echo "border_all import_contacts settings" - echo "border_bottom import_export settings_bluetooth" - echo "border_clear important_devices settings_brightness" - echo "border_color inbox settings_cell" - echo "border_horizontal indeterminate_check_box settings_ethernet" - echo "border_inner info settings_input_antenna" - echo "border_left info_outline settings_input_component" - echo "border_outer input settings_input_composite" - echo "border_right insert_chart settings_input_hdmi" - echo "border_style insert_comment settings_input_svideo" - echo "border_top insert_drive_file settings_overscan" - echo "border_vertical insert_emoticon settings_phone" - echo "branding_watermark insert_invitation settings_power" - echo "brightness_1 insert_link settings_remote" - echo "brightness_2 insert_photo settings_system_daydream" - echo "brightness_3 invert_colors settings_voice" - echo "brightness_4 invert_colors_off share" - echo "brightness_5 iso shop" - echo "brightness_6 keyboard_arrow_down shop_two" - echo "brightness_7 keyboard_arrow_left shopping_basket" - echo "brightness_auto keyboard_arrow_right shopping_cart" - echo "brightness_high keyboard_arrow_up short_text" - echo "brightness_low keyboard_backspace show_chart" - echo "brightness_medium keyboard shuffle" - echo "broken_image keyboard_capslock signal_cellular_0_bar" - echo "brush keyboard_hide signal_cellular_1_bar" - echo "bubble_chart keyboard_return signal_cellular_2_bar" - echo "bug_report keyboard_tab signal_cellular_3_bar" - echo "build keyboard_voice signal_cellular_4_bar" - echo "burst_mode kitchen signal_cellular_connected_no_internet_0_bar" - echo "business label signal_cellular_connected_no_internet_1_bar" - echo "business_center label_outline signal_cellular_connected_no_internet_2_bar" - echo "cached landscape signal_cellular_connected_no_internet_3_bar" - echo "cake language signal_cellular_connected_no_internet_4_bar" - echo "call laptop signal_cellular_no_sim" - echo "call_end laptop_chromebook signal_cellular_null" - echo "call_made laptop_mac signal_cellular_off" - echo "call_merge laptop_windows signal_wifi_0_bar" - echo "call_missed last_page signal_wifi_1_bar" - echo "call_missed_outgoing launch signal_wifi_1_bar_lock" - echo "call_received layers signal_wifi_2_bar" - echo "call_split layers_clear signal_wifi_2_bar_lock" - echo "call_to_action leak_add signal_wifi_3_bar" - echo "camera_alt leak_remove signal_wifi_3_bar_lock" - echo "camera lens signal_wifi_4_bar" - echo "camera_enhance library_add signal_wifi_4_bar_lock" - echo "camera_front library_books signal_wifi_off" - echo "camera_rear library_music sim_card_alert" - echo "camera_roll lightbulb_outline sim_card" - echo "cancel line_style skip_next" - echo "card_giftcard line_weight skip_previous" - echo "card_membership linear_scale slideshow" - echo "card_travel link slow_motion_video" - echo "casino linked_camera smartphone" - echo "cast list smoke_free" - echo "cast_connected live_help smoking_rooms" - echo "center_focus_strong live_tv sms" - echo "center_focus_weak local_activity sms_failed" - echo "change_history local_airport snooze" - echo "chat local_atm sort" - echo "chat_bubble local_bar sort_by_alpha" - echo "chat_bubble_outline local_cafe spa" - echo "check local_car_wash space_bar" - echo "check_box local_convenience_store speaker" - echo "check_box_outline_blank local_dining speaker_group" - echo "check_circle local_drink speaker_notes" - echo "chevron_left local_florist speaker_notes_off" - echo "chevron_right local_gas_station speaker_phone" - echo "child_care local_grocery_store spellcheck" - echo "child_friendly local_hospital star" - echo "chrome_reader_mode local_hotel star_border" - echo "class local_laundry_service star_half" - echo "clear_all local_library stars" - echo "clear local_mall stay_current_landscape" - echo "close local_movies stay_current_portrait" - echo "closed_caption local_offer stay_primary_landscape" - echo "cloud local_parking stay_primary_portrait" - echo "cloud_circle local_pharmacy stop" - echo "cloud_done local_phone stop_screen_share" - echo "cloud_download local_pizza storage" - echo "cloud_off local_play store" - echo "cloud_queue local_post_office store_mall_directory" - echo "cloud_upload local_printshop straighten" - echo "code local_see streetview" - echo "collections local_shipping strikethrough_s" - echo "collections_bookmark local_taxi style" - echo "color_lens location_city subdirectory_arrow_left" - echo "colorize location_disabled subdirectory_arrow_right" - echo "comment location_off subject" - echo "compare_arrows location_on subscriptions" - echo "compare location_searching subtitles" - echo "computer lock subway" - echo "confirmation_number lock_open supervisor_account" - echo "contact_mail lock_outline surround_sound" - echo "contact_phone looks_3 swap_calls" - echo "contacts looks_4 swap_horiz" - echo "content_copy looks_5 swap_vert" - echo "content_cut looks_6 swap_vertical_circle" - echo "content_paste looks switch_camera" - echo "control_point looks_one switch_video" - echo "control_point_duplicate looks_two sync" - echo "copyright loop sync_disabled" - echo "create loupe sync_problem" - echo "create_new_folder low_priority system_update_alt" - echo "credit_card loyalty system_update" - echo "crop_16_9 mail tab" - echo "crop_3_2 mail_outline tab_unselected" - echo "crop_5_4 map tablet_android" - echo "crop_7_5 markunread tablet" - echo "crop markunread_mailbox tablet_mac" - echo "crop_din memory tag_faces" - echo "crop_free menu tap_and_play" - echo "crop_landscape merge_type terrain" - echo "crop_original message text_fields" - echo "crop_portrait mic text_format" - echo "crop_rotate mic_none textsms" - echo "crop_square mic_off texture" - echo "dashboard mms theaters" - echo "data_usage mode_comment thumb_down" - echo "date_range mode_edit thumb_up" - echo "dehaze monetization_on thumbs_up_down" - echo "delete money_off time_to_leave" - echo "delete_forever monochrome_photos timelapse" - echo "delete_sweep mood_bad timeline" - echo "description mood timer_10" - echo "desktop_mac more timer_3" - echo "desktop_windows more_horiz timer" - echo "details more_vert timer_off" - echo "developer_board motorcycle title" - echo "developer_mode mouse toc" - echo "device_hub move_to_inbox today" - echo "devices movie toll" - echo "devices_other movie_creation tonality" - echo "dialer_sip movie_filter touch_app" - echo "dialpad multiline_chart toys" - echo "directions_bike music_note track_changes" - echo "directions music_video traffic" - echo "directions_boat my_location train" - echo "directions_bus nature tram" - echo "directions_car nature_people transfer_within_a_station" - echo "directions_railway navigate_before transform" - echo "directions_run navigate_next translate" - echo "directions_subway navigation trending_down" - echo "directions_transit near_me trending_flat" - echo "directions_walk network_cell trending_up" - echo "disc_full network_check tune" - echo "dns network_locked turned_in" - echo "do_not_disturb_alt network_wifi turned_in_not" - echo "do_not_disturb new_releases tv" - echo "do_not_disturb_off next_week unarchive" - echo "do_not_disturb_on nfc undo" - echo "dock no_encryption unfold_less" - echo "domain no_sim unfold_more" - echo "done_all not_interested update" - echo "done note_add usb" - echo "donut_large note verified_user" - echo "donut_small notifications_active vertical_align_bottom" - echo "drafts notifications vertical_align_center" - echo "drag_handle notifications_none vertical_align_top" - echo "drive_eta notifications_off vibration" - echo "dvr notifications_paused video_call" - echo "edit offline_pin video_label" - echo "edit_location ondemand_video video_library" - echo "eject opacity videocam" - echo "email open_in_browser videocam_off" - echo "enhanced_encryption open_in_new videogame_asset" - echo "equalizer open_with view_agenda" - echo "error pages view_array" - echo "error_outline pageview view_carousel" - echo "euro_symbol palette view_column" - echo "ev_station pan_tool view_comfy" - echo "event_available panorama view_compact" - echo "event panorama_fish_eye view_day" - echo "event_busy panorama_horizontal view_headline" - echo "event_note panorama_vertical view_list" - echo "event_seat panorama_wide_angle view_module" - echo "exit_to_app party_mode view_quilt" - echo "expand_less pause view_stream" - echo "expand_more pause_circle_filled view_week" - echo "explicit pause_circle_outline vignette" - echo "explore payment visibility" - echo "exposure people visibility_off" - echo "exposure_neg_1 people_outline voice_chat" - echo "exposure_neg_2 perm_camera_mic voicemail" - echo "exposure_plus_1 perm_contact_calendar volume_down" - echo "exposure_plus_2 perm_data_setting volume_mute" - echo "exposure_zero perm_device_information volume_off" - echo "extension perm_identity volume_up" - echo "face perm_media vpn_key" - echo "fast_forward perm_phone_msg vpn_lock" - echo "fast_rewind perm_scan_wifi wallpaper" - echo "favorite person_add warning" - echo "favorite_border person watch" - echo "featured_play_list person_outline watch_later" - echo "featured_video person_pin wb_auto" - echo "feedback person_pin_circle wb_cloudy" - echo "fiber_dvr personal_video wb_incandescent" - echo "fiber_manual_record pets wb_iridescent" - echo "fiber_new phone_android wb_sunny" - echo "fiber_pin phone wc" - echo "fiber_smart_record phone_bluetooth_speaker web_asset" - echo "file_download phone_forwarded web" - echo "file_upload phone_in_talk weekend" - echo "filter_1 phone_iphone whatshot" - echo "filter_2 phone_locked widgets" - echo "filter_3 phone_missed wifi" - echo "filter_4 phone_paused wifi_lock" - echo "filter_5 phonelink wifi_tethering" - echo "filter_6 phonelink_erase work" - echo "filter_7 phonelink_lock wrap_text" - echo "filter_8 phonelink_off youtube_searched_for" - echo "filter_9 phonelink_ring zoom_in" - echo "filter_9_plus phonelink_setup zoom_out" - echo "filter_b_and_w photo_album zoom_out_map" - echo "filter photo" -} - OPT_ACTION="" OPT_ALERT_ONCE="" OPT_BUTTON1_ACTION="" @@ -434,7 +106,7 @@ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ content:,group:,help,help-actions,\ -id:,icon:,icon-list,image-path:,\ +id:,icon:,image-path:,\ led-color:,led-on:,led-off:,\ media-previous:,media-next:,media-play:,media-pause:,\ on-delete:,ongoing,\ @@ -460,7 +132,6 @@ while true; do --help-actions) show_help_actions; exit 0;; -i | --id) OPT_ID="$2"; shift 2;; --icon) OPT_ICON="$2"; shift 2;; - --icon-list) icon_list; exit 0;; --image-path) OPT_IMAGE_PATH="$2"; shift 2;; --led-color) OPT_LED_COLOR="$2"; shift 2;; --led-off) OPT_LED_OFF="$2"; shift 2;; From f5c7633601297b7487a8a14d2695f8a333ddd440 Mon Sep 17 00:00:00 2001 From: AbdullahM0hamed <25087116+AbdullahM0hamed@users.noreply.github.com> Date: Tue, 23 Jun 2020 00:53:23 +0100 Subject: [PATCH 19/68] termux-download: add ability to set download path --- scripts/termux-download | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/termux-download b/scripts/termux-download index ae5ad86..161603a 100755 --- a/scripts/termux-download +++ b/scripts/termux-download @@ -7,6 +7,7 @@ show_usage () { echo "Download a resource using the system download manager." echo " -d description description for the download request notification" echo " -t title title for the download request notification" + echo " -p path full path to which the file should be downloaded" exit 0 } @@ -14,13 +15,16 @@ ARG_D="" OPT_D="" ARG_T="" OPT_T="" +ARG_P="" +OPT_P="" -while getopts :hd:t: option +while getopts :hd:t:p: option do case "$option" in h) show_usage;; d) ARG_D="--es description"; OPT_D="$OPTARG";; t) ARG_T="--es title"; OPT_T="$OPTARG";; + p) ARG_P="--es path"; OPT_P="$OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done @@ -34,6 +38,7 @@ URL_TO_DOWNLOAD="$1" set -- if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi +if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P "$OPT_P"; fi set -- "$@" "$URL_TO_DOWNLOAD" /data/data/com.termux/files/usr/libexec/termux-api Download "$@" From c9f1c409b9d48c377a8f0de7c5b76af7d9e645b8 Mon Sep 17 00:00:00 2001 From: Kaan Karaagacli Date: Sun, 9 Aug 2020 15:01:23 -0700 Subject: [PATCH 20/68] Allow signing raw messages in keystore Add NONE to the allowed digests so that the keys can be used to sign messages that are already hashed. --- scripts/termux-keystore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-keystore b/scripts/termux-keystore index 66a69e1..f14cd6f 100755 --- a/scripts/termux-keystore +++ b/scripts/termux-keystore @@ -109,7 +109,7 @@ generate_key () { # purpose 12 is SIGN+VERIFY $CMD_BASE -e command generate -e alias "$ALIAS" -e algorithm "$ALGORITHM" \ - --ei purposes 12 --esa digests SHA-1,SHA-256,SHA-384,SHA-512 \ + --ei purposes 12 --esa digests NONE,SHA-1,SHA-256,SHA-384,SHA-512 \ --ei size "$SIZE" -e curve "$CURVE" --ei validity "$VALIDITY" } From 9403af2f91a0793b70e228cf694fa3edd6d77270 Mon Sep 17 00:00:00 2001 From: Lucy Phipps Date: Tue, 29 Sep 2020 07:26:34 +0100 Subject: [PATCH 21/68] depend on util-linux getopt since busybox is deprecated in Termux --- scripts/termux-job-scheduler | 2 +- scripts/termux-notification | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 87e884d..ac59d9e 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -39,7 +39,7 @@ OPT_PERSISTED="" OPT_TRIGGER_CONTENT_URI="" OPT_TRIGGER_CONTENT_FLAG="" -TEMP=`busybox getopt \ +TEMP=`getopt \ -n $SCRIPTNAME \ -o hs:p \ --long script:,\ diff --git a/scripts/termux-notification b/scripts/termux-notification index bf7ee89..b361ec0 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -98,7 +98,7 @@ OPT_TITLE="" OPT_TYPE="" OPT_VIBRATE="" -TEMP=`busybox getopt \ +TEMP=`getopt \ -n $SCRIPTNAME \ -o hc:i:t: \ --long action:,alert-once,\ From e3c381151e23a66206b7f8b6eac2430c1d42a9e4 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Sat, 31 Oct 2020 00:29:49 +0200 Subject: [PATCH 22/68] make it possible to easily change prefix in binary & scripts --- Makefile | 7 +++++-- scripts/termux-audio-info | 4 ++-- scripts/termux-battery-status | 4 ++-- scripts/termux-brightness | 4 ++-- scripts/termux-call-log | 4 ++-- scripts/termux-camera-info | 4 ++-- scripts/termux-camera-photo | 4 ++-- scripts/termux-clipboard-get | 4 ++-- scripts/termux-clipboard-set | 4 ++-- scripts/termux-contact-list | 4 ++-- scripts/termux-dialog | 4 ++-- scripts/termux-download | 4 ++-- scripts/termux-fingerprint | 4 ++-- scripts/termux-infrared-frequencies | 4 ++-- scripts/termux-infrared-transmit | 4 ++-- scripts/termux-job-scheduler | 4 ++-- scripts/termux-keystore | 4 ++-- scripts/termux-location | 4 ++-- scripts/termux-media-player | 4 ++-- scripts/termux-media-scan | 4 ++-- scripts/termux-microphone-record | 4 ++-- scripts/termux-notification | 6 +++--- scripts/termux-notification-list | 4 ++-- scripts/termux-notification-remove | 4 ++-- scripts/termux-sensor | 4 ++-- scripts/termux-share | 6 +++--- scripts/termux-sms-inbox | 2 +- scripts/termux-sms-list | 4 ++-- scripts/termux-sms-send | 4 ++-- scripts/termux-speech-to-text | 4 ++-- scripts/termux-storage-get | 4 ++-- scripts/termux-telephony-call | 4 ++-- scripts/termux-telephony-cellinfo | 4 ++-- scripts/termux-telephony-deviceinfo | 4 ++-- scripts/termux-toast | 4 ++-- scripts/termux-torch | 4 ++-- scripts/termux-tts-engines | 4 ++-- scripts/termux-tts-speak | 4 ++-- scripts/termux-usb | 4 ++-- scripts/termux-vibrate | 4 ++-- scripts/termux-volume | 4 ++-- scripts/termux-wallpaper | 4 ++-- scripts/termux-wifi-connectioninfo | 4 ++-- scripts/termux-wifi-enable | 4 ++-- scripts/termux-wifi-scaninfo | 4 ++-- termux-api.c | 10 +++++----- 46 files changed, 99 insertions(+), 96 deletions(-) mode change 100644 => 100755 scripts/termux-wifi-enable diff --git a/Makefile b/Makefile index 09e96cf..ecbcc90 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS += -std=c11 -Wall -Wextra -pedantic -Werror PREFIX ?= /data/data/com.termux/files/usr +CFLAGS += -std=c11 -Wall -Wextra -pedantic -Werror -DPREFIX=\"$(PREFIX)\" termux-api: termux-api.c @@ -7,6 +7,9 @@ install: termux-api mkdir -p $(PREFIX)/bin/ $(PREFIX)/libexec/ install termux-api $(PREFIX)/libexec/ install termux-callback $(PREFIX)/libexec/ - install scripts/* $(PREFIX)/bin/ + for i in scripts/*; do \ + sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $i $(PREFIX)/bin/$i; \ + chmod 700 $(PREFIX)/bin/$i; \ + done .PHONY: install diff --git a/scripts/termux-audio-info b/scripts/termux-audio-info index 25525b8..5add06f 100755 --- a/scripts/termux-audio-info +++ b/scripts/termux-audio-info @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-audio-info @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api AudioInfo +@TERMUX_PREFIX@/libexec/termux-api AudioInfo diff --git a/scripts/termux-battery-status b/scripts/termux-battery-status index e540723..919535a 100755 --- a/scripts/termux-battery-status +++ b/scripts/termux-battery-status @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-battery-status @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api BatteryStatus +@TERMUX_PREFIX@/libexec/termux-api BatteryStatus diff --git a/scripts/termux-brightness b/scripts/termux-brightness index a0a9baf..799cef5 100755 --- a/scripts/termux-brightness +++ b/scripts/termux-brightness @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-brightness @@ -23,4 +23,4 @@ else ARGS="--ei brightness $1 --ez auto false" fi -/data/data/com.termux/files/usr/libexec/termux-api Brightness $ARGS +@TERMUX_PREFIX@/libexec/termux-api Brightness $ARGS diff --git a/scripts/termux-call-log b/scripts/termux-call-log index 14e48a2..3d8df1e 100755 --- a/scripts/termux-call-log +++ b/scripts/termux-call-log @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -u PARAM_LIMIT=10 @@ -29,4 +29,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT" -/data/data/com.termux/files/usr/libexec/termux-api CallLog $PARAMS +@TERMUX_PREFIX@/libexec/termux-api CallLog $PARAMS diff --git a/scripts/termux-camera-info b/scripts/termux-camera-info index f59f9f9..32fcbd9 100755 --- a/scripts/termux-camera-info +++ b/scripts/termux-camera-info @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-camera-info @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api CameraInfo +@TERMUX_PREFIX@/libexec/termux-api CameraInfo diff --git a/scripts/termux-camera-photo b/scripts/termux-camera-photo index ec094af..62d5751 100755 --- a/scripts/termux-camera-photo +++ b/scripts/termux-camera-photo @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-camera-photo @@ -27,4 +27,4 @@ if [ $# != 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi touch "$1" PARAMS="$PARAMS --es file `realpath $1`" -/data/data/com.termux/files/usr/libexec/termux-api CameraPhoto $PARAMS +@TERMUX_PREFIX@/libexec/termux-api CameraPhoto $PARAMS diff --git a/scripts/termux-clipboard-get b/scripts/termux-clipboard-get index edb9ff4..24b9f35 100755 --- a/scripts/termux-clipboard-get +++ b/scripts/termux-clipboard-get @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-clipboard-get @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api Clipboard +@TERMUX_PREFIX@/libexec/termux-api Clipboard diff --git a/scripts/termux-clipboard-set b/scripts/termux-clipboard-set index c043679..c401a7f 100755 --- a/scripts/termux-clipboard-set +++ b/scripts/termux-clipboard-set @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-clipboard-set @@ -17,7 +17,7 @@ do done shift $((OPTIND-1)) -CMD="/data/data/com.termux/files/usr/libexec/termux-api Clipboard -e api_version 2 --ez set true" +CMD="@TERMUX_PREFIX@/libexec/termux-api Clipboard -e api_version 2 --ez set true" if [ $# = 0 ]; then $CMD else diff --git a/scripts/termux-contact-list b/scripts/termux-contact-list index 2779ec7..90b1024 100755 --- a/scripts/termux-contact-list +++ b/scripts/termux-contact-list @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-contact-list @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api ContactList +@TERMUX_PREFIX@/libexec/termux-api ContactList diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 1347cd6..4df392b 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u DEFAULT_WIDGET="text" @@ -277,4 +277,4 @@ if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P "$OPT_P"; fi if [ -n "$ARG_N" ]; then set -- "$@" $ARG_N "$OPT_N"; fi if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi -/data/data/com.termux/files/usr/libexec/termux-api Dialog "$@" +@TERMUX_PREFIX@/libexec/termux-api Dialog "$@" diff --git a/scripts/termux-download b/scripts/termux-download index 161603a..83da2f1 100755 --- a/scripts/termux-download +++ b/scripts/termux-download @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-download @@ -41,4 +41,4 @@ if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P "$OPT_P"; fi set -- "$@" "$URL_TO_DOWNLOAD" -/data/data/com.termux/files/usr/libexec/termux-api Download "$@" +@TERMUX_PREFIX@/libexec/termux-api Download "$@" diff --git a/scripts/termux-fingerprint b/scripts/termux-fingerprint index dee437f..ecb40b8 100755 --- a/scripts/termux-fingerprint +++ b/scripts/termux-fingerprint @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-fingerprint @@ -36,4 +36,4 @@ if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi if [ -n "$ARG_S" ]; then set -- "$@" $ARG_S "$OPT_S"; fi if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi -/data/data/com.termux/files/usr/libexec/termux-api Fingerprint "$@" +@TERMUX_PREFIX@/libexec/termux-api Fingerprint "$@" diff --git a/scripts/termux-infrared-frequencies b/scripts/termux-infrared-frequencies index 63bd57f..f7a494c 100755 --- a/scripts/termux-infrared-frequencies +++ b/scripts/termux-infrared-frequencies @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-infrared-frequencies @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api InfraredFrequencies +@TERMUX_PREFIX@/libexec/termux-api InfraredFrequencies diff --git a/scripts/termux-infrared-transmit b/scripts/termux-infrared-transmit index a0544f3..81c912a 100755 --- a/scripts/termux-infrared-transmit +++ b/scripts/termux-infrared-transmit @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-infrared-transmit @@ -25,4 +25,4 @@ if [ -z "$FREQUENCY" ]; then echo "$SCRIPTNAME: No frequency specified"; exit 1; if [ $# -lt 1 ]; then echo "$SCRIPTNAME: too few arguments"; exit 1; fi if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api InfraredTransmit $FREQUENCY --eia pattern $1 +@TERMUX_PREFIX@/libexec/termux-api InfraredTransmit $FREQUENCY --eia pattern $1 diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index ac59d9e..6943a0f 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u -f SCRIPTNAME=termux-job-scheduler @@ -90,4 +90,4 @@ if [ -n "$OPT_PERSISTED" ]; then set -- "$@" --ez persisted "$OPT_PERSISTED"; fi if [ -n "$OPT_TRIGGER_CONTENT_URI" ]; then set -- "$@" --es trigger_content_uri "$OPT_TRIGGER_CONTENT_URI"; fi if [ -n "$OPT_TRIGGER_CONTENT_FLAG" ]; then set -- "$@" --ez trigger_content_flag "$OPT_TRIGGER_CONTENT_FLAG"; fi -/data/data/com.termux/files/usr/libexec/termux-api JobScheduler "$@" +@TERMUX_PREFIX@/libexec/termux-api JobScheduler "$@" diff --git a/scripts/termux-keystore b/scripts/termux-keystore index f14cd6f..d6d7ccc 100755 --- a/scripts/termux-keystore +++ b/scripts/termux-keystore @@ -1,7 +1,7 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u -readonly CMD_BASE="/data/data/com.termux/files/usr/libexec/termux-api Keystore" +readonly CMD_BASE="@TERMUX_PREFIX@/libexec/termux-api Keystore" SCRIPTNAME=termux-keystore show_usage () { diff --git a/scripts/termux-location b/scripts/termux-location index 024e21f..7c9eb96 100755 --- a/scripts/termux-location +++ b/scripts/termux-location @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-location @@ -45,4 +45,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api Location $PARAMS +@TERMUX_PREFIX@/libexec/termux-api Location $PARAMS diff --git a/scripts/termux-media-player b/scripts/termux-media-player index 800c962..31bde86 100755 --- a/scripts/termux-media-player +++ b/scripts/termux-media-player @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e SCRIPTNAME=termux-media-player @@ -15,7 +15,7 @@ show_usage () { } main() { - /data/data/com.termux/files/usr/libexec/termux-api MediaPlayer "$@" + @TERMUX_PREFIX@/libexec/termux-api MediaPlayer "$@" } case "$1" in diff --git a/scripts/termux-media-scan b/scripts/termux-media-scan index 8ac54fb..0211529 100755 --- a/scripts/termux-media-scan +++ b/scripts/termux-media-scan @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-media-scan @@ -39,4 +39,4 @@ shift $((OPTIND-1)) if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi PATHS=`get_paths "$@" | sed ':a;N;$!ba;s/,/\\\\,/g;s/\n/,/g'` -/data/data/com.termux/files/usr/libexec/termux-api MediaScanner $PARAMS "$PATHS" +@TERMUX_PREFIX@/libexec/termux-api MediaScanner $PARAMS "$PATHS" diff --git a/scripts/termux-microphone-record b/scripts/termux-microphone-record index 9efb0d7..4b13c89 100755 --- a/scripts/termux-microphone-record +++ b/scripts/termux-microphone-record @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e SCRIPTNAME=termux-microphone-record @@ -39,7 +39,7 @@ add_params() { } call_api () { - /data/data/com.termux/files/usr/libexec/termux-api MicRecorder "$@" + @TERMUX_PREFIX@/libexec/termux-api MicRecorder "$@" } while getopts h,f:,l:,e:,b:,r:,c:,d,i,q option diff --git a/scripts/termux-notification b/scripts/termux-notification index b361ec0..5e59b71 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u -f SCRIPTNAME=termux-notification @@ -190,7 +190,7 @@ if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi if [ -n "$OPT_CONTENT" ] || [ -t 0 ]; then # we either have some content, so it takes precedence over STDIN # or have no STDIN, so we must use content even if empty - echo "$OPT_CONTENT" | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" + echo "$OPT_CONTENT" | @TERMUX_PREFIX@/libexec/termux-api Notification "$@" else # use STDIN - /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" + @TERMUX_PREFIX@/libexec/termux-api Notification "$@" fi diff --git a/scripts/termux-notification-list b/scripts/termux-notification-list index d332f15..2015197 100755 --- a/scripts/termux-notification-list +++ b/scripts/termux-notification-list @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-notification-list @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api NotificationList +@TERMUX_PREFIX@/libexec/termux-api NotificationList diff --git a/scripts/termux-notification-remove b/scripts/termux-notification-remove index 9098f64..62b1c9d 100755 --- a/scripts/termux-notification-remove +++ b/scripts/termux-notification-remove @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-notification-remove @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 1 ]; then echo "$SCRIPTNAME: no notification id specified"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id "$1" +@TERMUX_PREFIX@/libexec/termux-api NotificationRemove --es id "$1" diff --git a/scripts/termux-sensor b/scripts/termux-sensor index 9f93d2b..6f29c60 100755 --- a/scripts/termux-sensor +++ b/scripts/termux-sensor @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-sensor @@ -69,7 +69,7 @@ get_limit () { } call_api () { - /data/data/com.termux/files/usr/libexec/termux-api Sensor "$@" + @TERMUX_PREFIX@/libexec/termux-api Sensor "$@" } set_flag () { diff --git a/scripts/termux-share b/scripts/termux-share index e2b674e..90177d5 100755 --- a/scripts/termux-share +++ b/scripts/termux-share @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-share @@ -48,7 +48,7 @@ if [ $# != 0 ]; then fi # Note that the file path can contain whitespace. - /data/data/com.termux/files/usr/libexec/termux-api Share $PARAMS --es file "$(realpath "$1")" + @TERMUX_PREFIX@/libexec/termux-api Share $PARAMS --es file "$(realpath "$1")" else - /data/data/com.termux/files/usr/libexec/termux-api Share $PARAMS + @TERMUX_PREFIX@/libexec/termux-api Share $PARAMS fi diff --git a/scripts/termux-sms-inbox b/scripts/termux-sms-inbox index 5a08b60..bf26917 100755 --- a/scripts/termux-sms-inbox +++ b/scripts/termux-sms-inbox @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh echo "termux-sms-inbox: This script has been replaced by termux-sms-list." exit 1 diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list index e765905..cfa7894 100755 --- a/scripts/termux-sms-list +++ b/scripts/termux-sms-list @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -u PARAM_LIMIT=10 @@ -47,4 +47,4 @@ case "$PARAM_TYPE" in esac PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT --ei type $PARAM_TYPE" -/data/data/com.termux/files/usr/libexec/termux-api SmsInbox $PARAMS +@TERMUX_PREFIX@/libexec/termux-api SmsInbox $PARAMS diff --git a/scripts/termux-sms-send b/scripts/termux-sms-send index 6d1228d..a63d335 100755 --- a/scripts/termux-sms-send +++ b/scripts/termux-sms-send @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-sms-send @@ -24,7 +24,7 @@ if [ -z "$RECIPIENTS" ]; then echo "$SCRIPTNAME: no recipient number given"; exit 1; fi -CMD="/data/data/com.termux/files/usr/libexec/termux-api SmsSend $RECIPIENTS" +CMD="@TERMUX_PREFIX@/libexec/termux-api SmsSend $RECIPIENTS" if [ $# = 0 ]; then $CMD else diff --git a/scripts/termux-speech-to-text b/scripts/termux-speech-to-text index 7c01cdb..4bc7fd0 100755 --- a/scripts/termux-speech-to-text +++ b/scripts/termux-speech-to-text @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-speech-to-text @@ -21,7 +21,7 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -CMD=/data/data/com.termux/files/usr/libexec/termux-api +CMD=@TERMUX_PREFIX@/libexec/termux-api if [ $show_progress = true ]; then $CMD SpeechToText else diff --git a/scripts/termux-storage-get b/scripts/termux-storage-get index 8690ae2..86b236e 100755 --- a/scripts/termux-storage-get +++ b/scripts/termux-storage-get @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-storage-get @@ -21,4 +21,4 @@ shift $((OPTIND-1)) if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no output file specified"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api StorageGet --es file "$(realpath "$1")" +@TERMUX_PREFIX@/libexec/termux-api StorageGet --es file "$(realpath "$1")" diff --git a/scripts/termux-telephony-call b/scripts/termux-telephony-call index 0b8cfaa..5a61015 100755 --- a/scripts/termux-telephony-call +++ b/scripts/termux-telephony-call @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-telephony-call @@ -18,7 +18,7 @@ done shift $((OPTIND-1)) if [ $# = 1 ]; then - /data/data/com.termux/files/usr/libexec/termux-api TelephonyCall --es number "$1" + @TERMUX_PREFIX@/libexec/termux-api TelephonyCall --es number "$1" else echo "$SCRIPTNAME: No single number to call specified." >&2 exit 1 diff --git a/scripts/termux-telephony-cellinfo b/scripts/termux-telephony-cellinfo index f3e91c4..e5c3d30 100755 --- a/scripts/termux-telephony-cellinfo +++ b/scripts/termux-telephony-cellinfo @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-telephony-cellinfo @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api TelephonyCellInfo +@TERMUX_PREFIX@/libexec/termux-api TelephonyCellInfo diff --git a/scripts/termux-telephony-deviceinfo b/scripts/termux-telephony-deviceinfo index 50b435e..14115dc 100755 --- a/scripts/termux-telephony-deviceinfo +++ b/scripts/termux-telephony-deviceinfo @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-telephony-deviceinfo @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api TelephonyDeviceInfo +@TERMUX_PREFIX@/libexec/termux-api TelephonyDeviceInfo diff --git a/scripts/termux-toast b/scripts/termux-toast index 6ef1313..075c280 100755 --- a/scripts/termux-toast +++ b/scripts/termux-toast @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-toast @@ -28,7 +28,7 @@ do done shift $((OPTIND-1)) -CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS" +CMD="@TERMUX_PREFIX@/libexec/termux-api Toast $PARAMS" if [ $# = 0 ]; then $CMD diff --git a/scripts/termux-torch b/scripts/termux-torch index d9ea675..cf30efb 100755 --- a/scripts/termux-torch +++ b/scripts/termux-torch @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-torch @@ -25,4 +25,4 @@ else show_usage fi -/data/data/com.termux/files/usr/libexec/termux-api Torch $PARAMS +@TERMUX_PREFIX@/libexec/termux-api Torch $PARAMS diff --git a/scripts/termux-tts-engines b/scripts/termux-tts-engines index e9d5dd5..af0959b 100755 --- a/scripts/termux-tts-engines +++ b/scripts/termux-tts-engines @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-tts-engines @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api TextToSpeech --es engine LIST_AVAILABLE +@TERMUX_PREFIX@/libexec/termux-api TextToSpeech --es engine LIST_AVAILABLE diff --git a/scripts/termux-tts-speak b/scripts/termux-tts-speak index 7d701ff..bd95037 100755 --- a/scripts/termux-tts-speak +++ b/scripts/termux-tts-speak @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-tts-speak @@ -40,7 +40,7 @@ do done shift $((OPTIND-1)) -CMD="/data/data/com.termux/files/usr/libexec/termux-api TextToSpeech $PARAMS" +CMD="@TERMUX_PREFIX@/libexec/termux-api TextToSpeech $PARAMS" if [ $# = 0 ]; then $CMD else diff --git a/scripts/termux-usb b/scripts/termux-usb index 98e2d3f..d6c365c 100755 --- a/scripts/termux-usb +++ b/scripts/termux-usb @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-usb @@ -39,7 +39,7 @@ else PARAMS="$PARAMS --es device $1" fi -CMD="/data/data/com.termux/files/usr/libexec/termux-api Usb -a $ACTION $PARAMS" +CMD="@TERMUX_PREFIX@/libexec/termux-api Usb -a $ACTION $PARAMS" if [ "$ACTION" == "permission" ] then diff --git a/scripts/termux-vibrate b/scripts/termux-vibrate index f8a630d..36b03fa 100755 --- a/scripts/termux-vibrate +++ b/scripts/termux-vibrate @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-vibrate @@ -25,4 +25,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api Vibrate $PARAMS +@TERMUX_PREFIX@/libexec/termux-api Vibrate $PARAMS diff --git a/scripts/termux-volume b/scripts/termux-volume index 410c771..84425d9 100755 --- a/scripts/termux-volume +++ b/scripts/termux-volume @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e -u SCRIPTNAME=termux-volume @@ -27,4 +27,4 @@ if [ $# -gt 0 ]; then ARGS="-a set-volume --es stream $1 --ei volume $2" fi -/data/data/com.termux/files/usr/libexec/termux-api Volume $ARGS +@TERMUX_PREFIX@/libexec/termux-api Volume $ARGS diff --git a/scripts/termux-wallpaper b/scripts/termux-wallpaper index 4db6918..247bc72 100755 --- a/scripts/termux-wallpaper +++ b/scripts/termux-wallpaper @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash set -e @@ -49,4 +49,4 @@ set -- [ -n "$OPT_LS" ] && set -- "$@" --ez lockscreen "$OPT_LS" [ -n "$OPT_FILE" ] && set -- "$@" --es file "$OPT_FILE" [ -n "$OPT_URL" ] && set -- "$@" --es url "$OPT_URL" -/data/data/com.termux/files/usr/libexec/termux-api Wallpaper "$@" +@TERMUX_PREFIX@/libexec/termux-api Wallpaper "$@" diff --git a/scripts/termux-wifi-connectioninfo b/scripts/termux-wifi-connectioninfo index 371ace9..dde982f 100755 --- a/scripts/termux-wifi-connectioninfo +++ b/scripts/termux-wifi-connectioninfo @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-wifi-connectioninfo @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api WifiConnectionInfo +@TERMUX_PREFIX@/libexec/termux-api WifiConnectionInfo diff --git a/scripts/termux-wifi-enable b/scripts/termux-wifi-enable old mode 100644 new mode 100755 index 38f5a28..9e9a1ef --- a/scripts/termux-wifi-enable +++ b/scripts/termux-wifi-enable @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-wifi-enable @@ -18,4 +18,4 @@ case $1 in *) show_usage;; esac -/data/data/com.termux/files/usr/libexec/termux-api WifiEnable --ez enabled "$1" +@TERMUX_PREFIX@/libexec/termux-api WifiEnable --ez enabled "$1" diff --git a/scripts/termux-wifi-scaninfo b/scripts/termux-wifi-scaninfo index 32812a7..85b5fdb 100755 --- a/scripts/termux-wifi-scaninfo +++ b/scripts/termux-wifi-scaninfo @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!@TERMUX_PREFIX@/bin/sh set -e -u SCRIPTNAME=termux-wifi-scaninfo @@ -19,4 +19,4 @@ shift $((OPTIND-1)) if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -/data/data/com.termux/files/usr/libexec/termux-api WifiScanInfo +@TERMUX_PREFIX@/libexec/termux-api WifiScanInfo diff --git a/termux-api.c b/termux-api.c index de4125b..61c235c 100644 --- a/termux-api.c +++ b/termux-api.c @@ -1,7 +1,7 @@ // termux-api.c - helper binary for calling termux api classes // Usage: termux-api ${API_METHOD} ${ADDITIONAL_FLAGS} // This executes -// am broadcast com.termux.api/.TermuxApiReceiver --es socket_input ${INPUT_SOCKET} +// am broadcast com.termux.api/.TermuxApiReceiver --es socket_input ${INPUT_SOCKET} // --es socket_output ${OUTPUT_SOCKET} // --es ${API_METHOD} // ${ADDITIONAL_FLAGS} @@ -60,9 +60,9 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_stri child_argv[argc + extra_args] = NULL; // Use an a executable taking care of PATH and LD_LIBRARY_PATH: - execv("/data/data/com.termux/files/usr/bin/am", child_argv); + execv(PREFIX "/bin/am", child_argv); - perror("execv(\"/data/data/com.termux/files/usr/bin/am\")"); + perror("execv(\"" PREFIX "/bin/am\")"); exit(1); } @@ -70,8 +70,8 @@ _Noreturn void exec_callback(int fd) { char *fds; if(asprintf(&fds, "%d", fd) == -1) { perror("asprintf"); } - execl("/data/data/com.termux/files/usr/libexec/termux-callback", "termux-callback", fds, NULL); - perror("execl(\"/data/data/com.termux/files/usr/libexec/termux-callback\")"); + execl(PREFIX "/libexec/termux-callback", "termux-callback", fds, NULL); + perror("execl(\"" PREFIX "/libexec/termux-callback\")"); exit(1); } From be347255ba82dc6e8ef5227c337e6759e0c1016d Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Sat, 31 Oct 2020 00:32:03 +0200 Subject: [PATCH 23/68] fix syntax in makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ecbcc90..7d2c7c9 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ install: termux-api install termux-api $(PREFIX)/libexec/ install termux-callback $(PREFIX)/libexec/ for i in scripts/*; do \ - sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $i $(PREFIX)/bin/$i; \ - chmod 700 $(PREFIX)/bin/$i; \ + sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $$i > $(PREFIX)/bin/$$i; \ + chmod 700 $(PREFIX)/bin/$$i; \ done .PHONY: install From 70bd13bd463c27fb8f52b0ad6c18858d554ed344 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Sat, 31 Oct 2020 00:36:30 +0200 Subject: [PATCH 24/68] fix path issue when installing scripts --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7d2c7c9..121332b 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ install: termux-api mkdir -p $(PREFIX)/bin/ $(PREFIX)/libexec/ install termux-api $(PREFIX)/libexec/ install termux-callback $(PREFIX)/libexec/ - for i in scripts/*; do \ + cd scripts; for i in *; do \ sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $$i > $(PREFIX)/bin/$$i; \ chmod 700 $(PREFIX)/bin/$$i; \ done From 34b8d6adfc927c580b682e5145c8965061a73b41 Mon Sep 17 00:00:00 2001 From: Svyatoslav2 <51791931+Svyatoslav2@users.noreply.github.com> Date: Mon, 7 Dec 2020 00:15:52 +0300 Subject: [PATCH 25/68] Script for run Nfc activity from Termux:API (#113) --- scripts/termux-nfc | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/termux-nfc diff --git a/scripts/termux-nfc b/scripts/termux-nfc new file mode 100644 index 0000000..b1b26c1 --- /dev/null +++ b/scripts/termux-nfc @@ -0,0 +1,47 @@ +#!@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 " -t, text for tag" + exit 0 +} + +ARG_R="" +OPT_R="" +ARG_W="" +OPT_T="" +ARG_T="" + +PARAM="" + +if [ $# -eq 0 ];then show_usage;fi + +while getopts ":r:t: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"; ;; + ?) 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 +@TERMUX_PREFIX@/libexec/termux-api Nfc "$@" From 729fd17bb0e3cd4ab65942e976213b37a08fbb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Mar=C3=A7ais?= Date: Tue, 16 Feb 2021 22:11:39 +0100 Subject: [PATCH 26/68] termux-sms-send takes sim argument. --- scripts/termux-sms-send | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/termux-sms-send b/scripts/termux-sms-send index a63d335..e109c7f 100755 --- a/scripts/termux-sms-send +++ b/scripts/termux-sms-send @@ -3,18 +3,21 @@ set -e -u SCRIPTNAME=termux-sms-send show_usage () { - echo "Usage: $SCRIPTNAME -n number[,number2,number3,...] [text]" + echo "Usage: $SCRIPTNAME -n number[,number2,number3,...] [-s slot] [text]" echo "Send a SMS message to the specified recipient number(s). The text to send is either supplied as arguments or read from stdin if no arguments are given." echo " -n number(s) recipient number(s) - separate multiple numbers by commas" + echo " -s sim slot to use" exit 0 } RECIPIENTS="" -while getopts :hn: option +SLOT="" +while getopts :hn:s: option do case "$option" in h) show_usage;; n) RECIPIENTS="--esa recipients $OPTARG";; + s) SLOT="--ei slot $OPTARG ";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done @@ -24,7 +27,7 @@ if [ -z "$RECIPIENTS" ]; then echo "$SCRIPTNAME: no recipient number given"; exit 1; fi -CMD="@TERMUX_PREFIX@/libexec/termux-api SmsSend $RECIPIENTS" +CMD="@TERMUX_PREFIX@/libexec/termux-api SmsSend $RECIPIENTS $SLOT" if [ $# = 0 ]; then $CMD else From 4a3fb609e67b7a8c7c689293b60c408711f41638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Mar=C3=A7ais?= Date: Thu, 18 Feb 2021 18:51:20 +0100 Subject: [PATCH 27/68] Added to termux-sms-send help message --- scripts/termux-sms-send | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-sms-send b/scripts/termux-sms-send index e109c7f..8a1bd4c 100755 --- a/scripts/termux-sms-send +++ b/scripts/termux-sms-send @@ -6,7 +6,7 @@ show_usage () { echo "Usage: $SCRIPTNAME -n number[,number2,number3,...] [-s slot] [text]" echo "Send a SMS message to the specified recipient number(s). The text to send is either supplied as arguments or read from stdin if no arguments are given." echo " -n number(s) recipient number(s) - separate multiple numbers by commas" - echo " -s sim slot to use" + echo " -s slot sim slot to use - silently fails if slot number is invalid or if missing READ_PHONE_STATE permission" exit 0 } From de0d9687ecfc2e98ee2d613b9944f15a630e737a Mon Sep 17 00:00:00 2001 From: obyy <24394587+obyy@users.noreply.github.com> Date: Tue, 16 Mar 2021 22:31:12 +0100 Subject: [PATCH 28/68] Bug correction : Update termux-job-scheduler (#125) * Update termux-job-scheduler wrong syntax on trigger_content_uri (ref to line 90 and 91) --- scripts/termux-job-scheduler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler index 6943a0f..26c9ec1 100755 --- a/scripts/termux-job-scheduler +++ b/scripts/termux-job-scheduler @@ -48,7 +48,7 @@ cancel,cancel-all,\ period-ms:,network:,\ battery-not-low:,storage-not-low:,\ charging:,persisted:,help,\ -trigger_content_flag:,trigger-content-uri: \ +trigger-content-flag:,trigger-content-uri: \ -s bash \ -- "$@"` eval set -- "$TEMP" From ffd8d44d3a2361ef4a3dc32cbbf586357a1817d7 Mon Sep 17 00:00:00 2001 From: Reynaldo San Juan Date: Thu, 25 Mar 2021 11:10:58 -0400 Subject: [PATCH 29/68] Added support to get conversation list mode and messages from a number, '-f ' param to get from specefic phone number, '-c' param to get a conversation list mode --- scripts/termux-sms-list | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list index cfa7894..73ad149 100755 --- a/scripts/termux-sms-list +++ b/scripts/termux-sms-list @@ -3,7 +3,8 @@ set -u PARAM_LIMIT=10 PARAM_OFFSET=0 -PARAM_TYPE=inbox +PARAM_TYPE= all +PARAM_NUMBER="" PARAMS="" SCRIPTNAME=termux-sms-list @@ -12,12 +13,15 @@ SUPPORTED_TYPES="all|inbox|sent|draft|outbox" show_usage () { echo "Usage: $SCRIPTNAME [-d] [-l limit] [-n] [-o offset] [-t type]" echo "List SMS messages." - echo " -d show dates when messages were created" echo " -l limit offset in sms list (default: $PARAM_LIMIT)" - echo " -n show phone numbers" echo " -o offset offset in sms list (default: $PARAM_OFFSET)" echo " -t type the type of messages to list (default: $PARAM_TYPE):" echo " $SUPPORTED_TYPES" + echo " -c conversation list (unique item per conversation)" + echo " -f number the number for locate messages" + + echo " -n (obsolete) show phone numbers" + echo " -d (obsolete) show dates when messages were created" exit 0 } @@ -30,6 +34,9 @@ do n) PARAMS="$PARAMS --ez show-phone-numbers true";; o) PARAM_OFFSET=$OPTARG;; t) PARAM_TYPE=$OPTARG;; + + u) PARAMS="$PARAMS --ez conversation-list true";; + f) PARAM_NUMBER=" --es from $OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done @@ -46,5 +53,5 @@ case "$PARAM_TYPE" in *) echo "$SCRIPTNAME: Unsupported type '$PARAM_TYPE'. Use one of: $SUPPORTED_TYPES"; exit 1 ;; esac -PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT --ei type $PARAM_TYPE" +PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT --ei type $PARAM_TYPE $PARAM_NUMBER" @TERMUX_PREFIX@/libexec/termux-api SmsInbox $PARAMS From 9357388f2a5ec3a628e671ca8217be369829655c Mon Sep 17 00:00:00 2001 From: Reynaldo San Juan Date: Thu, 25 Mar 2021 14:18:10 -0400 Subject: [PATCH 30/68] solved coments from https://github.com/Grimler91 --- scripts/termux-sms-list | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list index 73ad149..5fc2e01 100755 --- a/scripts/termux-sms-list +++ b/scripts/termux-sms-list @@ -3,7 +3,7 @@ set -u PARAM_LIMIT=10 PARAM_OFFSET=0 -PARAM_TYPE= all +PARAM_TYPE=all PARAM_NUMBER="" PARAMS="" @@ -11,7 +11,7 @@ SCRIPTNAME=termux-sms-list SUPPORTED_TYPES="all|inbox|sent|draft|outbox" show_usage () { - echo "Usage: $SCRIPTNAME [-d] [-l limit] [-n] [-o offset] [-t type]" + echo "Usage: $SCRIPTNAME [-d] [-l limit] [-n] [-o offset] [-t type] [-c] [-f number]" echo "List SMS messages." echo " -l limit offset in sms list (default: $PARAM_LIMIT)" echo " -o offset offset in sms list (default: $PARAM_OFFSET)" @@ -25,7 +25,7 @@ show_usage () { exit 0 } -while getopts :hdl:t:no: option +while getopts :hdl:tf:cno: option do case "$option" in h) show_usage;; @@ -34,9 +34,8 @@ do n) PARAMS="$PARAMS --ez show-phone-numbers true";; o) PARAM_OFFSET=$OPTARG;; t) PARAM_TYPE=$OPTARG;; - - u) PARAMS="$PARAMS --ez conversation-list true";; - f) PARAM_NUMBER=" --es from $OPTARG";; + c) PARAMS="$PARAMS --ez conversation-list true";; + f) PARAM_NUMBER="--es from $OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done From ff0937794f9d027bc6d0494bf0c119e0d144c251 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 17 Apr 2021 07:42:16 +0500 Subject: [PATCH 31/68] Fix termux-notification and termux-toast from hanging when running from background In termux-notification, if content is not passed as an argument and then using `[ -t 0 ]` to detect if stdin is also not available does not work for background commands since that is only meant to check if stdin is open and is associated with a terminal. When running in background, the check will fail, since stdin will not be attached to a terminal, but moreover, no data will be available on stdin either and termux-api will hang forever waiting for input. In termux-toast, similar thing happens where if toast text argument is not passed, it is assumed that data will be available on stdin, which it may not be, making termux-api hang forever waiting for input. Now for both, if arguments are not passed, then stdin is attempted to be read directly with a 3s timeout without relying on termux-api. If no data is available on stdin, then an empty string will be passed, after aborting after 3s. Fixes termux/termux-app#1925 Thanks to @krystean for investigating the issue. --- scripts/termux-notification | 160 +++++++++++++++++++----------------- scripts/termux-toast | 49 ++++++----- 2 files changed, 116 insertions(+), 93 deletions(-) diff --git a/scripts/termux-notification b/scripts/termux-notification index 5e59b71..d3966a8 100755 --- a/scripts/termux-notification +++ b/scripts/termux-notification @@ -3,71 +3,79 @@ set -e -u -f SCRIPTNAME=termux-notification show_usage () { - echo "Usage: termux-notification [options]" - echo "Display a system notification. Content text is specified using -c/--content or read from stdin." - echo "Please read --help-actions for help with action arguments." - echo " --action action action to execute when pressing the notification" - echo " --alert-once do not alert when the notification is edited" - echo " --button1 text text to show on the first notification button" - echo " --button1-action action action to execute on the first notification button" - echo " --button2 text text to show on the second notification button" - echo " --button2-action action action to execute on the second notification button" - echo " --button3 text text to show on the third notification button" - echo " --button3-action action action to execute on the third notification button" - echo " -c/--content content content to show in the notification. Will take precedence over stdin." - echo " --group group notification group (notifications with the same group are shown together)" - echo " -h/--help show this help" - echo " --help-actions show the help for actions" - echo " -i/--id id notification id (will overwrite any previous notification with the same id)" - echo " --icon icon-name set the icon that shows up in the status bar. View available icons at" - echo " https://material.io/resources/icons/ (default icon: event_note)" - echo " --image-path path absolute path to an image which will be shown in the notification" - echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" - echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)" - echo " --led-on milliseconds number of milliseconds for the LED to be on while it's flashing (default: 800)" - echo " --on-delete action action to execute when the the notification is cleared" - echo " --ongoing pin the notification" - echo " --priority prio notification priority (high/low/max/min/default)" - echo " --sound play a sound with the notification" - echo " -t/--title title notification title to show" - echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200" - echo " --type type notification style to use (default/media)" - echo "Media actions (available with --type \"media\"):" - echo " --media-next action to execute on the media-next button" - echo " --media-pause action to execute on the media-pause button" - echo " --media-play action to execute on the media-play button" - echo " --media-previous action to execute on the media-previous button" - exit 0 + echo "Usage: termux-notification [options]" + echo "Display a system notification. Content text is specified using -c/--content or read from stdin." + echo "Please read --help-actions for help with action arguments." + echo " --action action action to execute when pressing the notification" + echo " --alert-once do not alert when the notification is edited" + echo " --button1 text text to show on the first notification button" + echo " --button1-action action action to execute on the first notification button" + echo " --button2 text text to show on the second notification button" + echo " --button2-action action action to execute on the second notification button" + echo " --button3 text text to show on the third notification button" + echo " --button3-action action action to execute on the third notification button" + echo " -c/--content content content to show in the notification. Will take" + echo " precedence over stdin. If content is not passed as" + echo " an argument or with stdin, then there will be a 3s delay." + echo " --group group notification group (notifications with the same" + echo " group are shown together)" + echo " -h/--help show this help" + echo " --help-actions show the help for actions" + echo " -i/--id id notification id (will overwrite any previous notification" + echo " with the same id)" + echo " --icon icon-name set the icon that shows up in the status bar. View" + echo " available icons at https://material.io/resources/icons/" + echo " (default icon: event_note)" + echo " --image-path path absolute path to an image which will be shown in the" + echo " notification" + echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" + echo " --led-off milliseconds number of milliseconds for the LED to be off while" + echo " it's flashing (default: 800)" + echo " --led-on milliseconds number of milliseconds for the LED to be on while" + echo " it's flashing (default: 800)" + echo " --on-delete action action to execute when the the notification is cleared" + echo " --ongoing pin the notification" + echo " --priority prio notification priority (high/low/max/min/default)" + echo " --sound play a sound with the notification" + echo " -t/--title title notification title to show" + echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200" + echo " --type type notification style to use (default/media)" + echo "Media actions (available with --type \"media\"):" + echo " --media-next action to execute on the media-next button" + echo " --media-pause action to execute on the media-pause button" + echo " --media-play action to execute on the media-play button" + echo " --media-previous action to execute on the media-previous button" + exit 0 } show_help_actions () { - echo "This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next." - echo - echo "All these commands take an action string as their argument, which is fed to \`dash -c\`." - echo "A few important things must be kept in mind when using actions:" - echo - echo "You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"." - echo "Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")." - echo - echo "Running more than one command in a single action is as easy as" - echo "--action \"command1; command2; command3\"" - echo "or" - echo "--action \"if [ -e file ]; then termux-toast yes; else termux-toast no; fi\"." - echo - echo "For anything more complex, you should put your script in a file, make it executable, and use that as the action:" - echo "--action ~/bin/script" - echo - echo "The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:" - echo " - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")" - echo " - or use something like --action \"bash -l -c 'command1; command2'\")." - echo - echo "On Android N or above, you can use the special variable \$REPLY in your actions to use Android's Direct Reply feature." - echo "This prompts the user to enter some text directly in the notification, which is then substituted into your action." - echo " - termux-notification --button1 \"Answer\" --button1-action \"termux-toast \\\$REPLY\"" - echo "will call the action:" - echo " - termux-toast \"Some text entered by the user\"" - echo "Be careful to escape shell commands correctly for single or double quotes, e.g." - echo " --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\"" + echo "This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next." + echo + echo "All these commands take an action string as their argument, which is fed to \`dash -c\`." + echo "A few important things must be kept in mind when using actions:" + echo + echo "You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"." + echo "Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")." + echo + echo "Running more than one command in a single action is as easy as" + echo "--action \"command1; command2; command3\"" + echo "or" + echo "--action \"if [ -e file ]; then termux-toast yes; else termux-toast no; fi\"." + echo + echo "For anything more complex, you should put your script in a file, make it executable, and use that as the action:" + echo "--action ~/bin/script" + echo + echo "The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:" + echo " - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")" + echo " - or use something like --action \"bash -l -c 'command1; command2'\")." + echo + echo "On Android N or above, you can use the special variable \$REPLY in your actions to use Android's Direct Reply feature." + echo "This prompts the user to enter some text directly in the notification, which is then substituted into your action." + echo " - termux-notification --button1 \"Answer\" --button1-action \"termux-toast \\\$REPLY\"" + echo "will call the action:" + echo " - termux-toast \"Some text entered by the user\"" + echo "Be careful to escape shell commands correctly for single or double quotes, e.g." + echo " --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\"" } OPT_ACTION="" @@ -79,6 +87,7 @@ OPT_BUTTON2_TEXT="" OPT_BUTTON3_ACTION="" OPT_BUTTON3_TEXT="" OPT_CONTENT="" +OPT_CONTENT_PASSED="" OPT_GROUP="" OPT_ID="" OPT_ICON="" @@ -99,9 +108,9 @@ OPT_TYPE="" OPT_VIBRATE="" TEMP=`getopt \ - -n $SCRIPTNAME \ - -o hc:i:t: \ - --long action:,alert-once,\ + -n $SCRIPTNAME \ + -o hc:i:t: \ + --long action:,alert-once,\ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ @@ -112,8 +121,8 @@ media-previous:,media-next:,media-play:,media-pause:,\ on-delete:,ongoing,\ priority:,\ sound,title:,type:,vibrate: \ - -s bash \ - -- "$@"` + -s bash \ + -- "$@"` eval set -- "$TEMP" while true; do @@ -126,7 +135,7 @@ while true; do --button2-action) OPT_BUTTON2_ACTION="$2"; shift 2;; --button3) OPT_BUTTON3_TEXT="$2"; shift 2;; --button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;; - -c | --content) OPT_CONTENT="$2"; shift 2;; + -c | --content) OPT_CONTENT_PASSED=1; OPT_CONTENT="$2"; shift 2;; --group) OPT_GROUP="$2"; shift 2;; -h | --help) show_usage;; --help-actions) show_help_actions; exit 0;; @@ -187,10 +196,13 @@ if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi if [ -n "$OPT_TYPE" ]; then set -- "$@" --es type "$OPT_TYPE"; fi if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi -if [ -n "$OPT_CONTENT" ] || [ -t 0 ]; then - # we either have some content, so it takes precedence over STDIN - # or have no STDIN, so we must use content even if empty - echo "$OPT_CONTENT" | @TERMUX_PREFIX@/libexec/termux-api Notification "$@" -else # use STDIN - @TERMUX_PREFIX@/libexec/termux-api Notification "$@" +# If content was not passed as an argument, then attempt to read from STDIN with a 3s timeout +# Content argumOPT_CONTENT="$(echo "$OPT_CONTENT")" # trim trailing newlinesent takes precedence over STDIN +if [[ "$OPT_CONTENT_PASSED" != "1" ]]; then + set +e; IFS= read -t 3 -r -d '' OPT_CONTENT; set -e; fi + +# Trim trailing newlines +OPT_CONTENT="$(echo "$OPT_CONTENT")" + +echo "$OPT_CONTENT" | @TERMUX_PREFIX@/libexec/termux-api Notification "$@" diff --git a/scripts/termux-toast b/scripts/termux-toast index 075c280..58e8843 100755 --- a/scripts/termux-toast +++ b/scripts/termux-toast @@ -3,35 +3,46 @@ set -e -u SCRIPTNAME=termux-toast show_usage () { - echo "Usage: termux-toast [-b bgcolor] [-c color] [-g gravity] [-s] [text]" - echo "Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given." - echo " -h show this help" - echo " -b set background color (default: gray)" - echo " -c set text color (default: white)" - echo " -g set position of toast: [top, middle, or bottom] (default: middle)" - echo " -s only show the toast for a short while" - echo "NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value" - exit 0 + echo "Usage: termux-toast [-b bgcolor] [-c color] [-g gravity] [-s] [text]" + echo "Show text in a Toast (a transient popup)." + echo "The toast text is either supplied as arguments or read from stdin" + echo "if no arguments are given. Arguments will take precedence over stdin." + echo "If toast text is not passed as arguments or with stdin, then there will" + echo "be a 3s delay." + echo " -h show this help" + echo " -b set background color (default: gray)" + echo " -c set text color (default: white)" + echo " -g set position of toast: [top, middle, or bottom] (default: middle)" + echo " -s only show the toast for a short while" + echo "NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value" + exit 0 } PARAMS="" while getopts :hsc:b:g: option do - case "$option" in - h) show_usage;; - s) PARAMS+=" --ez short true";; - c) PARAMS+=" --es text_color $OPTARG";; - b) PARAMS+=" --es background $OPTARG";; - g) PARAMS+=" --es gravity $OPTARG";; - ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; - esac + case "$option" in + h) show_usage;; + s) PARAMS+=" --ez short true";; + c) PARAMS+=" --es text_color $OPTARG";; + b) PARAMS+=" --es background $OPTARG";; + g) PARAMS+=" --es gravity $OPTARG";; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac done shift $((OPTIND-1)) CMD="@TERMUX_PREFIX@/libexec/termux-api Toast $PARAMS" +# If toast text was not passed as an argument, then attempt to read from STDIN with a 3s timeout +# Toast text arguments takes precedence over STDIN if [ $# = 0 ]; then - $CMD + set +e; IFS= read -t 3 -r -d '' TOAST_TEXT; set -e; else - echo "$@" | $CMD + TOAST_TEXT="$*" fi + +# Trim trailing newlines +TOAST_TEXT="$(echo "$TOAST_TEXT")" + +echo "$TOAST_TEXT" | $CMD From ae77a04f3e086dbe2126a035d7f8f2d842bb8727 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Mon, 26 Apr 2021 08:26:25 +0200 Subject: [PATCH 32/68] termux-sms-list: fix -t argument and re-order command list --- scripts/termux-sms-list | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list index 5fc2e01..b700b0c 100755 --- a/scripts/termux-sms-list +++ b/scripts/termux-sms-list @@ -25,17 +25,17 @@ show_usage () { exit 0 } -while getopts :hdl:tf:cno: option +while getopts :hdl:t:f:cno: option do case "$option" in h) show_usage;; d) PARAMS="$PARAMS --ez show-dates true";; l) PARAM_LIMIT=$OPTARG;; - n) PARAMS="$PARAMS --ez show-phone-numbers true";; - o) PARAM_OFFSET=$OPTARG;; t) PARAM_TYPE=$OPTARG;; - c) PARAMS="$PARAMS --ez conversation-list true";; f) PARAM_NUMBER="--es from $OPTARG";; + c) PARAMS="$PARAMS --ez conversation-list true";; + n) PARAMS="$PARAMS --ez show-phone-numbers true";; + o) PARAM_OFFSET=$OPTARG;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done From 3c87d51c0778af0c6a657a52d8013b45ebd46ab9 Mon Sep 17 00:00:00 2001 From: Kemuri Senpai <65429873+gXLg@users.noreply.github.com> Date: Sun, 8 Aug 2021 21:26:10 +0200 Subject: [PATCH 33/68] small fix Fixed small mistake in the help header --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 61c235c..2afdab1 100644 --- a/termux-api.c +++ b/termux-api.c @@ -3,7 +3,7 @@ // This executes // am broadcast com.termux.api/.TermuxApiReceiver --es socket_input ${INPUT_SOCKET} // --es socket_output ${OUTPUT_SOCKET} -// --es ${API_METHOD} +// --es api_method ${API_METHOD} // ${ADDITIONAL_FLAGS} // where ${INPUT_SOCKET} and ${OUTPUT_SOCKET} are addresses to linux abstract namespace sockets, // used to pass on stdin to the java implementation and pass back output from java to stdout. From 4d4eff9609f1bc59eb8656e3c4d82de5aa72c1f1 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Fri, 26 Nov 2021 22:42:33 +0100 Subject: [PATCH 34/68] termux-usb: add option to pass file descriptor as env var And remove termux-callback shell script, we can implement that function in termux-api.c. --- Makefile | 5 ++--- scripts/termux-usb | 6 +++++- termux-api.c | 24 +++++++++++++++++++++--- termux-callback | 4 ---- 4 files changed, 28 insertions(+), 11 deletions(-) delete mode 100755 termux-callback diff --git a/Makefile b/Makefile index 121332b..c3e596e 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,9 @@ termux-api: termux-api.c install: termux-api mkdir -p $(PREFIX)/bin/ $(PREFIX)/libexec/ install termux-api $(PREFIX)/libexec/ - install termux-callback $(PREFIX)/libexec/ cd scripts; for i in *; do \ - sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $$i > $(PREFIX)/bin/$$i; \ - chmod 700 $(PREFIX)/bin/$$i; \ + sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $$i > $(PREFIX)/bin/$$i; \ + chmod 700 $(PREFIX)/bin/$$i; \ done .PHONY: install diff --git a/scripts/termux-usb b/scripts/termux-usb index d6c365c..8342c86 100755 --- a/scripts/termux-usb +++ b/scripts/termux-usb @@ -9,7 +9,10 @@ show_usage () { echo " -l list available devices" echo " -r show permission request dialog if necessary" echo " -e command execute the specified command with a file descriptor" - echo " referring to the device as its argument" + echo " referring to the device as an argument (unless -E" + echo " argument is given)" + echo " -E transfer file descriptor as env var instead of as" + echo " command line argument" exit 0 } @@ -23,6 +26,7 @@ do l) ACTION="list"; ((MASK |= 1));; r) PARAMS="$PARAMS --ez request true"; ((MASK |= 2));; e) ACTION="open"; export TERMUX_CALLBACK="$OPTARG"; ((MASK |= 2));; + E) export TERMUX_EXPORT_FD=true;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done diff --git a/termux-api.c b/termux-api.c index 2afdab1..c10d24d 100644 --- a/termux-api.c +++ b/termux-api.c @@ -69,9 +69,27 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_stri _Noreturn void exec_callback(int fd) { char *fds; - if(asprintf(&fds, "%d", fd) == -1) { perror("asprintf"); } - execl(PREFIX "/libexec/termux-callback", "termux-callback", fds, NULL); - perror("execl(\"" PREFIX "/libexec/termux-callback\")"); + char *callback_fun = getenv("TERMUX_CALLBACK"); + if (callback_fun == NULL) { + perror("TERMUX_CALLBACK is not set"); + exit(1); + } + + if (asprintf(&fds, "%d", fd) == -1) + perror("asprintf"); + + char errmsg[256]; + char *export_to_env = getenv("TERMUX_EXPORT_FD"); + if (strncmp(export_to_env, "true", 4) == 0) { + if (setenv("TERMUX_USB_FD", fds, true) == -1) + perror("setenv"); + execl(callback_fun, callback_fun, NULL); + sprintf(errmsg, "execl(\"%s\", %s)", callback_fun, fds); + } else { + execl(callback_fun, callback_fun, fds, NULL); + sprintf(errmsg, "execl(\"%s\")", callback_fun); + } + perror(errmsg); exit(1); } diff --git a/termux-callback b/termux-callback deleted file mode 100755 index 86c1a77..0000000 --- a/termux-callback +++ /dev/null @@ -1,4 +0,0 @@ -#!/data/data/com.termux/files/usr/bin/bash -set -e -u -$TERMUX_CALLBACK "$@" - From 3839df69d85daf6d54e3aa695756578fe70dd5d0 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 27 Nov 2021 08:20:04 +0100 Subject: [PATCH 35/68] termux-api: break long lines and tidy up some comments --- termux-api.c | 77 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/termux-api.c b/termux-api.c index c10d24d..43c2a4e 100644 --- a/termux-api.c +++ b/termux-api.c @@ -1,12 +1,15 @@ -// termux-api.c - helper binary for calling termux api classes -// Usage: termux-api ${API_METHOD} ${ADDITIONAL_FLAGS} -// This executes -// am broadcast com.termux.api/.TermuxApiReceiver --es socket_input ${INPUT_SOCKET} -// --es socket_output ${OUTPUT_SOCKET} -// --es api_method ${API_METHOD} -// ${ADDITIONAL_FLAGS} -// where ${INPUT_SOCKET} and ${OUTPUT_SOCKET} are addresses to linux abstract namespace sockets, -// used to pass on stdin to the java implementation and pass back output from java to stdout. +/* termux-api.c - helper binary for calling termux api classes + * Usage: termux-api ${API_METHOD} ${ADDITIONAL_FLAGS} + * This executes + * am broadcast com.termux.api/.TermuxApiReceiver \ + * --es socket_input ${INPUT_SOCKET} \ + * --es socket_output ${OUTPUT_SOCKET} \ + * --es api_method ${API_METHOD} \ + * ${ADDITIONAL_FLAGS} + * where ${INPUT_SOCKET} and ${OUTPUT_SOCKET} are addresses to linux + * abstract namespace sockets, used to pass on stdin to the java + * implementation and pass back output from java to stdout. + */ #define _POSIX_SOURCE #define _GNU_SOURCE #include @@ -25,7 +28,9 @@ #include // Function which execs "am broadcast ..". -_Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_string, char* output_address_string) +_Noreturn void exec_am_broadcast(int argc, char** argv, + char* input_address_string, + char* output_address_string) { // Redirect stdout to /dev/null (but leave stderr open): close(STDOUT_FILENO); @@ -95,11 +100,16 @@ _Noreturn void exec_callback(int fd) void generate_uuid(char* str) { sprintf(str, "%x%x-%x-%x-%x-%x%x%x", - arc4random(), arc4random(), // Generates a 64-bit Hex number - (uint32_t) getpid(), // Generates a 32-bit Hex number - ((arc4random() & 0x0fff) | 0x4000), // Generates a 32-bit Hex number of the form 4xxx (4 indicates the UUID version) - arc4random() % 0x3fff + 0x8000, // Generates a 32-bit Hex number in the range [0x8000, 0xbfff] - arc4random(), arc4random(), arc4random()); // Generates a 96-bit Hex number + /* 64-bit Hex number */ + arc4random(), arc4random(), + /* 32-bit Hex number */ + (uint32_t) getpid(), + /* 32-bit Hex number of the form 4xxx (4 is the UUID version) */ + ((arc4random() & 0x0fff) | 0x4000), + /* 32-bit Hex number in the range [0x8000, 0xbfff] */ + arc4random() % 0x3fff + 0x8000, + /* 96-bit Hex number */ + arc4random(), arc4random(), arc4random()); } // Thread function which reads from stdin and writes to socket. @@ -107,7 +117,9 @@ void* transmit_stdin_to_socket(void* arg) { int output_server_socket = *((int*) arg); struct sockaddr_un remote_addr; socklen_t addrlen = sizeof(remote_addr); - int output_client_socket = accept(output_server_socket, (struct sockaddr*) &remote_addr, &addrlen); + int output_client_socket = accept(output_server_socket, + (struct sockaddr*) &remote_addr, + &addrlen); ssize_t len; char buffer[1024]; @@ -150,7 +162,10 @@ int transmit_socket_to_stdout(int input_socket_fd) { int main(int argc, char** argv) { // Do not transform children into zombies when they terminate: - struct sigaction sigchld_action = { .sa_handler = SIG_DFL, .sa_flags = SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT }; + struct sigaction sigchld_action = { + .sa_handler = SIG_DFL, + .sa_flags = SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT + }; sigaction(SIGCHLD, &sigchld_action, NULL); char input_address_string[100]; // This program reads from it. @@ -161,20 +176,28 @@ int main(int argc, char** argv) { struct sockaddr_un input_address = { .sun_family = AF_UNIX }; struct sockaddr_un output_address = { .sun_family = AF_UNIX }; - // Leave struct sockaddr_un.sun_path[0] as 0 and use the UUID string as abstract linux namespace: - strncpy(&input_address.sun_path[1], input_address_string, strlen(input_address_string)); - strncpy(&output_address.sun_path[1], output_address_string, strlen(output_address_string)); + // Leave struct sockaddr_un.sun_path[0] as 0 and use the UUID + // string as abstract linux namespace: + strncpy(&input_address.sun_path[1], input_address_string, + strlen(input_address_string)); + strncpy(&output_address.sun_path[1], output_address_string, + strlen(output_address_string)); int input_server_socket = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); if (input_server_socket == -1) { perror("socket()"); return 1; } int output_server_socket = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); if (output_server_socket == -1) { perror("socket()"); return 1; } - if (bind(input_server_socket, (struct sockaddr*) &input_address, sizeof(sa_family_t) + strlen(input_address_string) + 1) == -1) { + int ret = bind(input_server_socket, (struct sockaddr*) &input_address, + sizeof(sa_family_t) + strlen(input_address_string) + 1); + if (ret == -1) { perror("bind(input)"); return 1; } - if (bind(output_server_socket, (struct sockaddr*) &output_address, sizeof(sa_family_t) + strlen(output_address_string) + 1) == -1) { + + ret = bind(output_server_socket, (struct sockaddr*) &output_address, + sizeof(sa_family_t) + strlen(output_address_string) + 1); + if (ret == -1) { perror("bind(output)"); return 1; } @@ -185,15 +208,18 @@ int main(int argc, char** argv) { pid_t fork_result = fork(); switch (fork_result) { case -1: perror("fork()"); return 1; - case 0: exec_am_broadcast(argc, argv, input_address_string, output_address_string); + case 0: exec_am_broadcast(argc, argv, input_address_string, + output_address_string); } struct sockaddr_un remote_addr; socklen_t addrlen = sizeof(remote_addr); - int input_client_socket = accept(input_server_socket, (struct sockaddr*) &remote_addr, &addrlen); + int input_client_socket = accept(input_server_socket, (struct sockaddr*) + &remote_addr, &addrlen); pthread_t transmit_thread; - pthread_create(&transmit_thread, NULL, transmit_stdin_to_socket, &output_server_socket); + pthread_create(&transmit_thread, NULL, transmit_stdin_to_socket, + &output_server_socket); int fd = transmit_socket_to_stdout(input_client_socket); close(input_client_socket); @@ -201,4 +227,3 @@ int main(int argc, char** argv) { return 0; } - From 61ed46753820880f65e078075e69eef0b6c71042 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 27 Nov 2021 08:30:14 +0100 Subject: [PATCH 36/68] gitignore: ignore emacs temporary files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4473321..e89fbcd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ termux-api +*~ From 19e7b9f6c648b4f9d5dbb514a255770ecbc79154 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 27 Nov 2021 08:38:45 +0100 Subject: [PATCH 37/68] LICENSE: update copyright date --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 6e4a645..d5be6d1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Termux +Copyright (c) 2017-2021 Termux Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 6e36bc24d0e4279d2fa1062e782d10383aafd9f1 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 10:52:09 +0100 Subject: [PATCH 38/68] scripts/*: rename to *.in Since they contain variables like TERMUX_PREFIX that need to be sed'ed before the scripts can be use in any case. --- scripts/{termux-audio-info => termux-audio-info.in} | 0 scripts/{termux-battery-status => termux-battery-status.in} | 0 scripts/{termux-brightness => termux-brightness.in} | 0 scripts/{termux-call-log => termux-call-log.in} | 0 scripts/{termux-camera-info => termux-camera-info.in} | 0 scripts/{termux-camera-photo => termux-camera-photo.in} | 0 scripts/{termux-clipboard-get => termux-clipboard-get.in} | 0 scripts/{termux-clipboard-set => termux-clipboard-set.in} | 0 scripts/{termux-contact-list => termux-contact-list.in} | 0 scripts/{termux-dialog => termux-dialog.in} | 0 scripts/{termux-download => termux-download.in} | 0 scripts/{termux-fingerprint => termux-fingerprint.in} | 0 ...termux-infrared-frequencies => termux-infrared-frequencies.in} | 0 scripts/{termux-infrared-transmit => termux-infrared-transmit.in} | 0 scripts/{termux-job-scheduler => termux-job-scheduler.in} | 0 scripts/{termux-keystore => termux-keystore.in} | 0 scripts/{termux-location => termux-location.in} | 0 scripts/{termux-media-player => termux-media-player.in} | 0 scripts/{termux-media-scan => termux-media-scan.in} | 0 scripts/{termux-microphone-record => termux-microphone-record.in} | 0 scripts/{termux-nfc => termux-nfc.in} | 0 scripts/{termux-notification-list => termux-notification-list.in} | 0 .../{termux-notification-remove => termux-notification-remove.in} | 0 scripts/{termux-notification => termux-notification.in} | 0 scripts/{termux-sensor => termux-sensor.in} | 0 scripts/{termux-share => termux-share.in} | 0 scripts/{termux-sms-inbox => termux-sms-inbox.in} | 0 scripts/{termux-sms-list => termux-sms-list.in} | 0 scripts/{termux-sms-send => termux-sms-send.in} | 0 scripts/{termux-speech-to-text => termux-speech-to-text.in} | 0 scripts/{termux-storage-get => termux-storage-get.in} | 0 scripts/{termux-telephony-call => termux-telephony-call.in} | 0 .../{termux-telephony-cellinfo => termux-telephony-cellinfo.in} | 0 ...termux-telephony-deviceinfo => termux-telephony-deviceinfo.in} | 0 scripts/{termux-toast => termux-toast.in} | 0 scripts/{termux-torch => termux-torch.in} | 0 scripts/{termux-tts-engines => termux-tts-engines.in} | 0 scripts/{termux-tts-speak => termux-tts-speak.in} | 0 scripts/{termux-usb => termux-usb.in} | 0 scripts/{termux-vibrate => termux-vibrate.in} | 0 scripts/{termux-volume => termux-volume.in} | 0 scripts/{termux-wallpaper => termux-wallpaper.in} | 0 .../{termux-wifi-connectioninfo => termux-wifi-connectioninfo.in} | 0 scripts/{termux-wifi-enable => termux-wifi-enable.in} | 0 scripts/{termux-wifi-scaninfo => termux-wifi-scaninfo.in} | 0 45 files changed, 0 insertions(+), 0 deletions(-) rename scripts/{termux-audio-info => termux-audio-info.in} (100%) mode change 100755 => 100644 rename scripts/{termux-battery-status => termux-battery-status.in} (100%) mode change 100755 => 100644 rename scripts/{termux-brightness => termux-brightness.in} (100%) mode change 100755 => 100644 rename scripts/{termux-call-log => termux-call-log.in} (100%) mode change 100755 => 100644 rename scripts/{termux-camera-info => termux-camera-info.in} (100%) mode change 100755 => 100644 rename scripts/{termux-camera-photo => termux-camera-photo.in} (100%) mode change 100755 => 100644 rename scripts/{termux-clipboard-get => termux-clipboard-get.in} (100%) mode change 100755 => 100644 rename scripts/{termux-clipboard-set => termux-clipboard-set.in} (100%) mode change 100755 => 100644 rename scripts/{termux-contact-list => termux-contact-list.in} (100%) mode change 100755 => 100644 rename scripts/{termux-dialog => termux-dialog.in} (100%) mode change 100755 => 100644 rename scripts/{termux-download => termux-download.in} (100%) mode change 100755 => 100644 rename scripts/{termux-fingerprint => termux-fingerprint.in} (100%) mode change 100755 => 100644 rename scripts/{termux-infrared-frequencies => termux-infrared-frequencies.in} (100%) mode change 100755 => 100644 rename scripts/{termux-infrared-transmit => termux-infrared-transmit.in} (100%) mode change 100755 => 100644 rename scripts/{termux-job-scheduler => termux-job-scheduler.in} (100%) mode change 100755 => 100644 rename scripts/{termux-keystore => termux-keystore.in} (100%) mode change 100755 => 100644 rename scripts/{termux-location => termux-location.in} (100%) mode change 100755 => 100644 rename scripts/{termux-media-player => termux-media-player.in} (100%) mode change 100755 => 100644 rename scripts/{termux-media-scan => termux-media-scan.in} (100%) mode change 100755 => 100644 rename scripts/{termux-microphone-record => termux-microphone-record.in} (100%) mode change 100755 => 100644 rename scripts/{termux-nfc => termux-nfc.in} (100%) rename scripts/{termux-notification-list => termux-notification-list.in} (100%) mode change 100755 => 100644 rename scripts/{termux-notification-remove => termux-notification-remove.in} (100%) mode change 100755 => 100644 rename scripts/{termux-notification => termux-notification.in} (100%) mode change 100755 => 100644 rename scripts/{termux-sensor => termux-sensor.in} (100%) mode change 100755 => 100644 rename scripts/{termux-share => termux-share.in} (100%) mode change 100755 => 100644 rename scripts/{termux-sms-inbox => termux-sms-inbox.in} (100%) mode change 100755 => 100644 rename scripts/{termux-sms-list => termux-sms-list.in} (100%) mode change 100755 => 100644 rename scripts/{termux-sms-send => termux-sms-send.in} (100%) mode change 100755 => 100644 rename scripts/{termux-speech-to-text => termux-speech-to-text.in} (100%) mode change 100755 => 100644 rename scripts/{termux-storage-get => termux-storage-get.in} (100%) mode change 100755 => 100644 rename scripts/{termux-telephony-call => termux-telephony-call.in} (100%) mode change 100755 => 100644 rename scripts/{termux-telephony-cellinfo => termux-telephony-cellinfo.in} (100%) mode change 100755 => 100644 rename scripts/{termux-telephony-deviceinfo => termux-telephony-deviceinfo.in} (100%) mode change 100755 => 100644 rename scripts/{termux-toast => termux-toast.in} (100%) mode change 100755 => 100644 rename scripts/{termux-torch => termux-torch.in} (100%) mode change 100755 => 100644 rename scripts/{termux-tts-engines => termux-tts-engines.in} (100%) mode change 100755 => 100644 rename scripts/{termux-tts-speak => termux-tts-speak.in} (100%) mode change 100755 => 100644 rename scripts/{termux-usb => termux-usb.in} (100%) mode change 100755 => 100644 rename scripts/{termux-vibrate => termux-vibrate.in} (100%) mode change 100755 => 100644 rename scripts/{termux-volume => termux-volume.in} (100%) mode change 100755 => 100644 rename scripts/{termux-wallpaper => termux-wallpaper.in} (100%) mode change 100755 => 100644 rename scripts/{termux-wifi-connectioninfo => termux-wifi-connectioninfo.in} (100%) mode change 100755 => 100644 rename scripts/{termux-wifi-enable => termux-wifi-enable.in} (100%) mode change 100755 => 100644 rename scripts/{termux-wifi-scaninfo => termux-wifi-scaninfo.in} (100%) mode change 100755 => 100644 diff --git a/scripts/termux-audio-info b/scripts/termux-audio-info.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-audio-info rename to scripts/termux-audio-info.in diff --git a/scripts/termux-battery-status b/scripts/termux-battery-status.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-battery-status rename to scripts/termux-battery-status.in diff --git a/scripts/termux-brightness b/scripts/termux-brightness.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-brightness rename to scripts/termux-brightness.in diff --git a/scripts/termux-call-log b/scripts/termux-call-log.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-call-log rename to scripts/termux-call-log.in diff --git a/scripts/termux-camera-info b/scripts/termux-camera-info.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-camera-info rename to scripts/termux-camera-info.in diff --git a/scripts/termux-camera-photo b/scripts/termux-camera-photo.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-camera-photo rename to scripts/termux-camera-photo.in diff --git a/scripts/termux-clipboard-get b/scripts/termux-clipboard-get.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-clipboard-get rename to scripts/termux-clipboard-get.in diff --git a/scripts/termux-clipboard-set b/scripts/termux-clipboard-set.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-clipboard-set rename to scripts/termux-clipboard-set.in diff --git a/scripts/termux-contact-list b/scripts/termux-contact-list.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-contact-list rename to scripts/termux-contact-list.in diff --git a/scripts/termux-dialog b/scripts/termux-dialog.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-dialog rename to scripts/termux-dialog.in diff --git a/scripts/termux-download b/scripts/termux-download.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-download rename to scripts/termux-download.in diff --git a/scripts/termux-fingerprint b/scripts/termux-fingerprint.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-fingerprint rename to scripts/termux-fingerprint.in diff --git a/scripts/termux-infrared-frequencies b/scripts/termux-infrared-frequencies.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-infrared-frequencies rename to scripts/termux-infrared-frequencies.in diff --git a/scripts/termux-infrared-transmit b/scripts/termux-infrared-transmit.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-infrared-transmit rename to scripts/termux-infrared-transmit.in diff --git a/scripts/termux-job-scheduler b/scripts/termux-job-scheduler.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-job-scheduler rename to scripts/termux-job-scheduler.in diff --git a/scripts/termux-keystore b/scripts/termux-keystore.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-keystore rename to scripts/termux-keystore.in diff --git a/scripts/termux-location b/scripts/termux-location.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-location rename to scripts/termux-location.in diff --git a/scripts/termux-media-player b/scripts/termux-media-player.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-media-player rename to scripts/termux-media-player.in diff --git a/scripts/termux-media-scan b/scripts/termux-media-scan.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-media-scan rename to scripts/termux-media-scan.in diff --git a/scripts/termux-microphone-record b/scripts/termux-microphone-record.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-microphone-record rename to scripts/termux-microphone-record.in diff --git a/scripts/termux-nfc b/scripts/termux-nfc.in similarity index 100% rename from scripts/termux-nfc rename to scripts/termux-nfc.in diff --git a/scripts/termux-notification-list b/scripts/termux-notification-list.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-notification-list rename to scripts/termux-notification-list.in diff --git a/scripts/termux-notification-remove b/scripts/termux-notification-remove.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-notification-remove rename to scripts/termux-notification-remove.in diff --git a/scripts/termux-notification b/scripts/termux-notification.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-notification rename to scripts/termux-notification.in diff --git a/scripts/termux-sensor b/scripts/termux-sensor.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-sensor rename to scripts/termux-sensor.in diff --git a/scripts/termux-share b/scripts/termux-share.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-share rename to scripts/termux-share.in diff --git a/scripts/termux-sms-inbox b/scripts/termux-sms-inbox.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-sms-inbox rename to scripts/termux-sms-inbox.in diff --git a/scripts/termux-sms-list b/scripts/termux-sms-list.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-sms-list rename to scripts/termux-sms-list.in diff --git a/scripts/termux-sms-send b/scripts/termux-sms-send.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-sms-send rename to scripts/termux-sms-send.in diff --git a/scripts/termux-speech-to-text b/scripts/termux-speech-to-text.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-speech-to-text rename to scripts/termux-speech-to-text.in diff --git a/scripts/termux-storage-get b/scripts/termux-storage-get.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-storage-get rename to scripts/termux-storage-get.in diff --git a/scripts/termux-telephony-call b/scripts/termux-telephony-call.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-telephony-call rename to scripts/termux-telephony-call.in diff --git a/scripts/termux-telephony-cellinfo b/scripts/termux-telephony-cellinfo.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-telephony-cellinfo rename to scripts/termux-telephony-cellinfo.in diff --git a/scripts/termux-telephony-deviceinfo b/scripts/termux-telephony-deviceinfo.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-telephony-deviceinfo rename to scripts/termux-telephony-deviceinfo.in diff --git a/scripts/termux-toast b/scripts/termux-toast.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-toast rename to scripts/termux-toast.in diff --git a/scripts/termux-torch b/scripts/termux-torch.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-torch rename to scripts/termux-torch.in diff --git a/scripts/termux-tts-engines b/scripts/termux-tts-engines.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-tts-engines rename to scripts/termux-tts-engines.in diff --git a/scripts/termux-tts-speak b/scripts/termux-tts-speak.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-tts-speak rename to scripts/termux-tts-speak.in diff --git a/scripts/termux-usb b/scripts/termux-usb.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-usb rename to scripts/termux-usb.in diff --git a/scripts/termux-vibrate b/scripts/termux-vibrate.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-vibrate rename to scripts/termux-vibrate.in diff --git a/scripts/termux-volume b/scripts/termux-volume.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-volume rename to scripts/termux-volume.in diff --git a/scripts/termux-wallpaper b/scripts/termux-wallpaper.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-wallpaper rename to scripts/termux-wallpaper.in diff --git a/scripts/termux-wifi-connectioninfo b/scripts/termux-wifi-connectioninfo.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-wifi-connectioninfo rename to scripts/termux-wifi-connectioninfo.in diff --git a/scripts/termux-wifi-enable b/scripts/termux-wifi-enable.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-wifi-enable rename to scripts/termux-wifi-enable.in diff --git a/scripts/termux-wifi-scaninfo b/scripts/termux-wifi-scaninfo.in old mode 100755 new mode 100644 similarity index 100% rename from scripts/termux-wifi-scaninfo rename to scripts/termux-wifi-scaninfo.in From 45af2715cebf81c5c8754ba05a558e53e1a2c6ff Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 12:02:02 +0100 Subject: [PATCH 39/68] Replace Makefile with CMakeLists.txt --- CMakeLists.txt | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 14 --------- 2 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3b15837 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,80 @@ +cmake_minimum_required(VERSION 3.0.0) +project(termux-api) +include(GNUInstallDirs) + +add_executable(termux-api termux-api.c) + +set(TERMUX_PREFIX ${CMAKE_INSTALL_PREFIX}) + +# TODO: get list through regex or similar +set(script_files + scripts/termux-audio-info + scripts/termux-battery-status + scripts/termux-brightness + scripts/termux-call-log + scripts/termux-camera-info + scripts/termux-camera-photo + scripts/termux-clipboard-get + scripts/termux-clipboard-set + scripts/termux-contact-list + scripts/termux-dialog + scripts/termux-download + scripts/termux-fingerprint + scripts/termux-infrared-frequencies + scripts/termux-infrared-transmit + scripts/termux-job-scheduler + scripts/termux-keystore + scripts/termux-location + scripts/termux-media-player + scripts/termux-media-scan + scripts/termux-microphone-record + scripts/termux-nfc + scripts/termux-notification + scripts/termux-notification-list + scripts/termux-notification-remove + scripts/termux-sensor + scripts/termux-share + scripts/termux-sms-inbox + scripts/termux-sms-list + scripts/termux-sms-send + scripts/termux-speech-to-text + scripts/termux-storage-get + scripts/termux-telephony-call + scripts/termux-telephony-cellinfo + scripts/termux-telephony-deviceinfo + scripts/termux-toast + scripts/termux-torch + scripts/termux-tts-engines + scripts/termux-tts-speak + scripts/termux-usb + scripts/termux-vibrate + scripts/termux-volume + scripts/termux-wallpaper + scripts/termux-wifi-connectioninfo + scripts/termux-wifi-enable + scripts/termux-wifi-scaninfo +) + +make_directory(scripts) +foreach(file ${script_files}) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/${file}.in + ${file} @ONLY + ) +endforeach() + +install( + FILES ${CMAKE_BINARY_DIR}/termux-api + DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE +) + +foreach(file ${script_files}) + install( + FILES ${CMAKE_BINARY_DIR}/${file} + TYPE BIN + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + ) +endforeach() diff --git a/Makefile b/Makefile deleted file mode 100644 index c3e596e..0000000 --- a/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -PREFIX ?= /data/data/com.termux/files/usr -CFLAGS += -std=c11 -Wall -Wextra -pedantic -Werror -DPREFIX=\"$(PREFIX)\" - -termux-api: termux-api.c - -install: termux-api - mkdir -p $(PREFIX)/bin/ $(PREFIX)/libexec/ - install termux-api $(PREFIX)/libexec/ - cd scripts; for i in *; do \ - sed -e "s|@TERMUX_PREFIX@|$(PREFIX)|g" $$i > $(PREFIX)/bin/$$i; \ - chmod 700 $(PREFIX)/bin/$$i; \ - done - -.PHONY: install From d3fe24d976fd62699b9b52dde4e50f0f3f24146f Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 16:58:30 +0100 Subject: [PATCH 40/68] exec_callback: fix check for TERMUX_EXPORT_FD env var Can't strncmp it without checking if it is null first. --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 43c2a4e..ef9fd33 100644 --- a/termux-api.c +++ b/termux-api.c @@ -85,7 +85,7 @@ _Noreturn void exec_callback(int fd) char errmsg[256]; char *export_to_env = getenv("TERMUX_EXPORT_FD"); - if (strncmp(export_to_env, "true", 4) == 0) { + if (export_to_env && strncmp(export_to_env, "true", 4) == 0) { if (setenv("TERMUX_USB_FD", fds, true) == -1) perror("setenv"); execl(callback_fun, callback_fun, NULL); From 231ed74f2f5ff692d800a09dc6e476024014b37b Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 18:04:53 +0100 Subject: [PATCH 41/68] termux-usb: fix -E arg It was forgotten in the getopts options. Also remove MASK check, with more options it is more tricky to keep track of how many args we should have just after the getopts loop. --- scripts/termux-usb.in | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/termux-usb.in b/scripts/termux-usb.in index 8342c86..9fe9f0a 100644 --- a/scripts/termux-usb.in +++ b/scripts/termux-usb.in @@ -3,7 +3,7 @@ set -e -u SCRIPTNAME=termux-usb show_usage () { - echo "Usage: $SCRIPTNAME [-l | [-r] [-e command] device]" + echo "Usage: $SCRIPTNAME [-l | [-r] [-E] [-e command] [device]" echo "List or access USB devices. Devices cannot be accessed directly," echo " only using $SCRIPTNAME." echo " -l list available devices" @@ -18,22 +18,19 @@ show_usage () { ACTION="permission" PARAMS="" -MASK=0 -while getopts :hlre: option +while getopts :hlre:E option do case "$option" in h) show_usage;; - l) ACTION="list"; ((MASK |= 1));; - r) PARAMS="$PARAMS --ez request true"; ((MASK |= 2));; - e) ACTION="open"; export TERMUX_CALLBACK="$OPTARG"; ((MASK |= 2));; + l) ACTION="list";; + r) PARAMS="$PARAMS --ez request true";; + e) ACTION="open"; export TERMUX_CALLBACK="$OPTARG";; E) export TERMUX_EXPORT_FD=true;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done shift $((OPTIND-1)) -if [ $MASK -eq 3 ]; then echo "$SCRIPTNAME: -l cannot be combined with other options"; exit 1; fi - if [ "$ACTION" == "list" ] then if [ $# -gt 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi From 895b0c3844bbbe3a9d463174b70faec7c78f43c1 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 16:58:06 +0100 Subject: [PATCH 42/68] Revert back to a termux-callback shell script again Using a shell script has the benefit of dealing with argument expansion for us, with the current termux-usb script we need to run something like `termux-usb -e "my_cmd my_cmd_arg"`, and just trying to execl that fails due to there being no file named `my_cmd my_cmd_arg`. --- CMakeLists.txt | 13 +++++++++++++ termux-api.c | 16 +++++----------- termux-callback.in | 3 +++ 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 termux-callback.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b15837..66d1e0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,11 @@ foreach(file ${script_files}) ) endforeach() +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/termux-callback.in + termux-callback @ONLY +) + install( FILES ${CMAKE_BINARY_DIR}/termux-api DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec @@ -78,3 +83,11 @@ foreach(file ${script_files}) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE ) endforeach() + +install( + FILES ${CMAKE_BINARY_DIR}/termux-callback + DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE +) diff --git a/termux-api.c b/termux-api.c index ef9fd33..2e20e16 100644 --- a/termux-api.c +++ b/termux-api.c @@ -74,25 +74,19 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, _Noreturn void exec_callback(int fd) { char *fds; - char *callback_fun = getenv("TERMUX_CALLBACK"); - if (callback_fun == NULL) { - perror("TERMUX_CALLBACK is not set"); - exit(1); - } - if (asprintf(&fds, "%d", fd) == -1) perror("asprintf"); char errmsg[256]; char *export_to_env = getenv("TERMUX_EXPORT_FD"); - if (export_to_env && strncmp(export_to_env, "true", 4) == 0) { + if (strncmp(export_to_env, "true", 4) == 0) { if (setenv("TERMUX_USB_FD", fds, true) == -1) perror("setenv"); - execl(callback_fun, callback_fun, NULL); - sprintf(errmsg, "execl(\"%s\", %s)", callback_fun, fds); + execl(PREFIX "/libexec/termux-callback", "termux-callback", NULL); + sprintf(errmsg, "execl(\"" PREFIX "/libexec/termux-callback\")"); } else { - execl(callback_fun, callback_fun, fds, NULL); - sprintf(errmsg, "execl(\"%s\")", callback_fun); + execl(PREFIX "/libexec/termux-callback", "termux-callback", fds, NULL); + sprintf(errmsg, "execl(\"" PREFIX "/libexec/termux-callback\", %s)", fds); } perror(errmsg); exit(1); diff --git a/termux-callback.in b/termux-callback.in new file mode 100644 index 0000000..3f36e17 --- /dev/null +++ b/termux-callback.in @@ -0,0 +1,3 @@ +#!@TERMUX_PREFIX@/bin/bash +set -e -u +$TERMUX_CALLBACK "$@" From 3154dfd25dee54dad961d0ef5dadfcbb26d9ac52 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 18:21:44 +0100 Subject: [PATCH 43/68] Fix check for TERMUX_EXPORT_FD env var .. again Was accidentally removed in revert in previous commit. --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 2e20e16..32ddcf0 100644 --- a/termux-api.c +++ b/termux-api.c @@ -79,7 +79,7 @@ _Noreturn void exec_callback(int fd) char errmsg[256]; char *export_to_env = getenv("TERMUX_EXPORT_FD"); - if (strncmp(export_to_env, "true", 4) == 0) { + if (export_to_env && strncmp(export_to_env, "true", 4) == 0) { if (setenv("TERMUX_USB_FD", fds, true) == -1) perror("setenv"); execl(PREFIX "/libexec/termux-callback", "termux-callback", NULL); From 7531d577ffae5156206ecd8cd193d0d6673c2871 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 27 Nov 2021 16:43:35 +0100 Subject: [PATCH 44/68] termux-usb: add option to open device based on vendor and productId --- scripts/termux-usb.in | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/termux-usb.in b/scripts/termux-usb.in index 9fe9f0a..26a8e36 100644 --- a/scripts/termux-usb.in +++ b/scripts/termux-usb.in @@ -3,7 +3,7 @@ set -e -u SCRIPTNAME=termux-usb show_usage () { - echo "Usage: $SCRIPTNAME [-l | [-r] [-E] [-e command] [device]" + echo "Usage: $SCRIPTNAME [-l | [-r] [-E] [-e command] [device | vendorId productId]]" echo "List or access USB devices. Devices cannot be accessed directly," echo " only using $SCRIPTNAME." echo " -l list available devices" @@ -35,9 +35,20 @@ if [ "$ACTION" == "list" ] then if [ $# -gt 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi else - if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi - if [ $# -lt 1 ]; then echo "$SCRIPTNAME: missing -l or device path"; exit 1; fi - PARAMS="$PARAMS --es device $1" + if [ $# -lt 1 ]; then + echo "$SCRIPTNAME: missing -l or device path" + exit 1 + elif [ $# -eq 1 ]; then + # The device's usbfs path has been provided + PARAMS="$PARAMS --es device $1" + elif [ $# -eq 2 ]; then + # A vendorId and ProductId of the device has been provided + PARAMS="$PARAMS --es vendorId $1" + PARAMS="$PARAMS --es productId $2" + else + echo "$SCRIPTNAME: too many arguments" + exit 1 + fi fi CMD="@TERMUX_PREFIX@/libexec/termux-api Usb -a $ACTION $PARAMS" From 77efa525680778b40eedb7c1f2321689a48561e9 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 28 Nov 2021 12:05:03 +0100 Subject: [PATCH 45/68] Mv termux-api helper functions into new library libtermux-api Any program can then link against it and get access to the API related functions. Will be useful for simplifying usb access for CLI programs for example. Also rename libexec/termux-api to libexec/termux-api-broadcast, cmake does not like having an executable with the same name as a library. --- CMakeLists.txt | 28 ++++++++++-- termux-api-broadcast.c | 23 ++++++++++ termux-api.c | 96 +++++++++++++++++++++++------------------- termux-api.h | 8 ++++ 4 files changed, 109 insertions(+), 46 deletions(-) create mode 100644 termux-api-broadcast.c create mode 100644 termux-api.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d1e0d..77876e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,13 @@ cmake_minimum_required(VERSION 3.0.0) project(termux-api) include(GNUInstallDirs) -add_executable(termux-api termux-api.c) - set(TERMUX_PREFIX ${CMAKE_INSTALL_PREFIX}) +add_library(termux-api SHARED termux-api.c) + +add_executable(termux-api-broadcast termux-api-broadcast.c) +target_link_libraries(termux-api-broadcast termux-api) + # TODO: get list through regex or similar set(script_files scripts/termux-audio-info @@ -69,13 +72,32 @@ configure_file( ) install( - FILES ${CMAKE_BINARY_DIR}/termux-api + FILES ${CMAKE_BINARY_DIR}/termux-api-broadcast DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) +# Create a symlink for termux-api-broadcast->termux-api for backwards +# compatibility +INSTALL(CODE "execute_process( \ + COMMAND ${CMAKE_COMMAND} -E create_symlink \ + termux-api-broadcast \ + ${CMAKE_INSTALL_PREFIX}/libexec/termux-api \ + )" +) + +install( + FILES ${CMAKE_BINARY_DIR}/libtermux-api.so + TYPE LIB +) + +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/termux-api.h + TYPE INCLUDE +) + foreach(file ${script_files}) install( FILES ${CMAKE_BINARY_DIR}/${file} diff --git a/termux-api-broadcast.c b/termux-api-broadcast.c new file mode 100644 index 0000000..cfd319f --- /dev/null +++ b/termux-api-broadcast.c @@ -0,0 +1,23 @@ +/* termux-api.c - helper binary for calling termux api classes + * Usage: termux-api ${API_METHOD} ${ADDITIONAL_FLAGS} + * This executes + * am broadcast com.termux.api/.TermuxApiReceiver \ + * --es socket_input ${INPUT_SOCKET} \ + * --es socket_output ${OUTPUT_SOCKET} \ + * --es api_method ${API_METHOD} \ + * ${ADDITIONAL_FLAGS} + * where ${INPUT_SOCKET} and ${OUTPUT_SOCKET} are addresses to linux + * abstract namespace sockets, used to pass on stdin to the java + * implementation and pass back output from java to stdout. + */ + +#include "termux-api.h" + +int main(int argc, char** argv) { + /* Run the api command */ + int fd = run_api_command(argc, argv); + + if (fd != -1) { exec_callback(fd); } + + return 0; +} diff --git a/termux-api.c b/termux-api.c index 32ddcf0..48d6ec0 100644 --- a/termux-api.c +++ b/termux-api.c @@ -1,15 +1,3 @@ -/* termux-api.c - helper binary for calling termux api classes - * Usage: termux-api ${API_METHOD} ${ADDITIONAL_FLAGS} - * This executes - * am broadcast com.termux.api/.TermuxApiReceiver \ - * --es socket_input ${INPUT_SOCKET} \ - * --es socket_output ${OUTPUT_SOCKET} \ - * --es api_method ${API_METHOD} \ - * ${ADDITIONAL_FLAGS} - * where ${INPUT_SOCKET} and ${OUTPUT_SOCKET} are addresses to linux - * abstract namespace sockets, used to pass on stdin to the java - * implementation and pass back output from java to stdout. - */ #define _POSIX_SOURCE #define _GNU_SOURCE #include @@ -20,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +16,12 @@ #include #include +#include "termux-api.h" + +#ifndef PREFIX +# define PREFIX "/data/data/com.termux/files/usr" +#endif + // Function which execs "am broadcast ..". _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_string, @@ -77,6 +72,9 @@ _Noreturn void exec_callback(int fd) if (asprintf(&fds, "%d", fd) == -1) perror("asprintf"); + /* TERMUX_EXPORT_FD and TERMUX_USB_FD are (currently) specific for + termux-usb, so there's some room for improvement here (this + function should be generic) */ char errmsg[256]; char *export_to_env = getenv("TERMUX_EXPORT_FD"); if (export_to_env && strncmp(export_to_env, "true", 4) == 0) { @@ -154,7 +152,7 @@ int transmit_socket_to_stdout(int input_socket_fd) { return fd; } -int main(int argc, char** argv) { +int run_api_command(int argc, char **argv) { // Do not transform children into zombies when they terminate: struct sigaction sigchld_action = { .sa_handler = SIG_DFL, @@ -162,62 +160,74 @@ int main(int argc, char** argv) { }; sigaction(SIGCHLD, &sigchld_action, NULL); - char input_address_string[100]; // This program reads from it. - char output_address_string[100]; // This program writes to it. + char input_addr_str[100]; // This program reads from it. + char output_addr_str[100]; // This program writes to it. - generate_uuid(input_address_string); - generate_uuid(output_address_string); + generate_uuid(input_addr_str); + generate_uuid(output_addr_str); - struct sockaddr_un input_address = { .sun_family = AF_UNIX }; - struct sockaddr_un output_address = { .sun_family = AF_UNIX }; + struct sockaddr_un input_addr = { .sun_family = AF_UNIX }; + struct sockaddr_un output_addr = { .sun_family = AF_UNIX }; // Leave struct sockaddr_un.sun_path[0] as 0 and use the UUID // string as abstract linux namespace: - strncpy(&input_address.sun_path[1], input_address_string, - strlen(input_address_string)); - strncpy(&output_address.sun_path[1], output_address_string, - strlen(output_address_string)); + strncpy(&input_addr.sun_path[1], input_addr_str, strlen(input_addr_str)); + strncpy(&output_addr.sun_path[1], output_addr_str, strlen(output_addr_str)); int input_server_socket = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); - if (input_server_socket == -1) { perror("socket()"); return 1; } + if (input_server_socket == -1) { + perror("socket()"); + return -1; + } int output_server_socket = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); - if (output_server_socket == -1) { perror("socket()"); return 1; } + if (output_server_socket == -1) { + perror("socket()"); + return -1; + } - int ret = bind(input_server_socket, (struct sockaddr*) &input_address, - sizeof(sa_family_t) + strlen(input_address_string) + 1); + int ret; + ret = bind(input_server_socket, (struct sockaddr*) &input_addr, + sizeof(sa_family_t) + strlen(input_addr_str) + 1); if (ret == -1) { perror("bind(input)"); - return 1; + return ret; } - ret = bind(output_server_socket, (struct sockaddr*) &output_address, - sizeof(sa_family_t) + strlen(output_address_string) + 1); + ret = bind(output_server_socket, (struct sockaddr*) &output_addr, + sizeof(sa_family_t) + strlen(output_addr_str) + 1); if (ret == -1) { perror("bind(output)"); - return 1; + return ret; + } + + if (listen(input_server_socket, 1) == -1) { + perror("listen()"); + return -1; } - if (listen(input_server_socket, 1) == -1) { perror("listen()"); return 1; } - if (listen(output_server_socket, 1) == -1) { perror("listen()"); return 1; } + if (listen(output_server_socket, 1) == -1) { + perror("listen()"); + return -1; + } pid_t fork_result = fork(); - switch (fork_result) { - case -1: perror("fork()"); return 1; - case 0: exec_am_broadcast(argc, argv, input_address_string, - output_address_string); - } + if (fork_result == -1) { + perror("fork()"); + return -1; + } else if (fork_result == 0) + exec_am_broadcast(argc, argv, input_addr_str, output_addr_str); struct sockaddr_un remote_addr; socklen_t addrlen = sizeof(remote_addr); - int input_client_socket = accept(input_server_socket, (struct sockaddr*) - &remote_addr, &addrlen); + int input_client_socket = accept(input_server_socket, + (struct sockaddr*) &remote_addr, + &addrlen); pthread_t transmit_thread; pthread_create(&transmit_thread, NULL, transmit_stdin_to_socket, &output_server_socket); + /* Device has been opened, time to actually get the fd */ int fd = transmit_socket_to_stdout(input_client_socket); close(input_client_socket); - if (fd != -1) { exec_callback(fd); } - - return 0; + return fd; } diff --git a/termux-api.h b/termux-api.h new file mode 100644 index 0000000..a0ce789 --- /dev/null +++ b/termux-api.h @@ -0,0 +1,8 @@ +#include + +_Noreturn void exec_am_broadcast(int, char**, char*, char*); +_Noreturn void exec_callback(int); +void generate_uuid(char*); +void* transmit_stdin_to_socket(void*); +int transmit_socket_to_stdout(int); +int run_api_command(int, char**); From 6f8a41eaf924e7704cd22edacdc28b5fac80c210 Mon Sep 17 00:00:00 2001 From: tareksander <57038324+tareksander@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:01:27 +0100 Subject: [PATCH 46/68] Changed: Try to connect over a unix socket to the plugin Fall back to to am if it doesn't work. --- CMakeLists.txt | 2 + scripts/termux-api-start.in | 2 + scripts/termux-api-stop.in | 2 + termux-api.c | 190 +++++++++++++++++++++++++++++++++++- termux-api.h | 1 + 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 scripts/termux-api-start.in create mode 100644 scripts/termux-api-stop.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 77876e0..004e509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ target_link_libraries(termux-api-broadcast termux-api) # TODO: get list through regex or similar set(script_files + scripts/termux-api-start + scripts/termux-api-stop scripts/termux-audio-info scripts/termux-battery-status scripts/termux-brightness diff --git a/scripts/termux-api-start.in b/scripts/termux-api-start.in new file mode 100644 index 0000000..f06d91d --- /dev/null +++ b/scripts/termux-api-start.in @@ -0,0 +1,2 @@ +#!@TERMUX_PREFIX@/bin/sh +am startservice -n com.termux.api/.KeepAliveService diff --git a/scripts/termux-api-stop.in b/scripts/termux-api-stop.in new file mode 100644 index 0000000..cf23769 --- /dev/null +++ b/scripts/termux-api-stop.in @@ -0,0 +1,2 @@ +#!@TERMUX_PREFIX@/bin/sh +am stopservice -n com.termux.api/.KeepAliveService diff --git a/termux-api.c b/termux-api.c index 48d6ec0..d6d8b5b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -22,6 +22,194 @@ # define PREFIX "/data/data/com.termux/files/usr" #endif +#define LISTEN_SOCKET_ADDRESS "com.termux.api://listen" + +/* passes the arguments to the plugin via the unix socket, falling + * back to exec_am_broadcast() if that doesn't work + */ +_Noreturn void contact_plugin(int argc, char** argv, + char* input_address_string, + char* output_address_string) +{ + // Redirect stdout to /dev/null (but leave stderr open): + close(STDOUT_FILENO); + open("/dev/null", O_RDONLY); + // Close stdin: + close(STDIN_FILENO); + + // ignore SIGPIPE, so am will be called when the connection is closed unexpectedly + struct sigaction sigpipe_action = { + .sa_handler = SIG_IGN, + .sa_flags = 0 + }; + sigaction(SIGPIPE, &sigpipe_action, NULL); + + // try to connect over the listen socket first + int listenfd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); + if (listenfd != -1) { + struct sockaddr_un listen_addr = { .sun_family = AF_UNIX }; + memcpy(listen_addr.sun_path+1, LISTEN_SOCKET_ADDRESS, strlen(LISTEN_SOCKET_ADDRESS)); + if (connect(listenfd, (struct sockaddr*) &listen_addr, sizeof(sa_family_t) + strlen(LISTEN_SOCKET_ADDRESS) + 1) == 0) { + socklen_t optlen = sizeof(struct ucred); + // check the uid to see if the socket is actually provided by the plugin + struct ucred cred; + if (getsockopt(listenfd, SOL_SOCKET, SO_PEERCRED, &cred, &optlen) == 0 && cred.uid == getuid()) { + + const char insock_str[] = "--es socket_input \""; + const char outsock_str[] = "--es socket_output \""; + const char method_str[] = "--es api_method \""; + + int len = sizeof(insock_str)-1+strlen(output_address_string)+2+sizeof(outsock_str)-1+strlen(input_address_string)+2+sizeof(method_str)-1+strlen(argv[1])+2; + for (int i = 2; i 0) { + int ret = send(listenfd, transmit, totransmit, 0); + if (ret == -1) { + err = true; + break; + } + totransmit -= ret; + } + + // transmit the argument list + if (! err) { + totransmit = len; + transmit = buffer; + while (totransmit > 0) { + int ret = send(listenfd, transmit, totransmit, 0); + if (ret == -1) { + err = true; + break; + } + totransmit -= ret; + } + } + + if (! err) { + char readbuffer[100]; + int ret; + bool first = true; + err = true; + while ((ret = read(listenfd, readbuffer, 99)) > 0) { + // if a single null byte is received as the first message, the call was successfull + if (ret == 1 && readbuffer[0] == 0 && first) { + err = false; + break; + } + // otherwise it's an error message + readbuffer[ret] = '\0'; + // printing out the error is good for debug purposes, but feel free to disable this + fprintf(stderr, "%s", readbuffer); + fflush(stderr); + first = false; + } + } + + // if everything went well, there is no need to call am + if (! err) { + exit(0); + } + } + } + } + + exec_am_broadcast(argc, argv, input_address_string, output_address_string); +} + // Function which execs "am broadcast ..". _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_string, @@ -214,7 +402,7 @@ int run_api_command(int argc, char **argv) { perror("fork()"); return -1; } else if (fork_result == 0) - exec_am_broadcast(argc, argv, input_addr_str, output_addr_str); + contact_plugin(argc, argv, input_addr_str, output_addr_str); struct sockaddr_un remote_addr; socklen_t addrlen = sizeof(remote_addr); diff --git a/termux-api.h b/termux-api.h index a0ce789..9c07b3e 100644 --- a/termux-api.h +++ b/termux-api.h @@ -1,6 +1,7 @@ #include _Noreturn void exec_am_broadcast(int, char**, char*, char*); +_Noreturn void contact_plugin(int, char**, char*, char*); _Noreturn void exec_callback(int); void generate_uuid(char*); void* transmit_stdin_to_socket(void*); From cfd4689bce9c0f85689c67cfd609b40b99945b37 Mon Sep 17 00:00:00 2001 From: tareksander <57038324+tareksander@users.noreply.github.com> Date: Mon, 20 Dec 2021 21:59:16 +0100 Subject: [PATCH 47/68] Added: channel selection to termux-notification, termux-notification-channel to create and delete channels. --- CMakeLists.txt | 1 + scripts/termux-notification-channel.in | 37 ++++++++++++++++++++++++++ scripts/termux-notification.in | 9 ++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 scripts/termux-notification-channel.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 004e509..a576c66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ set(script_files scripts/termux-microphone-record scripts/termux-nfc scripts/termux-notification + scripts/termux-notification-channel scripts/termux-notification-list scripts/termux-notification-remove scripts/termux-sensor diff --git a/scripts/termux-notification-channel.in b/scripts/termux-notification-channel.in new file mode 100644 index 0000000..1fa91d3 --- /dev/null +++ b/scripts/termux-notification-channel.in @@ -0,0 +1,37 @@ +#!@TERMUX_PREFIX@/bin/bash +set -e -u + +SCRIPTNAME=termux-notification-channel +show_usage () { + echo "Usage: $SCRIPTNAME -d channel-id" + echo " $SCRIPTNAME channel-id channel-name" + echo "Create or delete a notification channel." + echo "Only usable on Android 8.0 and higher." + echo "Use -d to delete a channel." + echo "Creating a channel requires a channel id and a channel name." + echo "The name will be visible in the options, the id is used to send notifications on that specific channel." + echo "Creating a channel with the same id again will change the name." + echo "Creating a channel with the same id as a deleted channel will restore the user settings of the deleted channel." + echo "Use termux-notification --channel channel-id to send a notification on a custom channel." + exit 0 +} + +ARGS="" + +if [ "$1" = "-d" ]; then + shift + if [ $# == 1 ]; then + ARGS="--ez delete true --es id $1" + else + show_usage + fi +else + if [ $# == 2 ]; then + ARGS="--es id $1 --es name $2" + else + show_usage + fi +fi + + +@TERMUX_PREFIX@/libexec/termux-api NotificationChannel $ARGS diff --git a/scripts/termux-notification.in b/scripts/termux-notification.in index d3966a8..61ee10b 100644 --- a/scripts/termux-notification.in +++ b/scripts/termux-notification.in @@ -17,6 +17,10 @@ show_usage () { echo " -c/--content content content to show in the notification. Will take" echo " precedence over stdin. If content is not passed as" echo " an argument or with stdin, then there will be a 3s delay." + echo " --channel channel-id Specifies the notification channel id this notification should be send on." + echo " On Android versions lower than 8.0 this is a no-op." + echo " Create custom channels with termux-notification-channel." + echo " If the channel id is invalid, the notification will not be send." echo " --group group notification group (notifications with the same" echo " group are shown together)" echo " -h/--help show this help" @@ -88,6 +92,7 @@ OPT_BUTTON3_ACTION="" OPT_BUTTON3_TEXT="" OPT_CONTENT="" OPT_CONTENT_PASSED="" +OPT_CHANNEL="" OPT_GROUP="" OPT_ID="" OPT_ICON="" @@ -114,7 +119,7 @@ TEMP=`getopt \ button1:,button1-action:,\ button2:,button2-action:,\ button3:,button3-action:,\ -content:,group:,help,help-actions,\ +content:,channel:,group:,help,help-actions,\ id:,icon:,image-path:,\ led-color:,led-on:,led-off:,\ media-previous:,media-next:,media-play:,media-pause:,\ @@ -136,6 +141,7 @@ while true; do --button3) OPT_BUTTON3_TEXT="$2"; shift 2;; --button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;; -c | --content) OPT_CONTENT_PASSED=1; OPT_CONTENT="$2"; shift 2;; + --channel) OPT_CHANNEL="$2"; shift 2;; --group) OPT_GROUP="$2"; shift 2;; -h | --help) show_usage;; --help-actions) show_help_actions; exit 0;; @@ -177,6 +183,7 @@ if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUT if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi +if [ -n "$OPT_CHANNEL" ]; then set -- "$@" --es channel "$OPT_CHANNEL"; fi if [ -n "$OPT_GROUP" ]; then set -- "$@" --es group "$OPT_GROUP"; fi if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi if [ -n "$OPT_ICON" ]; then set -- "$@" --es icon "$OPT_ICON"; fi From eaf966bf4671f5d97926791cfc08e93cecfe6f31 Mon Sep 17 00:00:00 2001 From: tareksander <57038324+tareksander@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:54:04 +0100 Subject: [PATCH 48/68] Added: Storage Access Framework programs: termux-saf-* --- CMakeLists.txt | 9 +++++++++ scripts/termux-saf-create.in | 33 ++++++++++++++++++++++++++++++ scripts/termux-saf-dirs.in | 27 +++++++++++++++++++++++++ scripts/termux-saf-ls.in | 36 +++++++++++++++++++++++++++++++++ scripts/termux-saf-managedir.in | 28 +++++++++++++++++++++++++ scripts/termux-saf-mkdir.in | 25 +++++++++++++++++++++++ scripts/termux-saf-read.in | 26 ++++++++++++++++++++++++ scripts/termux-saf-rm.in | 25 +++++++++++++++++++++++ scripts/termux-saf-stat.in | 25 +++++++++++++++++++++++ scripts/termux-saf-write.in | 24 ++++++++++++++++++++++ 10 files changed, 258 insertions(+) create mode 100644 scripts/termux-saf-create.in create mode 100644 scripts/termux-saf-dirs.in create mode 100644 scripts/termux-saf-ls.in create mode 100644 scripts/termux-saf-managedir.in create mode 100644 scripts/termux-saf-mkdir.in create mode 100644 scripts/termux-saf-read.in create mode 100644 scripts/termux-saf-rm.in create mode 100644 scripts/termux-saf-stat.in create mode 100644 scripts/termux-saf-write.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a576c66..3a10345 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,15 @@ set(script_files scripts/termux-notification-channel scripts/termux-notification-list scripts/termux-notification-remove + scripts/termux-saf-create + scripts/termux-saf-dirs + scripts/termux-saf-ls + scripts/termux-saf-managedir + scripts/termux-saf-mkdir + scripts/termux-saf-read + scripts/termux-saf-rm + scripts/termux-saf-stat + scripts/termux-saf-write scripts/termux-sensor scripts/termux-share scripts/termux-sms-inbox diff --git a/scripts/termux-saf-create.in b/scripts/termux-saf-create.in new file mode 100644 index 0000000..8b50e16 --- /dev/null +++ b/scripts/termux-saf-create.in @@ -0,0 +1,33 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-create +show_usage () { + echo "Usage: $SCRIPTNAME [-t mime-type] folder-uri name" + echo "Creates a file in a folder managed by Termux:API." + echo "Returns the URI you can use to read and write the file with termux-saf-read and termux-saf-write." + echo "You can specify the mime type explicitly or let it be guessed based on the file extension." + echo "As the folder URI you can use the URI of a directory listed by termux-saf-dirs or by termux-saf-ls." + echo "Android doesn't allow creating files with the same name, so the name may be changed if a file or folder with that name already exists." + echo "You can use termux-saf-stat with the returned URI to get the name it was really given." + echo " -h show this help" + echo " -t specify the mime type of the file. The mime type is required for other apps to recognize the content as e.g. a video. If not specified, 'application/octet-stream' is assumed, that means raw binary data." + exit 0 +} + +mime='' + +while getopts :ht: option +do + case "$option" in + h) show_usage;; + t) mime="$OPTARG";; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 2 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod createDocument --es treeuri "$1" --es filename "$2" --es mimetype "$mime" + diff --git a/scripts/termux-saf-dirs.in b/scripts/termux-saf-dirs.in new file mode 100644 index 0000000..e62e4df --- /dev/null +++ b/scripts/termux-saf-dirs.in @@ -0,0 +1,27 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-dirs +show_usage () { + echo "Usage: $SCRIPTNAME" + echo "Lists all directories you gave Termux:API in the same format as termux-saf-ls." + echo "That meas this lists the 'directory' that contains all directories you can access with the other termux-saf-* commands." + echo "The URIs can be used with the other termux-saf-* commands to create files and folders and list the directory contents." + echo "See termux-saf-managedir to give Termux:API access to a folder." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod getManagedDocumentTrees + diff --git a/scripts/termux-saf-ls.in b/scripts/termux-saf-ls.in new file mode 100644 index 0000000..7aeb807 --- /dev/null +++ b/scripts/termux-saf-ls.in @@ -0,0 +1,36 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-ls +show_usage () { + echo "Usage: $SCRIPTNAME folder-uri" + echo "Lists the files and folders in a folder identified by a URI." + echo "You can get a folder URI by:" + echo "- Listing folders with termux-saf-ls" + echo "- Giving Termux:API access to folders with termux-saf-managedir" + echo "- Listing the folders you gave Termux:API access to with termux-saf-dirs" + echo "- Creating a folder with termux-saf-mkdir" + echo "The list is returned as a JSON array with one JSON object per entry." + echo "The objects have the keys:" + echo "- 'name' for the human-readable name" + echo "- 'uri' for URI you can use with the other termux-saf-* commands" + echo "- 'type' for the mime type" + echo "- 'length' for size in bytes if it's a file" + echo "You can recognize folders by the special mime type 'vnd.android.document/directory'." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 1 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod listDirectory --es treeuri "$1" + diff --git a/scripts/termux-saf-managedir.in b/scripts/termux-saf-managedir.in new file mode 100644 index 0000000..1567033 --- /dev/null +++ b/scripts/termux-saf-managedir.in @@ -0,0 +1,28 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-managedir +show_usage () { + echo "Usage: $SCRIPTNAME" + echo "Opens the system file explorer and lets you specify a folder Termux:API get access to." + echo "You can then use the termux-saf-* utilities to manage the contents in that folder." + echo "Returns a URI identifying the directory, this URI can be used with the other termux-saf-* commands to create files and folders and list the directory contents." + echo "If you close the file manager instead, an empty string will be returned." + echo "You can use termux-saf-dirs to list out all directories you gave Termux:API access to like this." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod manageDocumentTree + diff --git a/scripts/termux-saf-mkdir.in b/scripts/termux-saf-mkdir.in new file mode 100644 index 0000000..2dbc28d --- /dev/null +++ b/scripts/termux-saf-mkdir.in @@ -0,0 +1,25 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-mkdir +show_usage () { + echo "Usage: $SCRIPTNAME parent-uri name" + echo "Creates a directory via SAF." + echo "This behaves like termux-saf-create, just for directories." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 2 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod createDocument --es treeuri "$1" --es filename "$2" --es mimetype 'vnd.android.document/directory' + diff --git a/scripts/termux-saf-read.in b/scripts/termux-saf-read.in new file mode 100644 index 0000000..89c195e --- /dev/null +++ b/scripts/termux-saf-read.in @@ -0,0 +1,26 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-read +show_usage () { + echo "Usage: $SCRIPTNAME uri" + echo "Reads from a file identified by a URI and writes the data to sstandard output." + echo "You can use pipes to process the data or redirect it into a file to make a local copy." + echo "See termux-saf-list to get the URIs to files." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 1 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod readDocument --es uri "$1" + diff --git a/scripts/termux-saf-rm.in b/scripts/termux-saf-rm.in new file mode 100644 index 0000000..0d41316 --- /dev/null +++ b/scripts/termux-saf-rm.in @@ -0,0 +1,25 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-rm +show_usage () { + echo "Usage: $SCRIPTNAME uri" + echo "Removes the file or folder at the given URI. See other termux-saf-* commands for more info." + echo "Returns 0 on success, 1 if the file or folder couldn't be deleted and 2 if another error occurred." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 1 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +exit "$(@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod removeDocument --es uri "$1")" + diff --git a/scripts/termux-saf-stat.in b/scripts/termux-saf-stat.in new file mode 100644 index 0000000..8a49f4e --- /dev/null +++ b/scripts/termux-saf-stat.in @@ -0,0 +1,25 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-stat +show_usage () { + echo "Usage: $SCRIPTNAME uri" + echo "Returns the file or folder info as a JSON object." + echo "The format is the same as an entry from termux-saf-ls." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 1 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod statURI --es uri "$1" + diff --git a/scripts/termux-saf-write.in b/scripts/termux-saf-write.in new file mode 100644 index 0000000..5109bde --- /dev/null +++ b/scripts/termux-saf-write.in @@ -0,0 +1,24 @@ +#!@TERMUX_PREFIX@/bin/sh +set -e -u + +SCRIPTNAME=termux-saf-write +show_usage () { + echo "Usage: $SCRIPTNAME uri" + echo "Writes the standard input into an existing file identified by a URI. The previous contents are erased. To create a new file, use termux-saf-create." + echo " -h show this help" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $((OPTIND-1)) + +if [ $# != 1 ]; then echo "$SCRIPTNAME: Invalid argument count"; exit 1; fi + +@TERMUX_PREFIX@/libexec/termux-api SAF --es safmethod writeDocument --es uri "$1" + From 08bcd73319825ccba1804c3f741764bc7decd551 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 2 Jan 2022 14:29:40 +0100 Subject: [PATCH 49/68] exec_am_broadcast: fix NULL assignment of last element of child_argv child_argv[argc+extra_args] is outside the allocated memory region, since it starts counting from 0. Seen with valgrind: ==22732== Invalid write of size 8 ==22732== at 0x5E876D4: exec_am_broadcast (termux-api.c:254) ==22732== Address 0x6033e10 is 0 bytes after a block of size 144 alloc'd ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231) ==22732== ==22732== Syscall param execve(argv) points to uninitialised byte(s) ==22732== at 0x5FEEB78: execve (in /apex/com.android.runtime/lib64/bionic/libc.so) ==22732== by 0x5F18023: execve (in /data/data/com.termux/files/usr/lib/libtermux-exec.so) ==22732== Address 0x6033e08 is 136 bytes inside a block of size 144 alloc'd ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231) ==22732== Uninitialised value was created by a heap allocation ==22732== at 0x5CC9FB4: malloc (in /data/data/com.termux/files/usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so) ==22732== by 0x5E875BF: exec_am_broadcast (termux-api.c:231) --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index d6d8b5b..a1cf427 100644 --- a/termux-api.c +++ b/termux-api.c @@ -245,7 +245,7 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, memcpy(child_argv + extra_args, argv + 2, (argc-1) * sizeof(char*)); // End with NULL: - child_argv[argc + extra_args] = NULL; + child_argv[argc + extra_args - 1] = NULL; // Use an a executable taking care of PATH and LD_LIBRARY_PATH: execv(PREFIX "/bin/am", child_argv); From 8684d5e4d9deb26221e15b6261812aec21df32fc Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Thu, 30 Dec 2021 22:32:08 +0100 Subject: [PATCH 50/68] termux-api.c: break some long lines And fix a typo. --- termux-api.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/termux-api.c b/termux-api.c index a1cf427..8194014 100644 --- a/termux-api.c +++ b/termux-api.c @@ -59,7 +59,10 @@ _Noreturn void contact_plugin(int argc, char** argv, const char outsock_str[] = "--es socket_output \""; const char method_str[] = "--es api_method \""; - int len = sizeof(insock_str)-1+strlen(output_address_string)+2+sizeof(outsock_str)-1+strlen(input_address_string)+2+sizeof(method_str)-1+strlen(argv[1])+2; + int len = 0; + len += sizeof(insock_str)-1 + strlen(output_address_string)+2; + len += sizeof(outsock_str)-1 + strlen(input_address_string)+2; + len += sizeof(method_str)-1 + strlen(argv[1])+2; for (int i = 2; i 0) { - // if a single null byte is received as the first message, the call was successfull + // if a single null byte is received as the first message, the call was successful if (ret == 1 && readbuffer[0] == 0 && first) { err = false; break; From d6972ebecd1e716cd77d56a1493f04522783dfc0 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Thu, 30 Dec 2021 09:54:03 +0100 Subject: [PATCH 51/68] termux-api.h: allow usage from c++ And prevent header from being included multiple times for no reason. --- termux-api.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/termux-api.h b/termux-api.h index 9c07b3e..c3a8edf 100644 --- a/termux-api.h +++ b/termux-api.h @@ -1,5 +1,12 @@ +#ifndef TERMUX_API_H +#define TERMUX_API_H + #include +#if defined(__cplusplus) +extern "C" { +#endif + _Noreturn void exec_am_broadcast(int, char**, char*, char*); _Noreturn void contact_plugin(int, char**, char*, char*); _Noreturn void exec_callback(int); @@ -7,3 +14,9 @@ void generate_uuid(char*); void* transmit_stdin_to_socket(void*); int transmit_socket_to_stdout(int); int run_api_command(int, char**); + +#if defined(__cplusplus) +} +#endif + +#endif /* TERMUX_API_H */ From 0fd5e3136cfed8ec2e50492d3d2c381f52f8022d Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Tue, 11 Oct 2022 07:41:32 +0200 Subject: [PATCH 52/68] Correct a typo in `scripts/termux-sms-list.in` --- scripts/termux-sms-list.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-sms-list.in b/scripts/termux-sms-list.in index b700b0c..dbeab67 100644 --- a/scripts/termux-sms-list.in +++ b/scripts/termux-sms-list.in @@ -13,7 +13,7 @@ SUPPORTED_TYPES="all|inbox|sent|draft|outbox" show_usage () { echo "Usage: $SCRIPTNAME [-d] [-l limit] [-n] [-o offset] [-t type] [-c] [-f number]" echo "List SMS messages." - echo " -l limit offset in sms list (default: $PARAM_LIMIT)" + echo " -l limit limit in retrieved sms list (default: $PARAM_LIMIT)" echo " -o offset offset in sms list (default: $PARAM_OFFSET)" echo " -t type the type of messages to list (default: $PARAM_TYPE):" echo " $SUPPORTED_TYPES" From f74ff801dca6fb1acdb975c3e8e8b326aa8d9acf Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Fri, 22 Dec 2023 22:52:06 +0100 Subject: [PATCH 53/68] Compile a static libtermux-api as well And link termux-api-broadcast against the static one to speed it up a bit. Suggested-by: @agnostic-apollo --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a10345..c8b1f9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,11 @@ include(GNUInstallDirs) set(TERMUX_PREFIX ${CMAKE_INSTALL_PREFIX}) add_library(termux-api SHARED termux-api.c) +add_library(termux-api-static STATIC termux-api.c) +set_target_properties(termux-api-static PROPERTIES OUTPUT_NAME termux-api) add_executable(termux-api-broadcast termux-api-broadcast.c) -target_link_libraries(termux-api-broadcast termux-api) +target_link_libraries(termux-api-broadcast termux-api-static) # TODO: get list through regex or similar set(script_files @@ -101,7 +103,9 @@ INSTALL(CODE "execute_process( \ ) install( - FILES ${CMAKE_BINARY_DIR}/libtermux-api.so + FILES + ${CMAKE_BINARY_DIR}/libtermux-api.so + ${CMAKE_BINARY_DIR}/libtermux-api.a TYPE LIB ) From e8b001399ac679eb48590cfbc7d63e55104d8629 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sun, 24 Dec 2023 01:31:58 +0500 Subject: [PATCH 54/68] Fixed: Fix termux-api commands hanging indefinitely on Android 14 by always using `TermuxAm` to send intents instead of the socket server that is run by the app This is currently only done for Android `>= 14` and is a temporary patch until termux-app release is made with finalized support for termux-am-socket to send intents Closes termux/termux-api#638, termux/termux-app#3754 Related termux/termux-app#3647, termux/TermuxAm@8b9844ab --- termux-api.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/termux-api.c b/termux-api.c index 8194014..bc8d54e 100644 --- a/termux-api.c +++ b/termux-api.c @@ -16,6 +16,10 @@ #include #include +#ifdef __ANDROID__ +#include +#endif + #include "termux-api.h" #ifndef PREFIX @@ -44,8 +48,21 @@ _Noreturn void contact_plugin(int argc, char** argv, }; sigaction(SIGPIPE, &sigpipe_action, NULL); - // try to connect over the listen socket first - int listenfd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); + // Try to connect over the listen socket first if running on Android `< 14`. + // On Android `>= 14`, if termux-api app process was started previously + // and it started the socket server, but later Android froze the + // process, the socket will still be connectable, but no response + // will be received until the app process is unfrozen agin and + // `read()` call below will hang indefinitely until that happens, + // so use legacy `am broadcast` command, which will also unfreeze + // the app process to deliver the intent. + // - https://github.com/termux/termux-api/issues/638#issuecomment-1813233924 + int listenfd = -1; + #ifdef __ANDROID__ + if (android_get_device_api_level() < 34) { + listenfd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); + } + #endif if (listenfd != -1) { struct sockaddr_un listen_addr = { .sun_family = AF_UNIX }; memcpy(listen_addr.sun_path+1, LISTEN_SOCKET_ADDRESS, strlen(LISTEN_SOCKET_ADDRESS)); From 751ed7b28a13e49395587d384f7748d00c979f4e Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sun, 24 Dec 2023 01:45:25 +0500 Subject: [PATCH 55/68] Added: Add support for `--version` to print `$TERMUX__PREFIX/libexec/termux-api-broadcast` version --- termux-api.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/termux-api.c b/termux-api.c index bc8d54e..4d6686b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -22,6 +22,8 @@ #include "termux-api.h" +#define TERMUX_API_PACKAGE_VERSION "0.57" + #ifndef PREFIX # define PREFIX "/data/data/com.termux/files/usr" #endif @@ -364,6 +366,13 @@ int transmit_socket_to_stdout(int input_socket_fd) { } int run_api_command(int argc, char **argv) { + // If only `--version` argument is passed + if (argc == 2 && strcmp(argv[1], "--version") == 0) { + fprintf(stdout, "%s\n", TERMUX_API_PACKAGE_VERSION); + fflush(stdout); + exit(0); + } + // Do not transform children into zombies when they terminate: struct sigaction sigchld_action = { .sa_handler = SIG_DFL, From e62bdadea3f26b60430bb85248f300fee68ecdcc Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sun, 24 Dec 2023 01:45:45 +0500 Subject: [PATCH 56/68] Changed: Bump to 0.58.0 --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 4d6686b..68dd822 100644 --- a/termux-api.c +++ b/termux-api.c @@ -22,7 +22,7 @@ #include "termux-api.h" -#define TERMUX_API_PACKAGE_VERSION "0.57" +#define TERMUX_API_PACKAGE_VERSION "0.58.0" #ifndef PREFIX # define PREFIX "/data/data/com.termux/files/usr" From 4253eb2f2b706c9fbb6821fcb306f0df8053981f Mon Sep 17 00:00:00 2001 From: EmilyGraceSeville7cf Date: Tue, 17 Sep 2024 08:30:19 +1000 Subject: [PATCH 57/68] Fixed(scripts/termux-call-log): Exit with error for invalid `-l` and `-o` options Co-authored-by: @EmilyGraceSeville7cf Co-authored-by: @agnostic-apollo --- scripts/termux-call-log.in | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/termux-call-log.in b/scripts/termux-call-log.in index 3d8df1e..0d09d3a 100644 --- a/scripts/termux-call-log.in +++ b/scripts/termux-call-log.in @@ -1,31 +1,45 @@ #!@TERMUX_PREFIX@/bin/bash set -u -PARAM_LIMIT=10 -PARAM_OFFSET=0 +PARAM_LIMIT_DEFAULT=10 +PARAM_LIMIT="$PARAM_LIMIT_DEFAULT" + +PARAM_OFFSET_DEFAULT=0 +PARAM_OFFSET="$PARAM_OFFSET_DEFAULT" + PARAMS="" SCRIPTNAME=termux-call-log +validate_is_postive_number() { + if [[ ! "${2:-}" =~ ^[0-9]+$ ]]; then + echo "ERROR: The -$1 value '${2:-}' is not a positive number." 1>&2 + show_usage || return $? + exit 1 + fi +} + show_usage () { - echo "Usage: $SCRIPTNAME [-l limit] [-o offset]" + echo "Usage: $SCRIPTNAME [-l ] [-o ]" echo "List call log history" - echo " -l limit offset in call log list (default: $PARAM_LIMIT)" - echo " -o offset offset in call log list (default: $PARAM_OFFSET)" - exit 0 + echo " -l limit in call log list (default: $PARAM_LIMIT_DEFAULT)" + echo " -o offset in call log list (default: $PARAM_OFFSET_DEFAULT)" } while getopts :hl:o: option do case "$option" in - h) show_usage;; - l) PARAM_LIMIT=$OPTARG;; - o) PARAM_OFFSET=$OPTARG;; + h) show_usage; exit 0;; + l) PARAM_LIMIT="$OPTARG";; + o) PARAM_OFFSET="$OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done shift $((OPTIND-1)) +validate_is_postive_number l "$PARAM_LIMIT" +validate_is_postive_number o "$PARAM_OFFSET" + if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT" From b2cb6af9fc4cfc67b4dc4852b29084d128978cbe Mon Sep 17 00:00:00 2001 From: kyufie Date: Tue, 1 Oct 2024 16:52:40 +0700 Subject: [PATCH 58/68] termux-usb: State TERMUX_USB_FD on the help page --- scripts/termux-usb.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/termux-usb.in b/scripts/termux-usb.in index 26a8e36..f68f838 100644 --- a/scripts/termux-usb.in +++ b/scripts/termux-usb.in @@ -11,8 +11,8 @@ show_usage () { echo " -e command execute the specified command with a file descriptor" echo " referring to the device as an argument (unless -E" echo " argument is given)" - echo " -E transfer file descriptor as env var instead of as" - echo " command line argument" + echo " -E transfer file descriptor as TERMUX_USB_FD env var" + echo " instead of as command line argument" exit 0 } From 6b7a800a13c50398f70935b6ec5c985f5d5d2092 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 24 Jan 2025 06:08:19 +0500 Subject: [PATCH 59/68] Added(termux-sms-list): Enhance API with new options and use `bash` instead of `sh` shell with a new script format The following options have been added. Check `termux-sms-list --help` for examples and more info. Alternate options: - `--help` for `-h`. - `--conversation-list` for `-c`. - `--message-address` for `-f`. - `--message-limit` for `-l`. - `--message-offset` for `-o`. - `--message-type` for `-t`. New options: - `-q` and `-v` options to control `TERMUX_API__LOG_LEVEL` for script, and `termux-api.c` in future. - `--conversation-limit=`: The SQL limit for returned SMS conversations. - `--conversation-offset=`: The SQL offset for returned SMS conversations. - `--conversation-return-multiple-messages`: Return multiple SMS messages per conversation. - `--conversation-return-nested-view`: Return a nested object view of conversations where each conversation contains an array of SMS messages with the conversation id as the key. - `--conversation-return-no-order-reverse`: Return SMS conversations without reversing order of conversation sort. - `--conversation-selection=`: The SQL selection for returned SMS conversations. - `--conversation-sort-order=`: The SMS conversations sort order as per SQL 'ORDER BY col1, col2, ... ASC|DESC' clause. Default value: 'date DESC'. - `--message-return-no-order-reverse`: Return SMS messages without reversing order of message sort. - `--message-selection=`: The SQL selection for returned SMS messages. - `--message-sort-order=`: The SMS messages sort order as per SQL 'ORDER BY col1, col2, ... ASC|DESC' clause. Default value: 'date DESC'. The script has been refactored to a new format for the following reasons and now uses `bash` shell. The new format will be used by all termux-api scripts in future to provide safe and consistent API scripts. Some `FIXME` remain in the script that will be fixed in future when `make` build script is used in future after https://github.com/termux/termux-packages/pull/18872 is merged. - The use of bash is needed for bash shell array support for dynamically creating API command arguments array instead of using `$PARAMS` shell variable for storing arguments which splits on IFS characters when expanded without quotes, resulting in non-deterministic behaviour. - Support for sourcing the script has been added so that external shell calls are not required for re-running the command for faster execution by calling `termux_api__sms_list__main()` function (saves ~10-15ms on Snapdragon 865 and ~40ms on Snapdragon 820). The `termux_api__*__(init|main|help|process_script_arguments|log_*) functions will exist in all API scripts to provide consistent calling mechanisms for user and third party programs. - Logging support with multiple log levels as per `TERMUX_API__LOG_LEVEL`, which will be used by `termux-api.c` in future as well. - Long arg options support and error handling for other short/long options - Termux scoped environment variables and functions are used, and local/global variables as needed. --- scripts/termux-sms-list.in | 662 ++++++++++++++++++++++++++++++++++--- 1 file changed, 611 insertions(+), 51 deletions(-) diff --git a/scripts/termux-sms-list.in b/scripts/termux-sms-list.in index dbeab67..5409e87 100644 --- a/scripts/termux-sms-list.in +++ b/scripts/termux-sms-list.in @@ -1,56 +1,616 @@ -#!@TERMUX_PREFIX@/bin/sh +#!@TERMUX_PREFIX@/bin/bash +# shellcheck shell=bash + set -u -PARAM_LIMIT=10 -PARAM_OFFSET=0 -PARAM_TYPE=all -PARAM_NUMBER="" -PARAMS="" - -SCRIPTNAME=termux-sms-list - -SUPPORTED_TYPES="all|inbox|sent|draft|outbox" -show_usage () { - echo "Usage: $SCRIPTNAME [-d] [-l limit] [-n] [-o offset] [-t type] [-c] [-f number]" - echo "List SMS messages." - echo " -l limit limit in retrieved sms list (default: $PARAM_LIMIT)" - echo " -o offset offset in sms list (default: $PARAM_OFFSET)" - echo " -t type the type of messages to list (default: $PARAM_TYPE):" - echo " $SUPPORTED_TYPES" - echo " -c conversation list (unique item per conversation)" - echo " -f number the number for locate messages" - - echo " -n (obsolete) show phone numbers" - echo " -d (obsolete) show dates when messages were created" - exit 0 +if [ -z "${BASH_VERSION:-}" ]; then + echo "The 'termux-sms-list' script must be run from a 'bash' shell."; return 64 2>/dev/null|| exit 64 # EX__USAGE +fi + +termux_api__sms_list__init() { + +# Any and all global variables used by this script must be set to +# default values here so that old/wrong values are not used as the +# `termux_api__*__main()` function of this script or some other API +# script may be called (repeatedly) after sourcing the respective +# scripts. + +TERMUX_API__SCRIPT_NAME="termux-sms-list" +TERMUX_API__API_CONTROLLER="SmsInbox" + +TERMUX_API__COMMAND_TYPE_NOOP="false" # Default: `false` + + +TERMUX_API__CONVERSATION_LIST="" # Default: `` +TERMUX_API__CONVERSATION_LIMIT="" # Default: `` +TERMUX_API__CONVERSATION_OFFSET="" # Default: `` +TERMUX_API__CONVERSATION_SELECTION="" # Default: `` +TERMUX_API__CONVERSATION_SORT_ORDER="" # Default: `` +TERMUX_API__CONVERSATION_RETURN_MULTIPLE_MESSAGES="" # Default: `` +TERMUX_API__CONVERSATION_RETURN_NESTED_VIEW="" # Default: `` +TERMUX_API__CONVERSATION_RETURN_NO_ORDER_REVERSE="" # Default: `` + + +TERMUX_API__MESSASGE_LIMIT___DEFAULT_VALUE=10 # Default: `10` +TERMUX_API__MESSASGE_LIMIT="$TERMUX_API__MESSASGE_LIMIT___DEFAULT_VALUE" # Default: `10` +TERMUX_API__MESSASGE_OFFSET___DEFAULT_VALUE=0 # Default: `0` +TERMUX_API__MESSASGE_OFFSET="$TERMUX_API__MESSASGE_OFFSET___DEFAULT_VALUE" # Default: `0` +TERMUX_API__MESSASGE_SELECTION="" # Default: `` +TERMUX_API__MESSASGE_ADDRESS="" # Default: `` +TERMUX_API__MESSAGE_SORT_ORDER="" # Default: `` +TERMUX_API__MESSASGE_TYPE_NAME___DEFAULT_VALUE="all" # Default: `all` +TERMUX_API__MESSASGE_TYPE_NAME___SUPPORTED_VALUES="all|inbox|sent|draft|outbox|failed|queued" # Default: `all|inbox|sent|draft|outbox|failed|queued` +TERMUX_API__MESSASGE_TYPE_NAME="$TERMUX_API__MESSASGE_TYPE_NAME___DEFAULT_VALUE" # Default: `all` +TERMUX_API__MESSAGE_RETURN_NO_ORDER_REVERSE="" # Default: `` + +# Backward compatibility. +TERMUX_API__MESSAGE_SHOW_DATES="" # Default: `` +TERMUX_API__MESSAGE_SHOW_PHONE_NUMBERS="" # Default: `` + + +unset TERMUX_API__API_ARGS; declare -a TERMUX_API__API_ARGS=() + + +# FIXME: +#TERMUX__PREFIX___N="@TERMUX_ENV__S_TERMUX@PREFIX" +#TERMUX__PREFIX="${!TERMUX__PREFIX___N:-}" +#[[ ! "$TERMUX__PREFIX" =~ ^(/[^/]+)+$ ]] && \ +#TERMUX__PREFIX="@TERMUX__PREFIX@" +TERMUX__PREFIX="@TERMUX_PREFIX@" + + +# FIXME: +#TERMUX_API__LOG_LEVEL___N="@TERMUX_ENV__S_TERMUX_API@LOG_LEVEL" +TERMUX_API__LOG_LEVEL___N="TERMUX_API__LOG_LEVEL" +TERMUX_API__LOG_LEVEL="${!TERMUX_API__LOG_LEVEL___N:-}" +export "${TERMUX_API__LOG_LEVEL___N?}" || return $? + +TERMUX_API__MAX_LOG_LEVEL=5 # Default: `5` (VVVERBOSE=5) +{ [[ ! "$TERMUX_API__LOG_LEVEL" =~ ^[0-9]+$ ]] || [[ "$TERMUX_API__LOG_LEVEL" -gt "$TERMUX_API__MAX_LOG_LEVEL" ]]; } && \ +TERMUX_API__LOG_LEVEL=1 # Default: `1` (OFF=0, NORMAL=1, DEBUG=2, VERBOSE=3, VVERBOSE=4 and VVVERBOSE=5) + } -while getopts :hdl:t:f:cno: option -do - case "$option" in - h) show_usage;; - d) PARAMS="$PARAMS --ez show-dates true";; - l) PARAM_LIMIT=$OPTARG;; - t) PARAM_TYPE=$OPTARG;; - f) PARAM_NUMBER="--es from $OPTARG";; - c) PARAMS="$PARAMS --ez conversation-list true";; - n) PARAMS="$PARAMS --ez show-phone-numbers true";; - o) PARAM_OFFSET=$OPTARG;; - ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + + +termux_api__log() { local log_level="${1:-}"; shift; if [[ "${TERMUX_API__LOG_LEVEL:-1}" -ge "$log_level" ]]; then echo "${TERMUX_API__SCRIPT_NAME:-termux-api}:" "$@"; fi } +termux_api__log_literal() { local log_level="${1:-}"; shift; if [[ "${TERMUX_API__LOG_LEVEL:-1}" -ge "$log_level" ]]; then echo -e "${TERMUX_API__SCRIPT_NAME:-termux-api}:" "$@"; fi } +termux_api__log_error() { echo "${TERMUX_API__SCRIPT_NAME:-termux-api}:" "$@" 1>&2; } + + + +## +# `termux_api__sms_list__main` [``] +## +termux_api__sms_list__main() { + + local return_value + + termux_api__sms_list__init || return $? + + # Process the command arguments passed to the script. + termux_api__sms_list__process_script_arguments "$@" || return $? + if [ "$TERMUX_API__COMMAND_TYPE_NOOP" = "true" ]; then return 0; fi + + + termux_api__log 2 "Running command" + + + local messasge_type_column + case "$TERMUX_API__MESSASGE_TYPE_NAME" in + all) messasge_type_column=0 ;; + inbox) messasge_type_column=1 ;; + sent) messasge_type_column=2 ;; + draft) messasge_type_column=3 ;; + outbox) messasge_type_column=4 ;; + failed) messasge_type_column=5 ;; + queued) messasge_type_column=6 ;; + *) + termux_api__log_error "Unsupported message type '$TERMUX_API__MESSASGE_TYPE_NAME'. It must one of following: $TERMUX_API__MESSASGE_TYPE_NAME___SUPPORTED_VALUES" + return 1 + ;; esac -done -shift $((OPTIND-1)) - -if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi - -case "$PARAM_TYPE" in - all) PARAM_TYPE=0 ;; - inbox) PARAM_TYPE=1 ;; - sent) PARAM_TYPE=2 ;; - draft) PARAM_TYPE=3 ;; - outbox) PARAM_TYPE=4 ;; - *) echo "$SCRIPTNAME: Unsupported type '$PARAM_TYPE'. Use one of: $SUPPORTED_TYPES"; exit 1 ;; -esac - -PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT --ei type $PARAM_TYPE $PARAM_NUMBER" -@TERMUX_PREFIX@/libexec/termux-api SmsInbox $PARAMS + + + if [[ -n "$TERMUX_API__CONVERSATION_LIST" ]]; then + TERMUX_API__API_ARGS+=(--ez "conversation-list" "$TERMUX_API__CONVERSATION_LIST") + + if [[ "$TERMUX_API__CONVERSATION_LIST" == "true" ]]; then + if [[ -n "$TERMUX_API__CONVERSATION_LIMIT" ]]; then + TERMUX_API__API_ARGS+=(--ei "conversation-limit" "$TERMUX_API__CONVERSATION_LIMIT") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_OFFSET" ]]; then + TERMUX_API__API_ARGS+=(--ei "conversation-offset" "$TERMUX_API__CONVERSATION_OFFSET") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_SELECTION" ]]; then + TERMUX_API__API_ARGS+=(--es "conversation-selection" "$TERMUX_API__CONVERSATION_SELECTION") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_SORT_ORDER" ]]; then + TERMUX_API__API_ARGS+=(--es "conversation-sort-order" "$TERMUX_API__CONVERSATION_SORT_ORDER") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_RETURN_MULTIPLE_MESSAGES" ]]; then + TERMUX_API__API_ARGS+=(--ez "conversation-return-multiple-messages" "$TERMUX_API__CONVERSATION_RETURN_MULTIPLE_MESSAGES") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_RETURN_NESTED_VIEW" ]]; then + TERMUX_API__API_ARGS+=(--ez "conversation-return-nested-view" "$TERMUX_API__CONVERSATION_RETURN_NESTED_VIEW") + fi + + if [[ -n "$TERMUX_API__CONVERSATION_SORT_ORDER" ]]; then + TERMUX_API__API_ARGS+=(--ez "conversation-return-no-order-reverse" "$TERMUX_API__CONVERSATION_RETURN_NO_ORDER_REVERSE") + fi + fi + fi + + + TERMUX_API__API_ARGS+=( + --ei "limit" "$TERMUX_API__MESSASGE_LIMIT" + --ei "offset" "$TERMUX_API__MESSASGE_OFFSET" + --ei "type" "$messasge_type_column" + ) + + if [[ -n "$TERMUX_API__MESSASGE_SELECTION" ]]; then + TERMUX_API__API_ARGS+=(--es "message-selection" "$TERMUX_API__MESSASGE_SELECTION") + fi + + if [[ -n "$TERMUX_API__MESSASGE_ADDRESS" ]]; then + TERMUX_API__API_ARGS+=(--es "from" "$TERMUX_API__MESSASGE_ADDRESS") + fi + + if [[ -n "$TERMUX_API__MESSAGE_SORT_ORDER" ]]; then + TERMUX_API__API_ARGS+=(--es "message-sort-order" "$TERMUX_API__MESSAGE_SORT_ORDER") + fi + + if [[ -n "$TERMUX_API__MESSAGE_RETURN_NO_ORDER_REVERSE" ]]; then + TERMUX_API__API_ARGS+=(--ez "message-return-no-order-reverse" "$TERMUX_API__MESSAGE_RETURN_NO_ORDER_REVERSE") + fi + + # Backward compatibility. + if [[ -n "$TERMUX_API__MESSAGE_SHOW_DATES" ]]; then + TERMUX_API__API_ARGS+=(--ez "show-dates" "$TERMUX_API__MESSAGE_SHOW_DATES") + fi + + # Backward compatibility. + if [[ -n "$TERMUX_API__MESSAGE_SHOW_PHONE_NUMBERS" ]]; then + TERMUX_API__API_ARGS+=(--ez "show-phone-numbers" "$TERMUX_API__MESSAGE_SHOW_PHONE_NUMBERS") + fi + + + if [[ $TERMUX_API__LOG_LEVEL -ge 2 ]]; then + local api_args_string="termux-api $TERMUX_API__API_CONTROLLER" + local i=1 + for ((i = 0; i < ${#TERMUX_API__API_ARGS[@]}; i++)); do + api_args_string="$api_args_string \`${TERMUX_API__API_ARGS[$i]}\`" + done + termux_api__log 2 "$api_args_string" + fi + + + return_value=0 + "$TERMUX__PREFIX/libexec/termux-api" "$TERMUX_API__API_CONTROLLER" "${TERMUX_API__API_ARGS[@]}" || return_value=$? + if [ $return_value -ne 0 ]; then + termux_api__log_error "Command failed with exit code $return_value" + else + termux_api__log 2 "Command successful" + fi + return $return_value + +} + +## +# `termux_api__sms_list__process_script_arguments` [``] +## +termux_api__sms_list__process_script_arguments() { + + local opt; local opt_arg; local OPTARG; local OPTIND + + # Parse options to main command. + while getopts ":hqvcdf:l:no:t:-:" opt; do + opt_arg="${OPTARG:-}" + case "${opt}" in + -) + case "${OPTARG}" in *?=*) opt_arg="${OPTARG#*=}";; *) opt_arg="";; esac + case "${OPTARG}" in + help) + TERMUX_API__COMMAND_TYPE_NOOP="true" + termux_api__sms_list__show_help; return $? + ;; + # FIXME: + #version) + # TERMUX_API__COMMAND_TYPE_NOOP="true" + # echo "@TERMUX_API_PKG__VERSION@"; return $? + # ;; + # [ --version ] Display version. + quiet) + TERMUX_API__LOG_LEVEL=0 + ;; + conversation-list) + TERMUX_API__CONVERSATION_LIST="true" + ;; + conversation-limit=?*) + TERMUX_API__CONVERSATION_LIMIT="$opt_arg" + ;; + conversation-limit | conversation-limit=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + conversation-offset=?*) + TERMUX_API__CONVERSATION_OFFSET="$opt_arg" + ;; + conversation-offset | conversation-offset=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + conversation-return-multiple-messages) + TERMUX_API__CONVERSATION_RETURN_MULTIPLE_MESSAGES="true" + ;; + conversation-return-nested-view) + TERMUX_API__CONVERSATION_RETURN_NESTED_VIEW="true" + ;; + conversation-return-no-order-reverse) + TERMUX_API__CONVERSATION_RETURN_NO_ORDER_REVERSE="true" + ;; + conversation-selection=?*) + TERMUX_API__CONVERSATION_SELECTION="$opt_arg" + ;; + conversation-selection | conversation-selection=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + conversation-sort-order=?*) + TERMUX_API__CONVERSATION_SORT_ORDER="$opt_arg" + ;; + conversation-sort-order | conversation-sort-order=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-address=?*) + TERMUX_API__MESSASGE_ADDRESS="$opt_arg" + ;; + message-address | message-address=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-limit=?*) + TERMUX_API__MESSASGE_LIMIT="$opt_arg" + ;; + message-limit | message-limit=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-offset=?*) + TERMUX_API__MESSASGE_OFFSET="$opt_arg" + ;; + message-offset | message-offset=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-return-no-order-reverse) + TERMUX_API__MESSAGE_RETURN_NO_ORDER_REVERSE="true" + ;; + message-selection=?*) + TERMUX_API__MESSASGE_SELECTION="$opt_arg" + ;; + message-selection | message-selection=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-sort-order=?*) + TERMUX_API__MESSAGE_SORT_ORDER="$opt_arg" + ;; + message-sort-order | message-sort-order=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + message-type=?*) + TERMUX_API__MESSASGE_TYPE_NAME="$opt_arg" + ;; + message-type | message-type=) + termux_api__log_error "No argument set for arg option '--${OPTARG%=*}'." + return 64 # EX__USAGE + ;; + '') + # End of options `--`. + break + ;; + *) + termux_api__log_error "Unknown option: '--${OPTARG:-}'." + termux_api__sms_list__exit_on_args_error || return $? + + ;; + esac + ;; + h) + TERMUX_API__COMMAND_TYPE_NOOP="true" + termux_api__sms_list__show_help; return $? + ;; + q) + TERMUX_API__LOG_LEVEL=0 + ;; + v) + if [ "$TERMUX_API__LOG_LEVEL" -lt "$TERMUX_API__MAX_LOG_LEVEL" ]; then + TERMUX_API__LOG_LEVEL=$((TERMUX_API__LOG_LEVEL+1)); + else + termux_api__log_error "Invalid option, max log level is $TERMUX_API__MAX_LOG_LEVEL." + return 64 # EX__USAGE + fi + ;; + c) + TERMUX_API__CONVERSATION_LIST="true" + ;; + d) + TERMUX_API__MESSAGE_SHOW_DATES="true" + ;; + f) + TERMUX_API__MESSASGE_ADDRESS="$opt_arg" + ;; + l) + TERMUX_API__MESSASGE_LIMIT="$opt_arg" + ;; + n) + TERMUX_API__MESSAGE_SHOW_PHONE_NUMBERS="true" + ;; + o) + TERMUX_API__MESSASGE_OFFSET="$opt_arg" + ;; + t) + TERMUX_API__MESSASGE_TYPE_NAME="$opt_arg" + ;; + :) + termux_api__log_error "No argument passed for arg option '-$OPTARG'." + termux_api__sms_list__exit_on_args_error || return $? + ;; + \?) + termux_api__log_error "Unknown option${OPTARG:+": '-${OPTARG:-}'"}." + termux_api__sms_list__exit_on_args_error || return $? + ;; + esac + done + shift $((OPTIND - 1)) # Remove already processed arguments from argument list + + # If a non-option argument is given to main command. + if [ $# -ne 0 ]; then + logger__log_error "Unknown argument(s) to command: $*" + return 64 # EX__USAGE + fi + + return 0; + +} + +## +# `termux_api__sms_list__exit_on_args_error` +## +termux_api__sms_list__exit_on_args_error() { + + termux_api__sms_list__show_help || return $? + + return 64 # EX__USAGE + +} + +## +# `termux_api__sms_list__show_help` +## +termux_api__sms_list__show_help() { + +# FIXME: CMake `configure_file` `@ONLY` will replace `@VAR@` style +# placeholders, so use `!VAR!` until we shift to make. + + cat <<'HELP_EOF' | \ + sed \ + -e "s%[!]TERMUX_API__SCRIPT_NAME[!]%${TERMUX_API__SCRIPT_NAME}%g" \ + -e "s%[!]TERMUX_API__MESSASGE_LIMIT___DEFAULT_VALUE[!]%${TERMUX_API__MESSASGE_LIMIT___DEFAULT_VALUE}%g" \ + -e "s%[!]TERMUX_API__MESSASGE_OFFSET___DEFAULT_VALUE[!]%${TERMUX_API__MESSASGE_OFFSET___DEFAULT_VALUE}%g" \ + -e "s%[!]TERMUX_API__MESSASGE_TYPE_NAME___DEFAULT_VALUE[!]%${TERMUX_API__MESSASGE_TYPE_NAME___DEFAULT_VALUE}%g" \ + -e "s%[!]TERMUX_API__MESSASGE_TYPE_NAME___SUPPORTED_VALUES[!]%${TERMUX_API__MESSASGE_TYPE_NAME___SUPPORTED_VALUES}%g" +!TERMUX_API__SCRIPT_NAME! command lists SMS conversations and messages. + +Usage: + !TERMUX_API__SCRIPT_NAME! [command_options] + +Available command_options: + [ -h | --help ] Display this help screen. +# [ --version ] Display version. + [ -q | --quiet ] Set log level to 'OFF'. + [ -v | -vv | -vvv | -vvvvv ] + Set log level to 'DEBUG', 'VERBOSE', + 'VVERBOSE' and 'VVVERBOSE'. + [ -c | --conversation-list ] + Show SMS conversations list instead of + messages list. + By default only one SMS message per + conversation is returned unless the + '--conversation-return-multiple-messages' + option is passed. + By default all SMS messages are returned + as a single array without nesting + unless the + '--conversation-return-nested-view' + option is passed. + [ --conversation-limit= ] + The SQL limit for returned SMS + conversations. + [ --conversation-offset= ] + The SQL offset for returned SMS + conversations. + [ --conversation-return-multiple-messages ] + Return multiple SMS messages per + conversation. + [ --conversation-return-nested-view ] + Return a nested object view of + conversations where each conversation + contains an array of SMS messages with + the conversation id as the key. + [ --conversation-return-no-order-reverse ] + Return SMS conversations without + reversing order of conversation sort. + [ --conversation-selection= ] + The SQL selection for returned SMS + conversations. + [ --conversation-sort-order= ] + The SMS conversations sort order as per + SQL 'ORDER BY col1, col2, ... ASC|DESC' + clause. + Default value: 'date DESC'. + [ -f address | --message-address=
] + The address or phone number of the + sender to return SMS messages for. + The '--conversation-selection' option + will override this if passed. + [ -l limit | --message-limit= ] + The limit for returned SMS messages. + Default value: '!TERMUX_API__MESSASGE_LIMIT___DEFAULT_VALUE!'. + [ -o offset | --message-offset= ] + The offset for returned SMS messages. + Default value: '!TERMUX_API__MESSASGE_OFFSET___DEFAULT_VALUE!'. + [ --message-return-no-order-reverse ] + Return SMS messages without reversing + order of message sort. + [ --message-selection= ] + The SQL selection for returned SMS + messages. + [ --message-sort-order= ] + The SMS messages sort order as per + SQL 'ORDER BY col1, col2, ... ASC|DESC' + clause. + Default value: 'date DESC'. + [ -t type | --message-type= ] + The type of returned SMS messages. + Default value: '!TERMUX_API__MESSASGE_TYPE_NAME___DEFAULT_VALUE!'. + Supported values: '!TERMUX_API__MESSASGE_TYPE_NAME___SUPPORTED_VALUES!'. + + + +# Sort and Print Order + +When conversation or messages are queried from the Android database, +first the sort order is applied, and then any offset and limit values +are used to filter the entries. Since the default sort order is +'date DESC', Android returns the latest dated conversations or +messages first, but the API reverses the order by default so that +the latest entries are printed at the end. If the order should not be +reversed, then pass the respective `--*-return-no-order-reverse` +options. + + + +# Message Type + +The following numbers can be used to match a message 'type' with +the '--message-selection' option. +- all: 0 +- inbox: 1 +- sent: 2 +- draft: 3 +- outbox: 4 +- failed: 5 +- queued: 6 + + + +### Examples + +# Get lastest 10 messages with latest dated message printed at end. +!TERMUX_API__SCRIPT_NAME! + +# Get lastest 10 messages with latest dated message printed at start. +!TERMUX_API__SCRIPT_NAME! --message-return-no-order-reverse + +# Get latest message of any type. +!TERMUX_API__SCRIPT_NAME! --message-limit=1 + +# Get latest inbox message. +!TERMUX_API__SCRIPT_NAME! --message-selection="type == 1" \ + --message-limit=1 + +# Get latest sent message. +!TERMUX_API__SCRIPT_NAME! --message-selection="type == 2" \ + --message-limit=1 + +# Get oldest 10 messages with latest dated message printed at end. +!TERMUX_API__SCRIPT_NAME! --message-sort-order="date ASC" \ + --message-return-no-order-reverse + +# Get the latest inbox message received from the address '666' that +# starts with the text 'Foo '. +!TERMUX_API__SCRIPT_NAME! \ + --message-selection="type == 1 and address == '666' and body LIKE 'Foo %'" \ + --message-limit=1 + +# Get the latest sent message sent to the address '666' that +# starts with the text 'Bar '. +!TERMUX_API__SCRIPT_NAME! \ + --message-selection="type == 2 and address == '666' and body LIKE 'Bar %'" \ + --message-limit=1 + + +# Get list view for conversations with default conversation limit and +# 1 message per conversastion. +!TERMUX_API__SCRIPT_NAME! --conversation-list + +# Get list view for conversations with default conversation limit and +# 10 messages per conversation. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages + + +# Get nested view for conversations with default conversation and +# message limits. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages \ + --conversation-return-nested-view + +# Get nested view for latest conversation with latest 5 messages. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages \ + --conversation-return-nested-view \ + --conversation-limit=1 \ + --message-limit=5 + +# Get nested view for conversations sorted on thread id with highest +# conversation id printed at end. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages \ + --conversation-return-nested-view \ + --conversation-sort-order="thread_id ASC" \ + --conversation-return-no-order-reverse + +# Get nested view for conversations for conversation with address +# equal to '666'. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages \ + --conversation-return-nested-view \ + --conversation-selection="address == '666'" + +# Get nested view for conversations for conversation with thread id +# equal to '6'. +!TERMUX_API__SCRIPT_NAME! --conversation-list \ + --conversation-return-multiple-messages \ + --conversation-return-nested-view \ + --conversation-selection="thread_id == 6" + + + + **See Also:** + - https://developer.android.com/reference/android/provider/Telephony + - https://developer.android.com/reference/android/provider/Telephony.Sms.Conversations + - https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns + - https://developer.android.com/reference/android/provider/BaseColumns +HELP_EOF + +} + +# If script is sourced, return with success, otherwise call main function. +# - https://stackoverflow.com/a/28776166/14686958 +# - https://stackoverflow.com/a/29835459/14686958 +if (return 0 2>/dev/null); then + return 0 # EX__SUCCESS +else + termux_api__sms_list__main "$@" + exit $? +fi From 2b7fe084e3fecff885f03cdf21492a95f9273ac3 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 15 Mar 2025 11:58:45 +0500 Subject: [PATCH 60/68] Added(termux-microphone-record): Add opus audio encoder to help Related pull https://github.com/termux/termux-api/pull/747 --- scripts/termux-microphone-record.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-microphone-record.in b/scripts/termux-microphone-record.in index 4b13c89..2cb7b39 100644 --- a/scripts/termux-microphone-record.in +++ b/scripts/termux-microphone-record.in @@ -11,7 +11,7 @@ show_usage () { echo "-d Start recording w/ defaults" echo "-f Start recording to specific file" echo "-l Start recording w/ specified limit (in seconds, unlimited for 0)" - echo "-e Start recording w/ specified encoder (aac, amr_wb, amr_nb)" + echo "-e Start recording w/ specified encoder (aac, amr_wb, amr_nb, opus)" echo "-b Start recording w/ specified bitrate (in kbps)" echo "-r Start recording w/ specified sampling rate (in Hz)" echo "-c Start recording w/ specified channel count (1, 2, ...)" From b807c046118acf3639af7654e0514bc5827c8287 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Mon, 17 Mar 2025 02:42:25 +0500 Subject: [PATCH 61/68] Changed(termux-usb): Update error handling as per new messages in termux/termux-api@15d5fb62 --- scripts/termux-usb.in | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/scripts/termux-usb.in b/scripts/termux-usb.in index f68f838..4c77ba2 100644 --- a/scripts/termux-usb.in +++ b/scripts/termux-usb.in @@ -53,17 +53,26 @@ fi CMD="@TERMUX_PREFIX@/libexec/termux-api Usb -a $ACTION $PARAMS" -if [ "$ACTION" == "permission" ] -then - if [ "$($CMD)" == "yes" ] - then - echo "Access granted." - exit 0 - else - echo "Access denied." - exit 1 - fi -else +if [[ "$ACTION" == "list" ]]; then $CMD +elif [[ "$ACTION" == "permission" ]]; then + OUTPUT="$($CMD)" + case "$OUTPUT" in + "No such device"|"No such device.") echo "No such device."; exit 1;; + "yes") echo "Permission granted."; exit 0;; + "no"|"Permission denied.") echo "Permission denied."; exit 1;; + "Permission request timeout.") echo "Permission request timeout."; exit 1;; + *) printf "%s\n" "$OUTPUT"; exit 0;; + esac +elif [[ "$ACTION" == "open" ]]; then + OUTPUT="$($CMD)" + case "$OUTPUT" in + "No such device"|"No such device.") echo "No such device."; exit 1;; + "No permission"|"Permission denied.") echo "Permission denied."; exit 1;; + "Permission request timeout.") echo "Permission request timeout."; exit 1;; + "Failed to open device"|"Open device failed.") echo "Open device failed."; exit 1;; + *) printf "%s\n" "$OUTPUT"; exit 0;; + esac fi +exit 0 From 22d6c109c1825a1e33626713444181e009d1f38a Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Mon, 17 Mar 2025 02:44:24 +0500 Subject: [PATCH 62/68] Release: 0.59.0 --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 68dd822..3cfda8b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -22,7 +22,7 @@ #include "termux-api.h" -#define TERMUX_API_PACKAGE_VERSION "0.58.0" +#define TERMUX_API_PACKAGE_VERSION "0.59.0" #ifndef PREFIX # define PREFIX "/data/data/com.termux/files/usr" From a0e1c71a7c117ad021f30b3bd66c320e13246667 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Mon, 17 Mar 2025 07:13:54 +0100 Subject: [PATCH 63/68] Include arpa/inet.h instead of sys/endian.h The header is included to get defintion for htons. In termux the definition is in sys/endian.h, but on other systems it is in arpa/inet.h. arpa/inet.h includes sys/endian.h though, so including that header works in termux as well. Change to arpa/inet.h so that termux-api-package can be easily compiled both in termux and for other systems. --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index 3cfda8b..ddc157b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include From 530f292a8e77e6dc2255b42fbe48f1ced319a485 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Wed, 26 Mar 2025 16:49:19 +0100 Subject: [PATCH 64/68] termux-api: free malloc'ed child_argv array on execv error We exit right after so this is not exactly strictly necessary, but that might change at some point and is good practise in any case. --- termux-api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/termux-api.c b/termux-api.c index ddc157b..30b848b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -275,6 +275,8 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, // Use an a executable taking care of PATH and LD_LIBRARY_PATH: execv(PREFIX "/bin/am", child_argv); + // We should not reach here, if we do, then free memory we malloc'ed + free(child_argv); perror("execv(\"" PREFIX "/bin/am\")"); exit(1); } From 512a252ba6220d5a6c9af4b96cb4e5153740c8aa Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Wed, 26 Mar 2025 16:51:36 +0100 Subject: [PATCH 65/68] termux-api: handle malloc errors malloc might fail to allocate memory for child_argv. Ensure it was successfully allocated before trying to set its elements. --- termux-api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/termux-api.c b/termux-api.c index 30b848b..5c86329 100644 --- a/termux-api.c +++ b/termux-api.c @@ -248,6 +248,10 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, int const extra_args = 15; // Including ending NULL. char** child_argv = malloc((sizeof(char*)) * (argc + extra_args)); + if (child_argv == NULL) { + perror("malloc failed for am child args"); + exit(1); + } child_argv[0] = "am"; child_argv[1] = "broadcast"; From 0edd4d450710e399c1e3e4f44558eecc0f78a068 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Wed, 26 Mar 2025 16:58:54 +0100 Subject: [PATCH 66/68] Fixed: only malloc as many bytes as are actully needed And make malloc&memcpy handling clearer. Before we potentially had an element with uninitialised memory, see discussion in termux/termux-api-package#203. Fixes: 1ec1334b54e0 ("Initial push") --- termux-api.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/termux-api.c b/termux-api.c index 5c86329..bee5433 100644 --- a/termux-api.c +++ b/termux-api.c @@ -246,13 +246,20 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, // Close stdin: close(STDIN_FILENO); - int const extra_args = 15; // Including ending NULL. - char** child_argv = malloc((sizeof(char*)) * (argc + extra_args)); - if (child_argv == NULL) { + const int child_pre_argc = 14; + const int child_post_argc = argc - 1; // Except `argv[0]`. + const int child_argc = child_pre_argc + child_post_argc; + + size_t child_argv_size = (sizeof(char*)) * (child_argc + 1); // Including trailing `NULL`. + // Do not directly cast, otherwise can trigger null pointer dereference if `NULL` is returned. + void* result = malloc(child_argv_size); + if (result == NULL) { perror("malloc failed for am child args"); exit(1); } + char **child_argv = (char **) result; + child_argv[0] = "am"; child_argv[1] = "broadcast"; child_argv[2] = "--user"; @@ -268,13 +275,12 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, child_argv[11] = input_address_string; child_argv[12] = "--es"; child_argv[13] = "api_method"; - child_argv[14] = argv[1]; - // Copy the remaining arguments -2 for first binary and second api name: - memcpy(child_argv + extra_args, argv + 2, (argc-1) * sizeof(char*)); + // Copy the remaining arguments except `argv[0]`, `argv[1]` should be `api_method` extra value: + memcpy(child_argv + child_pre_argc, argv + 1, child_post_argc * sizeof(char*)); // End with NULL: - child_argv[argc + extra_args - 1] = NULL; + child_argv[child_argc] = NULL; // Use an a executable taking care of PATH and LD_LIBRARY_PATH: execv(PREFIX "/bin/am", child_argv); From 319a7a58b104298e32ea8ae31b9282396a9a4fe4 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 29 Mar 2025 22:04:28 +0100 Subject: [PATCH 67/68] Changed: bump to 0.59.1 --- termux-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/termux-api.c b/termux-api.c index bee5433..74b669b 100644 --- a/termux-api.c +++ b/termux-api.c @@ -22,7 +22,7 @@ #include "termux-api.h" -#define TERMUX_API_PACKAGE_VERSION "0.59.0" +#define TERMUX_API_PACKAGE_VERSION "0.59.1" #ifndef PREFIX # define PREFIX "/data/data/com.termux/files/usr" From 0e3f9222eea7760c76ea6368dadbdf884ab85fbf Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Thu, 26 Jun 2025 04:38:34 +0500 Subject: [PATCH 68/68] Added: Add `SECURITY.md` --- SECURITY.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..479f15c --- /dev/null +++ b/SECURITY.md @@ -0,0 +1 @@ +Check https://termux.dev/security for info on Termux security policies and how to report vulnerabilities.