Commit 4fd36a12 authored by Vitaly Lipatov's avatar Vitaly Lipatov

add compatibility layer (print_command_path, is_command, subst) to pack.d and repack.d

parent a163769a
...@@ -6,9 +6,39 @@ fatal() ...@@ -6,9 +6,39 @@ fatal()
exit 1 exit 1
} }
# compatibility layer
# print a path to the command if exists in $PATH
if which which 2>/dev/null >/dev/null ; then
# the best case if we have which command (other ways needs checking)
# TODO: don't use which at all, it is binary, not builtin shell command
print_command_path()
{
which -- "$1" 2>/dev/null
}
elif type -a type 2>/dev/null >/dev/null ; then
print_command_path()
{
type -fpP -- "$1" 2>/dev/null
}
else
print_command_path()
{
type "$1" 2>/dev/null | sed -e 's|.* /|/|'
}
fi
# check if <arg> is a real command
is_command()
{
print_command_path "$1" >/dev/null
}
# 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
...@@ -17,13 +47,15 @@ realpath() ...@@ -17,13 +47,15 @@ realpath()
fi fi
# 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
erc() erc()
{ {
epm tool erc "$@" epm tool erc "$@"
...@@ -34,6 +66,14 @@ is_dir_empty() ...@@ -34,6 +66,14 @@ is_dir_empty()
[ -z "$(ls -A "$1")" ] [ -z "$(ls -A "$1")" ]
} }
# copied from strings
# CHECKME: the same like estrlist has ?
# Note: used grep -E! write '[0-9]+(first|two)', not '[0-9]\+...'
rhas()
{
echo "$1" | grep -E -q -- "$2"
}
has_space() has_space()
{ {
[ "${1/ /}" != "$1" ] [ "${1/ /}" != "$1" ]
......
...@@ -7,8 +7,36 @@ fatal() ...@@ -7,8 +7,36 @@ fatal()
} }
# compatibility layer # compatibility layer
# print a path to the command if exists in $PATH
if which which 2>/dev/null >/dev/null ; then
# the best case if we have which command (other ways needs checking)
# TODO: don't use which at all, it is binary, not builtin shell command
print_command_path()
{
which -- "$1" 2>/dev/null
}
elif type -a type 2>/dev/null >/dev/null ; then
print_command_path()
{
type -fpP -- "$1" 2>/dev/null
}
else
print_command_path()
{
type "$1" 2>/dev/null | sed -e 's|.* /|/|'
}
fi
# check if <arg> is a real command
is_command()
{
print_command_path "$1" >/dev/null
}
# 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
...@@ -17,13 +45,14 @@ realpath() ...@@ -17,13 +45,14 @@ realpath()
fi fi
# 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
# Remove file from the file system and from spec # Remove file from the file system and from spec
# Usage: remove_file <path_to_file> # Usage: remove_file <path_to_file>
remove_file() remove_file()
......
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