Commit a163769a authored by Vitaly Lipatov's avatar Vitaly Lipatov

remove direct which command using

parent bf021f5e
......@@ -19,7 +19,7 @@
__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
......
......@@ -73,14 +73,14 @@ epm_full_upgrade()
fi
if [ -z "$full_upgrade_no_flatpack" ] ; then
if which flatpak 2>/dev/null >/dev/null ; then
if is_command flatpak ; then
[ -n "$quiet" ] || echo
docmd flatpak update
fi
fi
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
sudocmd snap refresh
fi
......
......@@ -255,7 +255,7 @@ compare_version()
{
case $PMTYPE in
*-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 "$@"
;;
*-dpkg)
......
......@@ -41,7 +41,7 @@ __do_query_real_file()
if [ -e "$1" ] ; then
TOFILE="$(__abs_filename "$1")"
else
TOFILE=$(which -- "$1" 2>/dev/null || echo "$1")
TOFILE=$(print_command_path "$1" || echo "$1")
if [ "$TOFILE" != "$1" ] ; then
info " > $1 is placed as $TOFILE"
fi
......
......@@ -37,7 +37,7 @@ epm_remove_old_kernels()
[ -n "$dryrun" ] && return
# 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
yes | sudocmd nvidia-clean-driver
else
......
......@@ -19,16 +19,6 @@
# 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
inputisatty()
......@@ -66,7 +56,7 @@ check_tty()
export EGREPCOLOR="--color"
fi
which tput >/dev/null 2>/dev/null || return
is_command tput || return
# FreeBSD does not support tput -S
echo | tput -S >/dev/null 2>/dev/null || return
[ -z "$USETTY" ] || return
......@@ -200,14 +190,6 @@ sudocmd_foreach()
done
}
# add realpath if missed
if ! which realpath 2>/dev/null >/dev/null ; then
realpath()
{
readlink -f "$@"
}
fi
# print full path to files
make_filepath()
{
......@@ -391,7 +373,7 @@ set_sudo()
# start error section
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.'"
return "$SUDO_TESTED"
fi
......@@ -429,7 +411,7 @@ sudo_allowed()
# args: seconds command
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
$TO "$@"
return
......@@ -447,7 +429,7 @@ set_eatmydata()
# skip if disabled
[ -n "$EPMNOEATMYDATA" ] && return
# use if possible
which eatmydata >/dev/null 2>/dev/null || return
is_command eatmydata || return
set_sudo
# FIXME: check if SUDO already has eatmydata
[ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata"
......@@ -544,7 +526,7 @@ eget()
# FIXME: we need disable output here, eget can be used for get output
assure_exists eget eget 3.3 >/dev/null
# 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 "$@"
}
......@@ -562,7 +544,7 @@ erc()
# FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null
# 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 "$@"
}
......@@ -580,7 +562,7 @@ ercat()
# FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null
# 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 "$@"
}
......@@ -602,8 +584,9 @@ onefile_estrlist()
onefile_eget()
{
# check for both
which curl 2>/dev/null >/dev/null || assure_exists wget
which wget 2>/dev/null >/dev/null || assure_exists curl
# we really need that cross here,
is_command curl || assure_exists wget
is_command wget || assure_exists curl
internal_tools_eget "$@"
}
......@@ -801,7 +784,7 @@ is_command()
# compatibility layer
# add realpath if missed
if ! which realpath 2>/dev/null >/dev/null ; then
if ! is_command realpath ; then
realpath()
{
[ -n "$*" ] || return
......@@ -809,15 +792,28 @@ realpath()
}
fi
# TODO: use perl if sed -i is not accessible
# sed -i is only supported in GNU sed.
# sed -i "s/$find/$replace/g" "$@"
# perl -p -i -e "s/$find/$replace/g" "$@"
# add subst if missed
if ! which subst 2>/dev/null >/dev/null ; then
if ! is_command subst ; then
subst()
{
sed -i -e "$@"
}
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()
{
local CMD="$1"
shift
if which "$CMD" 2>/dev/null >/dev/null ; then
if is_command "$CMD" ; then
docmd $CMD "$@"
return 0
fi
return 1
}
# TODO: use something like xdg-browser
open_browser()
{
local i
......
......@@ -35,8 +35,6 @@ Requires: apt-repo
AutoProv:no
AutoReq:no
Requires: which
# TODO: drop gzip
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