install: adjustments to install scripts to better support alternative versions of python, PYTHON_DEP added for system package adjustments

This commit is contained in:
Blake Harnden 2022-05-27 20:10:48 -07:00
parent 7173e488cb
commit d77ed9c473
2 changed files with 27 additions and 14 deletions

View file

@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
# install pre-reqs using yum/apt # install pre-reqs using yum/apt
PYTHON="${PYTHON:=python3}"
PYTHON_DEP="${PYTHON_DEP:=python3}"
if command -v apt &> /dev/null if command -v apt &> /dev/null
then then
echo "setup to install CORE using apt" echo "setup to install CORE using apt"
sudo apt install -y python3-pip python3-venv sudo apt install -y ${PYTHON_DEP}-pip ${PYTHON_DEP}-venv
elif command -v yum &> /dev/null elif command -v yum &> /dev/null
then then
echo "setup to install CORE using yum" echo "setup to install CORE using yum"
sudo yum install -y python3-pip sudo yum install -y ${PYTHON_DEP}-pip
else else
echo "apt/yum was not found" echo "apt/yum was not found"
echo "install python3, pip, venv, pipx, and invoke to run the automated install" echo "install python3, pip, venv, pipx, and invoke to run the automated install"
@ -16,8 +18,8 @@ else
fi fi
# install tooling for invoke based installation # install tooling for invoke based installation
python3 -m pip install --user pipx==0.16.4 ${PYTHON} -m pip install --user pipx==0.16.4
python3 -m pipx ensurepath ${PYTHON} -m pipx ensurepath
export PATH=$PATH:~/.local/bin export PATH=$PATH:~/.local/bin
pipx install invoke==1.4.1 pipx install invoke==1.4.1
pipx install poetry==1.1.12 pipx install poetry==1.1.12

View file

