summaryrefslogtreecommitdiff
path: root/nextbin
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-04-28 19:26:18 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-04-28 19:26:18 -0400
commit40b620f61bc26e59c20adc74500062a558c4999e (patch)
treec644a515e0ad096e3f0462772e975be60cd458d8 /nextbin
parentc3678e8877669b55de9cd8d7b44fa7e642e3cf1f (diff)
downloadnextbin-master.tar.xz
nextbin-master.zip
add POSIX same_file fallback, absolute file checkHEADmaster
Diffstat (limited to 'nextbin')
-rwxr-xr-xnextbin32
1 files changed, 29 insertions, 3 deletions
diff --git a/nextbin b/nextbin
index 006b158..d688fa9 100755
--- a/nextbin
+++ b/nextbin
@@ -23,9 +23,35 @@ die() {
exit 1
}
-[ / -ef / ] || exec bash "$0" "$orig_exe" "$@" || die "test -ef doesn't work, and bash not found"
[ -n "$PATH" ] || die 'PATH is empty'
+# shellcheck disable=SC3013
+if [ / -ef / ] && ! [ / -ef /dev/null ]; then
+ same_file() {
+ # shellcheck disable=SC3013
+ [ "$1" -ef "$2" ]
+ }
+else
+ if command -v bash >/dev/null 2>&1; then
+ exec bash "$0" "$orig_exe" "$@"
+ fi
+ ino() {
+ ls=$(ls -i "$1")
+ printf '%s\n' "${ls%% *}"
+ }
+ dev() {
+ df -P "$1" | awk 'END{print $1}'
+ }
+ same_file() {
+ [ "$(ino "$1")" = "$(ino "$2")" ] && [ "$(dev "$1")" = "$(dev "$2")" ]
+ }
+fi
+
+case $orig_exe in
+ /*) ;;
+ *) die 'non-absolute $0'
+esac
+
exe_name=${orig_exe##*/}
path=$PATH
phase=1
@@ -34,10 +60,10 @@ while :; do
exe=${path%%:*}/$exe_name
if [ -f "$exe" ] && [ -x "$exe" ]; then
if [ "$phase" = 1 ]; then
- if [ "$exe" -ef "$orig_exe" ]; then
+ if same_file "$exe" "$orig_exe"; then
phase=2
fi
- elif [ "$exe" -ef "$orig_exe" ]; then
+ elif same_file "$exe" "$orig_exe"; then
[ -z "$found" ] || die 'duplicate PATH entries found'
elif [ -z "$found" ]; then
found=$exe