cephadm: locate path to the python3 binary

fixes incorrect shebang in the compiled zipfile (`#!python3`)

Signed-off-by: Michael Fritch <mfritch@suse.com>
This commit is contained in:
Michael Fritch 2021-11-18 14:54:56 -07:00 committed by John Mulligan
parent f756b3cfcc
commit 5499bbbb9c

View File

@ -9,6 +9,8 @@ clean_up() {
}
trap clean_up EXIT
PYTHON=$(which python3)
# Create build directory and install required dependencies
target_fpath="$(pwd)/cephadm"
if [ -n "$1" ]; then
@ -16,13 +18,13 @@ if [ -n "$1" ]; then
fi
builddir=$(mktemp -d)
if [ -e "requirements.txt" ]; then
python3 -m pip install -r requirements.txt --target ${builddir}
$PYTHON -m pip install -r requirements.txt --target ${builddir}
fi
# Make sure all newly created source files are copied here as well!
cp cephadm.py ${builddir}/__main__.py
version=$(python3 --version)
version=$($PYTHON --version)
if [[ "$version" =~ ^Python[[:space:]]([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$ ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
@ -33,7 +35,7 @@ if [[ "$version" =~ ^Python[[:space:]]([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:
compress="--compress"
fi
python3 -mzipapp -p python3 ${builddir} ${compress} --output $target_fpath
$PYTHON -mzipapp -p $PYTHON ${builddir} ${compress} --output $target_fpath
echo written to ${target_fpath}
else
echo "Couldn't parse Python version"