这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 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
#!/data/data/com.termux/files/usr/bin/sh
set -e -u

SCRIPTNAME=termux-brightness
Expand All @@ -12,7 +12,13 @@ if [ $# != 1 ]; then
show_usage
fi

if ! [[ $1 =~ ^[0-9]+$ ]]; then
case "$1" in
("" | *[!0-9]*)
echo "ERROR: Arg must be a number between 0 - 255!"
show_usage
esac

if [ "$1" -lt 0 ] || [ "$1" -gt 255 ]; then
echo "ERROR: Arg must be a number between 0 - 255!"
show_usage
fi
Expand Down
2 changes: 1 addition & 1 deletion 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
#!/data/data/com.termux/files/usr/bin/sh
set -u

PARAM_LIMIT=10
Expand Down
31 changes: 18 additions & 13 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
#!/data/data/com.termux/files/usr/bin/sh
set -e -u

DEFAULT_WIDGET="text"
Expand All @@ -13,7 +13,7 @@ show_usage() {
exit 0
}

declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinner" "speech" "text" "time")
widgets="confirm checkbox counter date radio sheet spinner speech text time"

# Descriptions for various options that multiple widgets can use
OPT_HINT_DESC="[-i hint] text hint (optional)"
Expand Down Expand Up @@ -74,7 +74,7 @@ FLAGS=0

# Show usage help for specific widget
widget_usage () {
echo -n -e "$1 - "
printf "%s - " "$1"

case "$1" in
"confirm")
Expand Down Expand Up @@ -141,16 +141,16 @@ list_widgets() {
echo "Supported widgets:"
echo

for w in "${widgets[@]}"; do
for w in ${widgets}; do
widget_usage $w
echo
done
}

# Checks to see if widgets array contains specified widget
has_widget () {
for w in "${widgets[@]}"; do
[ "$w" == "$1" ] && return 0
for w in ${widgets}; do
[ "$w" = "$1" ] && return 0
done
return 1
}
Expand Down Expand Up @@ -181,7 +181,8 @@ parse_options() {
}

options_error () {
echo -e "ERROR: Invalid option(s) detected for '$1'\n"
echo "ERROR: Invalid option(s) detected for '$1'"
echo
echo "Usage '$1'"
widget_usage $1
exit 1
Expand All @@ -193,11 +194,15 @@ if [ $# -eq 0 ]; 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
echo -e "ERROR: Illegal argument $1\n"
show_usage
fi
WIDGET="$DEFAULT_WIDGET"
case "$1" in
-[a-z])
WIDGET="$DEFAULT_WIDGET"
;;
*)
echo "ERROR: Illegal argument $1"
echo
show_usage
esac
else
WIDGET="$1"
shift
Expand Down Expand Up @@ -244,7 +249,7 @@ case "$WIDGET" in
;;

"checkbox" | "radio" | "sheet" | "spinner")
if [ "$ARG_V" == "" ]; then
if [ "$ARG_V" = "" ]; then
echo "ERROR: '$WIDGET' must be called with $OPT_VALUES_DESC"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion 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
#!/data/data/com.termux/files/usr/bin/sh
set -e

SCRIPTNAME=termux-media-player
Expand Down
15 changes: 7 additions & 8 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
#!/data/data/com.termux/files/usr/bin/sh
set -e -u

