fixed running bash script remotely and install package error

This commit is contained in:
Mathieu Broillet 2023-06-12 22:05:21 +02:00
parent 31c310c6e0
commit 88f4cdf14f
Signed by: mathieu
GPG Key ID: A08E484FE95074C1
2 changed files with 9 additions and 4 deletions

View File

@ -17,6 +17,11 @@ def run_script(lxc, step):
Typically read from the "creation/steps/<step>" in JSON file
"""
# Install bash if not installed
# Sometimes only ash or sh are installed, which doesn't work for some scripts
if not lxc.has_program("bash"):
install_package(lxc, "bash")
# Run local script
if "path" in step:
_run_local_script_on_lxc(lxc, step["path"])
@ -42,7 +47,7 @@ def _run_local_script_on_lxc(lxc, path: "Path to the script on the machine runni
path = get_path(lxc, path)
with open(path, "r") as file:
script = file.read()
lxc.run_command("'bash -s' <<'ENDSSH'\n" + script)
lxc.run_command("bash <<EOF\n" + script + "\nEOF")
def _run_remote_script_on_lxc(lxc, url: "URL to the script"):
@ -196,9 +201,9 @@ def install_package(lxc, package):
if type(package) is list:
for p in package:
lxc.run_command(f"{proxmox_utils.get_install_package_command(lxc.get_os_name())} {p} -y")
lxc.run_command(f"{proxmox_utils.get_install_package_command(lxc.get_os_name())} {p}")
else:
lxc.run_command(f"{proxmox_utils.get_install_package_command(lxc.get_os_name())} {package} -y")
lxc.run_command(f"{proxmox_utils.get_install_package_command(lxc.get_os_name())} {package}")
def remove_package(lxc, package):

View File

@ -142,7 +142,7 @@ def get_install_package_command(distribution):
elif distribution == "gentoo":
return "emerge -a"
elif distribution == "alpine":
return "apk add --no-cache"
return "apk add"
elif distribution == "archlinux":
return "pacman -S --noconfirm"
elif distribution == "devuan":