WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9806c79

Browse files
robertkirkmanTomJo2000
authored andcommitted
tree-wide: code style and print message cleanup
- Continuation of #179, particularly these topics from there: - #179 (review) - #179 (comment) - Contains things that were proposed there, but that it was decided to separate out into another PR for organization and easier review - Replaces backtick command substitution syntax with dollar symbol and parentheses command substitution syntax in shell scripts - Places double quote symbols around all string (non-numerical) variable references that aren't possibly-empty references in the argument lists of command invocations - (placing double quote symbols around a possibly-empty variable in a command invocation is a case where the double quote symbols would cause an error to happen) - Places double quote symbols around all instances of `@TERMUX_PREFIX@` and other replaced strings in `.sh.in` files - Remove unused function `hostname()` from `pkg` - Remove unused variable `PREFIX` from `termux-restore` - Unify and clarify instances of `login`-related error message in `chsh`
1 parent 0685e59 commit 9806c79

File tree

9 files changed

+39
-49
lines changed

9 files changed

+39
-49
lines changed

scripts/chsh.in

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ show_usage() {
1111
echo "usage: chsh [-s shell]"
1212
echo "Change the login shell."
1313
echo
14-
if [ "${1:-}" = "login" ]; then
15-
echo "The shell value must be one of following and cannot be 'login':"
16-
else
17-
echo "The shell value must be one of following:"
18-
fi
14+
echo "The shell value must be one of following and cannot be 'login':"
1915
echo " - Empty value to restore default shell."
2016
echo " - Absolute path to shell starting with a '/'."
2117
echo " - Relative path to shell not starting with a '/' relative to '@TERMUX_PREFIX@/bin'."
@@ -28,10 +24,6 @@ set_shell() {
2824
exit 0
2925
fi
3026

31-
if [ "$1" = "login" ]; then
32-
show_usage "login"
33-
exit 1
34-
fi
3527
mkdir -p "$HOME/.termux"
3628

3729
unset NEW_SHELL
@@ -44,18 +36,22 @@ set_shell() {
4436

4537
if ! is_executable_file "$SHELL_TARGET"; then
4638
echo "The shell file '$SHELL_TARGET' is not an executable file." 1>&2
39+
echo
40+
show_usage
4741
exit 1
4842
fi
4943

5044
if [ "$SHELL_TARGET" -ef "@TERMUX_PREFIX@/bin/login" ]; then
5145
echo "The shell file '$SHELL_TARGET' must not point to the '@TERMUX_PREFIX@/bin/login' script." 1>&2
46+
echo
47+
show_usage
5248
exit 1
5349
fi
5450

5551
ln -sf "$SHELL_TARGET" "$HOME/.termux/shell"
5652
}
5753

58-
O=`getopt -l help -- hs: "$@"`
54+
O="$(getopt -l help -- hs: "$@")"
5955
eval set -- "$O"
6056
while true; do
6157
case "$1" in

scripts/dalvikvm.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/sh
22

33
# There needs to be a folder at $ANDROID_DATA/dalvik-cache
4-
export ANDROID_DATA=@TERMUX_PREFIX@/var/android/
5-
mkdir -p $ANDROID_DATA/dalvik-cache
4+
export ANDROID_DATA="@TERMUX_PREFIX@/var/android/"
5+
mkdir -p "$ANDROID_DATA/dalvik-cache"
66

77
if [ -x /apex/com.android.art/bin/dalvikvm ]; then
88
DALVIKVM="/apex/com.android.art/bin/dalvikvm"
@@ -11,4 +11,4 @@ else
1111
fi
1212

1313
unset LD_LIBRARY_PATH LD_PRELOAD
14-
exec "$DALVIKVM" -Xusejit:true -Xnoimage-dex2oat -Djava.io.tmpdir=@TERMUX_PREFIX@/tmp "$@"
14+
exec "$DALVIKVM" -Xusejit:true -Xnoimage-dex2oat -Djava.io.tmpdir="@TERMUX_PREFIX@/tmp" "$@"

scripts/login.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ if tty >/dev/null 2>&1 && [ $# = 0 ] && [ ! -f ~/.hushlogin ] && [ -z "$TERMUX_H
2020
[ ! -x ~/.termux/motd.sh ] && chmod u+x ~/.termux/motd.sh
2121
~/.termux/motd.sh
2222
# Default to termux-tools package provided static motd file if it exists
23-
elif [ -f @TERMUX_PREFIX@/etc/motd ]; then
24-
cat @TERMUX_PREFIX@/etc/motd
23+
elif [ -f "@TERMUX_PREFIX@/etc/motd" ]; then
24+
cat "@TERMUX_PREFIX@/etc/motd"
2525
fi
2626
else
2727
# This variable shouldn't be kept set.
2828
unset TERMUX_HUSHLOGIN
2929
fi
3030

3131
# TERMUX_VERSION env variable has been exported since v0.107 and PATH was being set to following value in <0.104. Last playstore version was v0.101.
32-
if tty >/dev/null 2>&1 && [ $# = 0 ] && [ -f @TERMUX_PREFIX@/etc/motd-playstore ] && [ -z "$TERMUX_VERSION" ] && [ "$PATH" = "@TERMUX_PREFIX@/bin:@TERMUX_PREFIX@/bin/applets" ]; then
33-
printf '\033[0;31m'; cat @TERMUX_PREFIX@/etc/motd-playstore; printf '\033[0m'
32+
if tty >/dev/null 2>&1 && [ $# = 0 ] && [ -f "@TERMUX_PREFIX@/etc/motd-playstore" ] && [ -z "$TERMUX_VERSION" ] && [ "$PATH" = "@TERMUX_PREFIX@/bin:@TERMUX_PREFIX@/bin/applets" ]; then
33+
printf '\033[0;31m'; cat "@TERMUX_PREFIX@/etc/motd-playstore"; printf '\033[0m'
3434
fi
3535

3636
unset SHELL
@@ -74,8 +74,8 @@ elif [ -f "@TERMUX_PREFIX@/lib/libtermux-exec.so" ]; then
7474
$SHELL -c "coreutils --coreutils-prog=true" > /dev/null 2>&1 || unset LD_PRELOAD
7575
fi
7676

77-
if [ -f @TERMUX_PREFIX@/etc/termux-login.sh ]; then
78-
. @TERMUX_PREFIX@/etc/termux-login.sh
77+
if [ -f "@TERMUX_PREFIX@/etc/termux-login.sh" ]; then
78+
. "@TERMUX_PREFIX@/etc/termux-login.sh"
7979
fi
8080

8181
if [ -n "$TERM" ]; then

scripts/pkg.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ show_help() {
2121
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
2222
cache_dir="@TERMUX_PREFIX@/var/cache/pacman/pkg"
2323
fi
24-
cache_size=$(du -sh "$cache_dir" 2>/dev/null | cut -f1)
24+
cache_size="$(du -sh "$cache_dir" 2>/dev/null | cut -f1)"
2525

2626
echo 'Usage: pkg [--check-mirror] command [arguments]'
2727
echo
@@ -96,10 +96,6 @@ check_command() {
9696
fi
9797
}
9898

99-
hostname() {
100-
echo "$1" | awk -F'[/:]' '{print $4}'
101-
}
102-
10399
last_modified() {
104100
local mtime
105101
local now

scripts/su.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ unset LD_LIBRARY_PATH LD_PRELOAD
44

55
for p in /debug_ramdisk/su /sbin/su /system/sbin/su /system/bin/su /system/xbin/su /su/bin/su /magisk/.core/bin/su
66
do
7-
if [ -x $p ]; then
7+
if [ -x "$p" ]; then
88
# The su tool may require programs in PATH:
99
PATH=/debug_ramdisk:/sbin:/sbin/su:/su/bin:/su/xbin:/system/bin:/system/xbin \
10-
exec $p "$@"
10+
exec "$p" "$@"
1111
fi
1212
done
1313

scripts/termux-backup.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
set -e -u
3333

34-
export PREFIX=@TERMUX_PREFIX@
34+
export PREFIX="@TERMUX_PREFIX@"
3535

3636
msg() {
3737
echo "$*" >&2

scripts/termux-change-repo.in

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ select_repository_group() {
3030
MIRRORS+=("Mirrors in Oceania" "All in Oceania")
3131
MIRRORS+=("Mirrors in Russia" "All in Russia")
3232

33-
local TEMPFILE="$(mktemp @TERMUX_PREFIX@/tmp/mirror.XXXXXX)"
33+
local TEMPFILE="$(mktemp "@TERMUX_PREFIX@/tmp/mirror.XXXXXX")"
3434
dialog \
3535
--title "termux-change-repo" --clear \
3636
--menu "Which group of mirrors do you want to use?" 0 0 0 \
@@ -55,31 +55,31 @@ select_repository_group() {
5555

5656
if [ "$mirror_group" == "Mirrors in Asia" ]; then
5757
echo "[*] Mirrors in Asia (excl. Chinese Mainland and Russia) selected"
58-
unlink_and_link ${MIRROR_BASE_DIR}/asia
58+
unlink_and_link "${MIRROR_BASE_DIR}/asia"
5959

6060
elif [ "$mirror_group" == "Mirrors in Chinese Mainland" ]; then
6161
echo "[*] Mirrors in Chinese Mainland selected"
62-
unlink_and_link ${MIRROR_BASE_DIR}/chinese_mainland
62+
unlink_and_link "${MIRROR_BASE_DIR}/chinese_mainland"
6363

6464
elif [ "$mirror_group" == "Mirrors in Europe" ]; then
6565
echo "[*] Mirrors in Europe selected"
66-
unlink_and_link ${MIRROR_BASE_DIR}/europe
66+
unlink_and_link "${MIRROR_BASE_DIR}/europe"
6767

6868
elif [ "$mirror_group" == "Mirrors in North America" ]; then
6969
echo "[*] Mirrors in North America selected"
70-
unlink_and_link ${MIRROR_BASE_DIR}/north_america
70+
unlink_and_link "${MIRROR_BASE_DIR}/north_america"
7171

7272
elif [ "$mirror_group" == "Mirrors in Oceania" ]; then
7373
echo "[*] Mirrors in Oceania selected"
74-
unlink_and_link ${MIRROR_BASE_DIR}/oceania
74+
unlink_and_link "${MIRROR_BASE_DIR}/oceania"
7575

7676
elif [ "$mirror_group" == "Mirrors in Russia" ]; then
7777
echo "[*] Mirrors in Russia selected"
78-
unlink_and_link ${MIRROR_BASE_DIR}/russia
78+
unlink_and_link "${MIRROR_BASE_DIR}/russia"
7979

8080
elif [ "$mirror_group" == "All mirrors" ]; then
8181
echo "[*] All mirrors selected"
82-
unlink_and_link ${MIRROR_BASE_DIR}/all
82+
unlink_and_link "${MIRROR_BASE_DIR}/all"
8383

8484
else
8585
echo "[!] Error: unknown mirror group: '$1'. Exiting"
@@ -102,7 +102,7 @@ get_mirror_description() {
102102
}
103103

104104
select_individual_mirror() {
105-
mirrors=($(find ${MIRROR_BASE_DIR}/{asia,chinese_mainland,europe,north_america,oceania,russia}/ -type f ! -name "*\.dpkg-old" ! -name "*\.dpkg-new" ! -name "*~"))
105+
mirrors=($(find "${MIRROR_BASE_DIR}"/{asia,chinese_mainland,europe,north_america,oceania,russia}/ -type f ! -name "*\.dpkg-old" ! -name "*\.dpkg-new" ! -name "*~"))
106106

107107
# Choose default mirror per default
108108
MIRRORS=("$(get_mirror_url "${MIRROR_BASE_DIR}/default")" "$(get_mirror_description "${MIRROR_BASE_DIR}/default")")
@@ -114,7 +114,7 @@ select_individual_mirror() {
114114
MIRRORS+=("$mirror_url" "$(get_mirror_description "$mirror")")
115115
done
116116

117-
local TEMPFILE="$(mktemp @TERMUX_PREFIX@/tmp/mirror.XXXXXX)"
117+
local TEMPFILE="$(mktemp "@TERMUX_PREFIX@/tmp/mirror.XXXXXX")"
118118
dialog \
119119
--title "termux-change-repo" --clear \
120120
--menu "Which mirror do you want to use?" 0 0 0 \
@@ -137,7 +137,7 @@ select_individual_mirror() {
137137
mirror="$(cat "$TEMPFILE")"
138138

139139
echo "[*] Mirror $(get_mirror_url "$mirror") selected"
140-
unlink_and_link "$(find ${MIRROR_BASE_DIR} -name $mirror)"
140+
unlink_and_link "$(find "${MIRROR_BASE_DIR}" -name "$mirror")"
141141
rm "$TEMPFILE"
142142
}
143143

@@ -160,12 +160,12 @@ fi
160160
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
161161
read -p "Warning: termux-change-repo can only change mirrors for apt, is that what you intended? [y|n] " -n 1 -r
162162
echo
163-
[[ ${REPLY} =~ ^[Nn]$ ]] && exit
163+
[[ "${REPLY}" =~ ^[Nn]$ ]] && exit
164164
fi
165165

166166
mkdir -p "@TERMUX_PREFIX@/tmp" || exit $?
167167

168-
TEMPFILE="$(mktemp @TERMUX_PREFIX@/tmp/termux-change-repo.XXXXXX)"
168+
TEMPFILE="$(mktemp "@TERMUX_PREFIX@/tmp/termux-change-repo.XXXXXX")"
169169

170170
MODES=()
171171
MODES+=("Mirror group" "Rotate between several mirrors (recommended)")
@@ -180,7 +180,7 @@ clear
180180

181181
case $retval in
182182
0)
183-
case "$(cat $TEMPFILE)" in
183+
case "$(cat "$TEMPFILE")" in
184184
"Mirror group")
185185
select_repository_group
186186
;;

scripts/termux-open.in

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ show_usage () {
1212
exit 0
1313
}
1414

15-
TEMP=`getopt \
16-
-n $SCRIPTNAME \
17-
-o h \
18-
--long send,view,chooser,content-type:,help\
19-
-- "$@"`
15+
TEMP="$(getopt \
16+
-n "$SCRIPTNAME" \
17+
-o h \
18+
--long send,view,chooser,content-type:,help \
19+
-- "$@")"
2020
eval set -- "$TEMP"
2121

2222
ACTION=android.intent.action.VIEW

scripts/termux-restore.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
set -e -u
3838

39-
export PREFIX=@TERMUX_PREFIX@
40-
4139
msg() {
4240
echo "$*" >&2
4341
}
@@ -80,7 +78,7 @@ fi
8078

8179
case "$1" in
8280
-\?|-h|--help|--usage) show_usage; exit 0;;
83-
*) BACKUP_FILE_PATH=$1;;
81+
*) BACKUP_FILE_PATH="$1";;
8482
esac
8583

8684
if [ "$BACKUP_FILE_PATH" != "-" ] && [ ! -e "$BACKUP_FILE_PATH" ]; then

0 commit comments

Comments
 (0)