fixed running bash script remotely and install package error
This commit is contained in:
parent
31c310c6e0
commit
88f4cdf14f
@ -17,6 +17,11 @@ def run_script(lxc, step):
|
|||||||
Typically read from the "creation/steps/<step>" in JSON file
|
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
|
# Run local script
|
||||||
if "path" in step:
|
if "path" in step:
|
||||||
_run_local_script_on_lxc(lxc, step["path"])
|
_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)
|
path = get_path(lxc, path)
|
||||||
with open(path, "r") as file:
|
with open(path, "r") as file:
|
||||||
script = file.read()
|
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"):
|
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:
|
if type(package) is list:
|
||||||
for p in package:
|
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:
|
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):
|
def remove_package(lxc, package):
|
||||||
|
@ -142,7 +142,7 @@ def get_install_package_command(distribution):
|
|||||||
elif distribution == "gentoo":
|
elif distribution == "gentoo":
|
||||||
return "emerge -a"
|
return "emerge -a"
|
||||||
elif distribution == "alpine":
|
elif distribution == "alpine":
|
||||||
return "apk add --no-cache"
|
return "apk add"
|
||||||
elif distribution == "archlinux":
|
elif distribution == "archlinux":
|
||||||
return "pacman -S --noconfirm"
|
return "pacman -S --noconfirm"
|
||||||
elif distribution == "devuan":
|
elif distribution == "devuan":
|
||||||
|
Loading…
Reference in New Issue
Block a user