Commit a163769a authored by Vitaly Lipatov's avatar Vitaly Lipatov

remove direct which command using

parent bf021f5e
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
__check_command_in_path() __check_command_in_path()
{ {
PATH=$PATH:/sbin:/usr/sbin which "$1" 2>/dev/null PATH=$PATH:/sbin:/usr/sbin print_command_path "$1"
} }
# returns TRUE if package version is omitted, or package is not installed, or version is too old # returns TRUE if package version is omitted, or package is not installed, or version is too old
......
...@@ -73,14 +73,14 @@ epm_full_upgrade() ...@@ -73,14 +73,14 @@ epm_full_upgrade()
fi fi
if [ -z "$full_upgrade_no_flatpack" ] ; then if [ -z "$full_upgrade_no_flatpack" ] ; then
if which flatpak 2>/dev/null >/dev/null ; then if is_command flatpak ; then
[ -n "$quiet" ] || echo [ -n "$quiet" ] || echo
docmd flatpak update docmd flatpak update
fi fi
fi fi
if [ -z "$full_upgrade_no_snap" ] ; then if [ -z "$full_upgrade_no_snap" ] ; then
if which snap 2>/dev/null >/dev/null && serv snapd exists && serv snapd status ; then if is_command snap && serv snapd exists && serv snapd status >/dev/null ; then
[ -n "$quiet" ] || echo [ -n "$quiet" ] || echo
sudocmd snap refresh sudocmd snap refresh
fi fi
......
...@@ -255,7 +255,7 @@ compare_version() ...@@ -255,7 +255,7 @@ compare_version()
{ {
case $PMTYPE in case $PMTYPE in
*-rpm) *-rpm)
which rpmevrcmp 2>/dev/null >/dev/null || fatal "rpmevrcmp exists in ALT Linux only" is_command rpmevrcmp || fatal "rpmevrcmp exists in ALT Linux only"
a= rpmevrcmp "$@" a= rpmevrcmp "$@"
;; ;;
*-dpkg) *-dpkg)
......
...@@ -41,7 +41,7 @@ __do_query_real_file() ...@@ -41,7 +41,7 @@ __do_query_real_file()
if [ -e "$1" ] ; then if [ -e "$1" ] ; then
TOFILE="$(__abs_filename "$1")" TOFILE="$(__abs_filename "$1")"
else else
TOFILE=$(which -- "$1" 2>/dev/null || echo "$1") TOFILE=$(print_command_path "$1" || echo "$1")
if [ "$TOFILE" != "$1" ] ; then if [ "$TOFILE" != "$1" ] ; then
info " > $1 is placed as $TOFILE" info " > $1 is placed as $TOFILE"
fi fi
......
...@@ -37,7 +37,7 @@ epm_remove_old_kernels() ...@@ -37,7 +37,7 @@ epm_remove_old_kernels()
[ -n "$dryrun" ] && return [ -n "$dryrun" ] && return
# remove unused nvidia drivers # remove unused nvidia drivers
if which nvidia-clean-driver 2>/dev/null ; then if is_command nvidia-clean-driver ; then
if [ -n "$non_interactive" ] ; then if [ -n "$non_interactive" ] ; then
yes | sudocmd nvidia-clean-driver yes | sudocmd nvidia-clean-driver
else else
......
...@@ -19,16 +19,6 @@ ...@@ -19,16 +19,6 @@
# copied from /etc/init.d/outformat (ALT Linux) # copied from /etc/init.d/outformat (ALT Linux)
check_core_commands()
{
#which --help >/dev/null || fatal "Can't find which command (which package is missed?)"
# broken which on Debian systems
# TODO: use is_command and print_command_path instead of
which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)"
which grep >/dev/null || fatal "Can't find grep command (coreutils package is missed?)"
which sed >/dev/null || fatal "Can't find sed command (sed package is missed?)"
}
# FIXME on Android: FIX ME! implement ttyname_r() bionic/libc/bionic/stubs.c:366 # FIXME on Android: FIX ME! implement ttyname_r() bionic/libc/bionic/stubs.c:366
inputisatty() inputisatty()
...@@ -66,7 +56,7 @@ check_tty() ...@@ -66,7 +56,7 @@ check_tty()
export EGREPCOLOR="--color" export EGREPCOLOR="--color"
fi fi
which tput >/dev/null 2>/dev/null || return is_command tput || return
# FreeBSD does not support tput -S # FreeBSD does not support tput -S
echo | tput -S >/dev/null 2>/dev/null || return echo | tput -S >/dev/null 2>/dev/null || return
[ -z "$USETTY" ] || return [ -z "$USETTY" ] || return
...@@ -200,14 +190,6 @@ sudocmd_foreach() ...@@ -200,14 +190,6 @@ sudocmd_foreach()
done done
} }
# add realpath if missed
if ! which realpath 2>/dev/null >/dev/null ; then
realpath()
{
readlink -f "$@"
}
fi
# print full path to files # print full path to files
make_filepath() make_filepath()
{ {
...@@ -391,7 +373,7 @@ set_sudo() ...@@ -391,7 +373,7 @@ set_sudo()
# start error section # start error section
SUDO_TESTED="1" SUDO_TESTED="1"
if ! which $SUDO_CMD >/dev/null 2>/dev/null ; then if ! is_command $SUDO_CMD ; then
[ "$nofail" = "nofail" ] || SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'"
return "$SUDO_TESTED" return "$SUDO_TESTED"
fi fi
...@@ -429,7 +411,7 @@ sudo_allowed() ...@@ -429,7 +411,7 @@ sudo_allowed()
# args: seconds command # args: seconds command
withtimeout() withtimeout()
{ {
local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null) local TO=$(print_command_path timeout || print_command_path gtimeout)
if [ -x "$TO" ] ; then if [ -x "$TO" ] ; then
$TO "$@" $TO "$@"
return return
...@@ -447,7 +429,7 @@ set_eatmydata() ...@@ -447,7 +429,7 @@ set_eatmydata()
# skip if disabled # skip if disabled
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
which eatmydata >/dev/null 2>/dev/null || return is_command eatmydata || return
set_sudo set_sudo
# FIXME: check if SUDO already has eatmydata # FIXME: check if SUDO already has eatmydata
[ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata" [ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata"
...@@ -544,7 +526,7 @@ eget() ...@@ -544,7 +526,7 @@ eget()
# FIXME: we need disable output here, eget can be used for get output # FIXME: we need disable output here, eget can be used for get output
assure_exists eget eget 3.3 >/dev/null assure_exists eget eget 3.3 >/dev/null
# run external command, not the function # run external command, not the function
EGET=$(which eget) || fatal "Missed command eget from installed package eget" EGET=$(print_command_path eget) || fatal "Missed command eget from installed package eget"
$EGET "$@" $EGET "$@"
} }
...@@ -562,7 +544,7 @@ erc() ...@@ -562,7 +544,7 @@ erc()
# FIXME: we need disable output here, ercat can be used for get output # FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null assure_exists_erc >/dev/null
# run external command, not the function # run external command, not the function
ERC=$(which erc) || fatal "Missed command erc from installed package erc" ERC=$(print_command_path erc) || fatal "Missed command erc from installed package erc"
$ERC "$@" $ERC "$@"
} }
...@@ -580,7 +562,7 @@ ercat() ...@@ -580,7 +562,7 @@ ercat()
# FIXME: we need disable output here, ercat can be used for get output # FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null assure_exists_erc >/dev/null
# run external command, not the function # run external command, not the function
ERCAT=$(which ercat) || fatal "Missed command ercat from installed package erc" ERCAT=$(print_command_path ercat) || fatal "Missed command ercat from installed package erc"
$ERCAT "$@" $ERCAT "$@"
} }
...@@ -602,8 +584,9 @@ onefile_estrlist() ...@@ -602,8 +584,9 @@ onefile_estrlist()
onefile_eget() onefile_eget()
{ {
# check for both # check for both
which curl 2>/dev/null >/dev/null || assure_exists wget # we really need that cross here,
which wget 2>/dev/null >/dev/null || assure_exists curl is_command curl || assure_exists wget
is_command wget || assure_exists curl
internal_tools_eget "$@" internal_tools_eget "$@"
} }
...@@ -801,7 +784,7 @@ is_command() ...@@ -801,7 +784,7 @@ is_command()
# compatibility layer # compatibility layer
# add realpath if missed # add realpath if missed
if ! which realpath 2>/dev/null >/dev/null ; then if ! is_command realpath ; then
realpath() realpath()
{ {
[ -n "$*" ] || return [ -n "$*" ] || return
...@@ -809,15 +792,28 @@ realpath() ...@@ -809,15 +792,28 @@ realpath()
} }
fi fi
# TODO: use perl if sed -i is not accessible # TODO: use perl if sed -i is not accessible
# sed -i is only supported in GNU sed. # sed -i is only supported in GNU sed.
# sed -i "s/$find/$replace/g" "$@" # sed -i "s/$find/$replace/g" "$@"
# perl -p -i -e "s/$find/$replace/g" "$@" # perl -p -i -e "s/$find/$replace/g" "$@"
# add subst if missed # add subst if missed
if ! which subst 2>/dev/null >/dev/null ; then if ! is_command subst ; then
subst() subst()
{ {
sed -i -e "$@" sed -i -e "$@"
} }
fi fi
check_core_commands()
{
#which --help >/dev/null || fatal "Can't find which command (which package is missed?)"
# broken which on Debian systems
# TODO: use is_command and print_command_path instead of
which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)"
is_command grep || fatal "Can't find grep command (coreutils package is missed?)"
is_command sed || fatal "Can't find sed command (sed package is missed?)"
}
...@@ -44,13 +44,14 @@ run_command_if_exists() ...@@ -44,13 +44,14 @@ run_command_if_exists()
{ {
local CMD="$1" local CMD="$1"
shift shift
if which "$CMD" 2>/dev/null >/dev/null ; then if is_command "$CMD" ; then
docmd $CMD "$@" docmd $CMD "$@"
return 0 return 0
fi fi
return 1 return 1
} }
# TODO: use something like xdg-browser
open_browser() open_browser()
{ {
local i local i
......
...@@ -35,8 +35,6 @@ Requires: apt-repo ...@@ -35,8 +35,6 @@ Requires: apt-repo
AutoProv:no AutoProv:no
AutoReq:no AutoReq:no
Requires: which
# TODO: drop gzip # TODO: drop gzip
Requires: coreutils diffutils findutils file gawk grep gzip less sed bash termutils Requires: coreutils diffutils findutils file gawk grep gzip less sed bash termutils
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment