Skip to content

Commit

Permalink
make it possible to easily change prefix in binary & scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonid Pliushch committed Oct 30, 2020
1 parent 1519179 commit e3c3811
Show file tree
Hide file tree
Showing 46 changed files with 99 additions and 96 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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

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
4 changes: 2 additions & 2 deletions scripts/termux-audio-info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-audio-info
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-battery-status
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-battery-status
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-brightness
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u

SCRIPTNAME=termux-brightness
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-call-log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -u

PARAM_LIMIT=10
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-camera-info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-camera-info
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-camera-photo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-camera-photo
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-clipboard-get
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-clipboard-get
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-clipboard-set
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-clipboard-set
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-contact-list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-contact-list
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-dialog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u

DEFAULT_WIDGET="text"
Expand Down Expand Up @@ -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 "$@"
4 changes: 2 additions & 2 deletions scripts/termux-download
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-download
Expand Down Expand Up @@ -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 "$@"
4 changes: 2 additions & 2 deletions scripts/termux-fingerprint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-fingerprint
Expand Down Expand Up @@ -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 "$@"
4 changes: 2 additions & 2 deletions scripts/termux-infrared-frequencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-infrared-frequencies
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-infrared-transmit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-infrared-transmit
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-job-scheduler
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u -f

SCRIPTNAME=termux-job-scheduler
Expand Down Expand Up @@ -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 "$@"
4 changes: 2 additions & 2 deletions scripts/termux-keystore
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-location
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-location
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-media-player
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e

SCRIPTNAME=termux-media-player
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-media-scan
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u

SCRIPTNAME=termux-media-scan
Expand Down Expand Up @@ -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"
4 changes: 2 additions & 2 deletions scripts/termux-microphone-record
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e

SCRIPTNAME=termux-microphone-record
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/termux-notification
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u -f

SCRIPTNAME=termux-notification
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-notification-list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-notification-list
Expand All @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-notification-remove
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-notification-remove
Expand All @@ -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"
4 changes: 2 additions & 2 deletions scripts/termux-sensor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!@TERMUX_PREFIX@/bin/bash
set -e -u

SCRIPTNAME=termux-sensor
Expand Down Expand Up @@ -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 () {
Expand Down
6 changes: 3 additions & 3 deletions scripts/termux-share
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-share
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/termux-sms-inbox
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions scripts/termux-sms-list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -u

PARAM_LIMIT=10
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/termux-sms-send
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-sms-send
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-speech-to-text
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-speech-to-text
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-storage-get
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
#!@TERMUX_PREFIX@/bin/sh
set -e -u

SCRIPTNAME=termux-storage-get
Expand All @@ -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")"
Loading

0 comments on commit e3c3811

Please sign in to comment.