diff options
Diffstat (limited to 'nextbin')
-rwxr-xr-x | nextbin | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -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 |