SCRIPTNAME=termux-media-scan
Expand All @@ -12,14 +12,13 @@ show_usage () {

get_paths() {
for ARG in "$@"; do
if [[ -e "$ARG" ]]; then
if [ -e "$ARG" ]; then
realpath "$ARG"
else
if [[ "$ARG" =~ ^/ ]]; then
echo "$ARG"
else
echo "`pwd`/$ARG"
fi
else
case "$ARG" in
/*) echo "$ARG";;
*) echo "`pwd`/$ARG"
esac
fi
done
}
Expand Down
46 changes: 23 additions & 23 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
#!/data/data/com.termux/files/usr/bin/sh
set -e

SCRIPTNAME=termux-microphone-record
Expand All @@ -15,6 +15,11 @@ show_usage () {
echo "-q Quits recording"
}

ARG_F=""
OPT_F=""
ARG_L=""
OPT_L=""

usage_error () {
echo
show_usage
Expand All @@ -28,50 +33,45 @@ sole() {
fi
}

add_params() {
for i in "$@"; do
params[index++]="$i"
done
}

call_api () {
/data/data/com.termux/files/usr/libexec/termux-api MicRecorder "$@"
exit 0
}

while getopts h,f:,l:,d,i,q option
do
case "$option" in
h) sole "$@"
show_usage
exit 0
;;
f) record=yes
dir="$(dirname "$OPTARG")"
f) dir="$(dirname "$OPTARG")"
file="$(basename "$OPTARG")"
dir="$(realpath "$dir")"
add_params --es file "$dir/$file"
ARG_F="--es file"
OPT_F="$dir/$file"
;;
# API takes limit in milliseconds
l) record=yes
add_params --ei limit $((OPTARG * 1000))
l) ARG_L="--ei limit"
OPT_L=$((OPTARG * 1000))
;;
d) record=yes
d) sole "$@"
call_api -a record
;;
i) sole "$@"
add_params -a info
call_api -a info
;;
q) sole "$@"
add_params -a quit
call_api -a quit
;;
*) usage_error
;;
esac
done

if [ -v record ]; then
add_params -a record
fi
set --
if [ -n "$ARG_F" ]; then set -- "$@" $ARG_F "$OPT_F"; fi
if [ -n "$ARG_L" ]; then set -- "$@" $ARG_L "$OPT_L"; fi
set -- "$@" -a record

if [ -v params ]; then
call_api "${params[@]}"
else
show_usage
fi
call_api "$@"
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
#!/data/data/com.termux/files/usr/bin/sh
set -e -u -f

SCRIPTNAME=termux-notification
Expand Down Expand Up @@ -53,7 +53,7 @@ content:,help,id:,\
led-color:,led-on:,led-off:,\
on-delete:,\
priority:,sound,title:,vibrate: \
-s bash \
-s sh \
-- "$@"`
eval set -- "$TEMP"

Expand Down Expand Up @@ -101,7 +101,7 @@ if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi
if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi
if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi

if [ -v OPT_CONTENT ]; then
if [ ! -z ${OPT_CONTENT+x} ]; then
# Note that we want to accept an empty content (--content "").
echo ${OPT_CONTENT:=""} | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
else
Expand Down
79 changes: 46 additions & 33 deletions scripts/termux-sensor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/data/data/com.termux/files/usr/bin/bash
set -e -u
#!/data/data/com.termux/files/usr/bin/sh
set -e

SCRIPTNAME=termux-sensor
show_usage () {
Expand All @@ -16,29 +16,30 @@ show_usage () {
}

# ensure we properly release resources if needed on ^C
trap handle_interrupt SIGTERM SIGINT
trap handle_interrupt TERM INT

if [ $# -eq 0 ]; then
echo "No arguments supplied!"
show_usage
exit 1;
fi

SENSOR_FLAG=1
ALL_SENSORS_FLAG=2
LIST_FLAG=4
CLEANUP_FLAG=8
DELAY_FLAG=16
LIMIT_FLAG=32
FLAGS=0
ARG_A=""
OPT_A=""
ARG_S=""
OPT_S=""
ARG_D=""
OPT_D=""
ARG_N=""
OPT_N=""

handle_interrupt () {
echo "Caught interrupt.. Finishing..."
cleanup
}

cleanup () {
if [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) != 0 ]; then
if [ -n "$ARG_A" ] || [ -n "$ARG_S" ]; then
echo "Performing sensor cleanup"
call_api -a cleanup
else
Expand All @@ -52,28 +53,32 @@ get_sensors () {
fi
}

is_number () {
case "$1" in
("" | *[!0-9]*)
return 1
esac
}

get_delay () {
if [ $# -gt 1 ]; then
usage_error "Too many arguments for -d delay"
elif ! [[ $1 =~ ^[0-9]+$ ]]; then
elif ! is_number "$1"; then
usage_error "Illegal argument! -d delay arg should be a number!"
fi
}

get_limit () {
if [ $# -gt 1 ]; then
usage_error "Too many arguments for -n limit"
elif ! [[ $1 =~ ^[0-9]+$ ]]; then
elif ! is_number "$1"; then
usage_error "Illegal argument! -n limit arg should be a number!"
fi
}

call_api () {
/data/data/com.termux/files/usr/libexec/termux-api Sensor "$@"
}

set_flag () {
FLAGS=$((FLAGS | $1));
exit 0
}

usage_error () {
Expand All @@ -82,33 +87,41 @@ usage_error () {
exit 1
}

sole() {
if [ "$1 $2" != "-$option $OPTARG" ] || [ $# -gt 2 ]; then
echo "ERROR: No other options should be specified with -$option!"
usage_error
fi
}


PARAMS=()
while getopts :h,a,c,l,s:d:n: option
do
case "$option" in
h) show_usage ;;
a) set_flag $ALL_SENSORS_FLAG; PARAMS+=(-a sensors --ez all true);;
c) set_flag $CLEANUP_FLAG; PARAMS=(-a cleanup) ;;
l) set_flag $LIST_FLAG; PARAMS=(-a list) ;;
s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=(-a sensors --es sensors "$OPTARG") ;;
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=(--ei delay $OPTARG) ;;
n) set_flag $LIMIT_FLAG; get_limit $OPTARG; PARAMS+=(--ei limit $OPTARG) ;;
a) ARG_A="--ez all"; OPT_A="true" ;;
c) sole "$@"; call_api -a cleanup ;;
l) sole "$@"; call_api -a list ;;
s) get_sensors "$OPTARG"; ARG_S="--es sensors"; OPT_S="$OPTARG" ;;
d) get_delay $OPTARG; ARG_D="--ei delay"; OPT_D="$OPTARG" ;;
n) get_limit $OPTARG; ARG_N="--ei limit"; OPT_N="$OPTARG" ;;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $((OPTIND -1))

# Validate options were set properly

if [ $((FLAGS & CLEANUP_FLAG)) -ne 0 ] && [ $FLAGS -ne $CLEANUP_FLAG ]; then
usage_error "No other options should be specified with -c cleanup!"
elif [ $((FLAGS & LIST_FLAG)) -ne 0 ] && [ $FLAGS -ne $LIST_FLAG ]; then
usage_error "No other options should be specified with -l list!"
elif [ $((FLAGS & DELAY_FLAG)) -ne 0 ] && [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) -eq 0 ]; then
usage_error "Use -s <sensors> or -a option when using -d delay!"
elif [ $((FLAGS & ALL_SENSORS_FLAG)) -ne 0 ] && [ $((FLAGS & SENSOR_FLAG)) -ne 0 ]; then
if [ -n "$ARG_A" ] && [ -n "$ARG_S" ]; then
usage_error "Listed sensors will be ignored with -a all option!"
elif [ -n "$ARG_D" ] && ! ([ -n "$ARG_A" ] || [ -n "$ARG_S" ]); then
usage_error "Use -s <sensors> or -a option when using -d delay!"
fi

call_api "${PARAMS[@]}"
set --
if [ -n "$ARG_A" ]; then set -- "$@" $ARG_A "$OPT_A"; fi
if [ -n "$ARG_S" ]; then set -- "$@" $ARG_S "$OPT_S"; fi
if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
if [ -n "$ARG_N" ]; then set -- "$@" $ARG_N "$OPT_N"; fi
set -- "$@" -a sensors

call_api "$@"
Loading