From bd87403ae5d968473fe651db4cd0f69b46a1ec00 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 13 Jul 2020 14:13:32 -0700 Subject: [PATCH] add prefix option to install2.sh script --- install2.sh | 9 +++++++-- tasks.py | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/install2.sh b/install2.sh index bdfd2f7b..5e5a9b11 100755 --- a/install2.sh +++ b/install2.sh @@ -13,7 +13,8 @@ fi # parse arguments dev="" verbose="" -while getopts "dv" opt; do +prefix="" +while getopts "dvp:" opt; do case ${opt} in d) dev="-d" @@ -21,11 +22,15 @@ while getopts "dv" opt; do v) verbose="-v" ;; + p) + prefix="-p ${OPTARG}" + ;; \?) echo "script usage: $(basename $0) [-d] [-v]" >&2 echo "" >&2 echo "-v enable verbose install" >&2 echo "-d enable developer install" >&2 + echo "-p install prefix, defaults to /usr/local" >&2 exit 1 ;; esac @@ -49,4 +54,4 @@ python3 -m pip install --user pipx python3 -m pipx ensurepath export PATH=$PATH:~/.local/bin pipx install invoke -inv install ${dev} ${verbose} +inv install ${dev} ${verbose} ${prefix} diff --git a/tasks.py b/tasks.py index 2f9bd556..b4f37679 100644 --- a/tasks.py +++ b/tasks.py @@ -10,6 +10,7 @@ from invoke import task, Context DAEMON_DIR: str = "daemon" VCMD_DIR: str = "netns" GUI_DIR: str = "gui" +DEFAULT_PREFIX: str = "/usr/local" class OsName(Enum): @@ -169,7 +170,7 @@ def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None: c.run("sudo make install", hide=hide) -def install_files(c: Context, hide: bool, prefix: str = "/usr/local") -> None: +def install_files(c: Context, hide: bool, prefix: str = DEFAULT_PREFIX) -> None: # install all scripts python = get_python(c) bin_dir = Path(prefix).joinpath("bin") @@ -225,10 +226,11 @@ def install_files(c: Context, hide: bool, prefix: str = "/usr/local") -> None: @task -def install(c, dev=False, verbose=False): +def install(c, dev=False, verbose=False, prefix=DEFAULT_PREFIX): """ install core """ + print(f"installing core with prefix: {prefix}") hide = not verbose os_info = get_os() install_system(c, os_info, hide) @@ -236,7 +238,7 @@ def install(c, dev=False, verbose=False): build(c, os_info, hide) install_core(c, hide) install_poetry(c, dev, hide) - install_files(c, hide) + install_files(c, hide, prefix) install_ospf_mdr(c, os_info, hide) print("please open a new terminal or re-login to leverage invoke for running core") print("# run daemon") @@ -246,7 +248,7 @@ def install(c, dev=False, verbose=False): @task -def uninstall(c, dev=False, verbose=False, prefix="/usr/local"): +def uninstall(c, dev=False, verbose=False, prefix=DEFAULT_PREFIX): """ uninstall core """