Remove use of command -v from linux-installer.sh

This commit is contained in:
Kovid Goyal 2018-04-30 08:29:59 +05:30
parent 64c375848b
commit f04b5eea20
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,20 +2,47 @@
# linux-installer.sh # linux-installer.sh
# Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net> # Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
PYTHON3=$(command -v python3) search_for_python() {
PYTHON2=$(command -v python2) # We have to search for python as Ubuntu, in its infinite wisdom decided
# to release 18.04 with no python symlink, making it impossible to run polyglot
# python scripts.
if [ -x "$PYTHON3" ] # We cannot use command -v as it is not implemented in the posh shell shipped with
then # Ubuntu/Debian. Similarly, there is no guarantee that which is installed.
PYTHON=python3 # Shell scripting is a horrible joke, thank heavens for python.
else local IFS=:
if [ -x "$PYTHON2" ] if [ $ZSH_VERSION ]; then
then # zsh does not split by default
PYTHON=python2; setopt sh_word_split
else
PYTHON=python;
fi fi
fi local candidate_path
local candidate_python
local pythons=python3:python2
# disable pathname expansion (globbing)
set -f
for candidate_path in $PATH
do
if [ ! -z $candidate_path ]
then
for candidate_python in $pythons
do
if [ ! -z "$candidate_path" ]
then
if [ -x "$candidate_path/$candidate_python" ]
then
printf "$candidate_path/$candidate_python"
return
fi
fi
done
fi
done
set +f
printf "python"
}
PYTHON=$(search_for_python)
echo Using python executable: $PYTHON
$PYTHON -c "import sys; script_launch=lambda:sys.exit('Download of installer failed!'); exec(sys.stdin.read()); script_launch()" "$@" <<'CALIBRE_LINUX_INSTALLER_HEREDOC' $PYTHON -c "import sys; script_launch=lambda:sys.exit('Download of installer failed!'); exec(sys.stdin.read()); script_launch()" "$@" <<'CALIBRE_LINUX_INSTALLER_HEREDOC'
# {{{ # {{{