@ -114,6 +114,10 @@ def get_env_python() -> str:
return os.environ.get("PYTHON", "python3") return os.environ.get("PYTHON", "python3")
def get_env_python_dep() -> str:
return os.environ.get("PYTHON_DEP", "python3")
def get_python(c: Context, warn: bool = False) -> str: def get_python(c: Context, warn: bool = False) -> str:
with c.cd(DAEMON_DIR): with c.cd(DAEMON_DIR):
r = c.run("poetry env info -p", warn=warn, hide=True) r = c.run("poetry env info -p", warn=warn, hide=True)
@ -153,23 +157,27 @@ def get_os(install_type: Optional[str]) -> OsInfo:
def check_existing_core(c: Context, hide: bool) -> None: def check_existing_core(c: Context, hide: bool) -> None:
if c.run("python -c \"import core\"", warn=True, hide=hide): if c.run("python -c \"import core\"", warn=True, hide=hide):
raise SystemError("existing python2 core installation detected, please remove") raise SystemError("existing python2 core installation detected, please remove")
if c.run("python3 -c \"import core\"", warn=True, hide=hide): python_bin = get_env_python()
raise SystemError("existing python3 core installation detected, please remove") if c.run(f"{python_bin} -c \"import core\"", warn=True, hide=hide):
raise SystemError(
f"existing {python_bin} core installation detected, please remove"
)
if c.run("which core-daemon", warn=True, hide=hide): if c.run("which core-daemon", warn=True, hide=hide):
raise SystemError("core scripts found, please remove old installation") raise SystemError("core scripts found, please remove old installation")
def install_system(c: Context, os_info: OsInfo, hide: bool) -> None: def install_system(c: Context, os_info: OsInfo, hide: bool) -> None:
python_dep = get_env_python_dep()
if os_info.like == OsLike.DEBIAN: if os_info.like == OsLike.DEBIAN:
c.run( c.run(
"sudo apt install -y automake pkg-config gcc libev-dev nftables " "sudo apt install -y automake pkg-config gcc libev-dev nftables "
"iproute2 ethtool tk python3-tk bash", f"iproute2 ethtool tk {python_dep}-tk bash",
hide=hide hide=hide
) )
elif os_info.like == OsLike.REDHAT: elif os_info.like == OsLike.REDHAT:
c.run( c.run(
"sudo yum install -y automake pkgconf-pkg-config gcc gcc-c++ " "sudo yum install -y automake pkgconf-pkg-config gcc gcc-c++ "
"libev-devel nftables iproute python3-devel python3-tkinter " f"libev-devel nftables iproute {python_dep}-devel {python_dep}-tkinter "
"tk ethtool make bash", "tk ethtool make bash",
hide=hide hide=hide
) )
@ -202,14 +210,14 @@ def install_core(c: Context, hide: bool) -> None:
def install_poetry(c: Context, dev: bool, local: bool, hide: bool) -> None: def install_poetry(c: Context, dev: bool, local: bool, hide: bool) -> None:
python_bin = get_env_python()
if local: if local:
with c.cd(DAEMON_DIR): with c.cd(DAEMON_DIR):
c.run("poetry build -f wheel", hide=hide) c.run("poetry build -f wheel", hide=hide)
c.run("sudo python3 -m pip install dist/*") c.run(f"sudo {python_bin} -m pip install dist/*")
else: else:
args = "" if dev else "--no-dev" args = "" if dev else "--no-dev"
with c.cd(DAEMON_DIR): with c.cd(DAEMON_DIR):
python_bin = get_env_python()
c.run(f"poetry env use {python_bin}", hide=hide) c.run(f"poetry env use {python_bin}", hide=hide)
c.run(f"poetry install {args}", hide=hide) c.run(f"poetry install {args}", hide=hide)
if dev: if dev:
@ -388,12 +396,13 @@ def install_emane(c, emane_version, verbose=False, install_type=None):
p = Progress(verbose) p = Progress(verbose)
hide = not verbose hide = not verbose
os_info = get_os(install_type) os_info = get_os(install_type)
python_dep = get_env_python_dep()
with p.start("installing system dependencies"): with p.start("installing system dependencies"):
if os_info.like == OsLike.DEBIAN: if os_info.like == OsLike.DEBIAN:
c.run( c.run(
"sudo apt install -y gcc g++ automake libtool libxml2-dev " "sudo apt install -y gcc g++ automake libtool libxml2-dev "
"libprotobuf-dev libpcap-dev libpcre3-dev uuid-dev pkg-config " "libprotobuf-dev libpcap-dev libpcre3-dev uuid-dev pkg-config "
"protobuf-compiler git python3-protobuf python3-setuptools", f"protobuf-compiler git {python_dep}-protobuf {python_dep}-setuptools",
hide=hide, hide=hide,
) )
elif os_info.like == OsLike.REDHAT: elif os_info.like == OsLike.REDHAT:
@ -402,7 +411,7 @@ def install_emane(c, emane_version, verbose=False, install_type=None):
c.run( c.run(
"sudo yum install -y autoconf automake git libtool libxml2-devel " "sudo yum install -y autoconf automake git libtool libxml2-devel "
"libpcap-devel pcre-devel libuuid-devel make gcc-c++ protobuf-compiler " "libpcap-devel pcre-devel libuuid-devel make gcc-c++ protobuf-compiler "
"protobuf-devel python3-setuptools", f"protobuf-devel {python_dep}-setuptools",
hide=hide, hide=hide,
) )
emane_dir = "../emane" emane_dir = "../emane"
@ -411,10 +420,11 @@ def install_emane(c, emane_version, verbose=False, install_type=None):
with p.start("cloning emane"): with p.start("cloning emane"):
c.run(f"git clone {emane_url} {emane_dir}", hide=hide) c.run(f"git clone {emane_url} {emane_dir}", hide=hide)
with p.start("setup emane"): with p.start("setup emane"):
python_bin = get_env_python()
with c.cd(emane_dir): with c.cd(emane_dir):
c.run(f"git checkout {emane_version}", hide=hide) c.run(f"git checkout {emane_version}", hide=hide)
c.run("./autogen.sh", hide=hide) c.run("./autogen.sh", hide=hide)
c.run("PYTHON=python3 ./configure --prefix=/usr", hide=hide) c.run(f"PYTHON={python_bin} ./configure --prefix=/usr", hide=hide)
with p.start("build emane python bindings"): with p.start("build emane python bindings"):
with c.cd(str(emane_python_dir)): with c.cd(str(emane_python_dir)):
c.run("make -j$(nproc)", hide=hide) c.run("make -j$(nproc)", hide=hide)
@ -456,7 +466,8 @@ def uninstall(
if local: if local:
with p.start("uninstalling core"): with p.start("uninstalling core"):
c.run("sudo python3 -m pip uninstall -y core", hide=hide) python_bin = get_env_python()
c.run(f"sudo {python_bin} -m pip uninstall -y core", hide=hide)
else: else:
python = get_python(c, warn=True) python = get_python(c, warn=True)
if python: if python: