Fix script cwd handling
This commit is contained in:
parent
be36199640
commit
41156fe424
@ -15,10 +15,6 @@ from . import lxcmgr
|
|||||||
from . import svcmgr
|
from . import svcmgr
|
||||||
from .paths import LXC_STORAGE_DIR, REPO_CACHE_DIR, REPO_CONF_FILE, REPO_LOCAL_FILE, REPO_LOCK, REPO_SIG_FILE
|
from .paths import LXC_STORAGE_DIR, REPO_CACHE_DIR, REPO_CONF_FILE, REPO_LOCAL_FILE, REPO_LOCK, REPO_SIG_FILE
|
||||||
|
|
||||||
INSTALL_SCRIPT = 'install.sh'
|
|
||||||
UPDATE_SCRIPT = 'update.sh'
|
|
||||||
UNINSTALL_SCRIPT = 'uninstall.sh'
|
|
||||||
|
|
||||||
class Stage(Enum):
|
class Stage(Enum):
|
||||||
QUEUED = 1
|
QUEUED = 1
|
||||||
DOWNLOAD = 2
|
DOWNLOAD = 2
|
||||||
@ -103,11 +99,11 @@ class PkgMgr:
|
|||||||
# Run setup scripts
|
# Run setup scripts
|
||||||
app.stage = Stage.INSTALL
|
app.stage = Stage.INSTALL
|
||||||
# Run uninstall script to clean previous failed installation
|
# Run uninstall script to clean previous failed installation
|
||||||
self.run_script(app.name, UNINSTALL_SCRIPT)
|
self.run_script(app.name, 'uninstall')
|
||||||
# Build containers and services
|
# Build containers and services
|
||||||
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
||||||
# Run install script and register the app
|
# Run install script and register the app
|
||||||
self.run_script(app.name, INSTALL_SCRIPT)
|
self.run_script(app.name, 'install')
|
||||||
self.register_app(app.name, self.online_packages['apps'][app.name])
|
self.register_app(app.name, self.online_packages['apps'][app.name])
|
||||||
app.stage = Stage.DONE
|
app.stage = Stage.DONE
|
||||||
|
|
||||||
@ -193,16 +189,15 @@ class PkgMgr:
|
|||||||
subprocess.run(['tar', 'xJf', tmp_archive], cwd=os.path.join(REPO_CACHE_DIR, 'apps'), check=True)
|
subprocess.run(['tar', 'xJf', tmp_archive], cwd=os.path.join(REPO_CACHE_DIR, 'apps'), check=True)
|
||||||
os.unlink(tmp_archive)
|
os.unlink(tmp_archive)
|
||||||
|
|
||||||
def run_script(self, app, script):
|
def run_script(self, app, action):
|
||||||
# Runs script for an app, if the script is present
|
# Runs script for an app, if the script is present
|
||||||
script_dir = os.path.join(REPO_CACHE_DIR, 'apps', app)
|
cache_dir = os.path.join(REPO_CACHE_DIR, 'apps', app)
|
||||||
script_path = os.path.join(script_dir, script)
|
script_dir = os.path.join(cache_dir, action)
|
||||||
|
script_path = '{}.sh'.format(script_dir)
|
||||||
if os.path.exists(script_path):
|
if os.path.exists(script_path):
|
||||||
# Change working directory, so the script doesn't have to figure out paths to packaged files
|
# Run the script in its working directory, if there is one, so it doesn't have to figure out paths to packaged files
|
||||||
cwd = os.getcwd()
|
cwd = script_dir if os.path.exists(script_dir) else cache_dir
|
||||||
os.chdir(script_dir)
|
subprocess.run(script_path, cwd=cwd, check=True)
|
||||||
subprocess.run(script_path, check=True)
|
|
||||||
os.chdir(cwd)
|
|
||||||
|
|
||||||
def register_app(self, app, metadata):
|
def register_app(self, app, metadata):
|
||||||
# Register installed app in list of installed apps
|
# Register installed app in list of installed apps
|
||||||
@ -240,7 +235,7 @@ class PkgMgr:
|
|||||||
app.stage = Stage.DONE
|
app.stage = Stage.DONE
|
||||||
return
|
return
|
||||||
app.stage = Stage.UNINSTALL
|
app.stage = Stage.UNINSTALL
|
||||||
self.run_script(app.name, UNINSTALL_SCRIPT)
|
self.run_script(app.name, 'uninstall')
|
||||||
self.destroy_containers(self.installed_packages['apps'][app.name]['containers'])
|
self.destroy_containers(self.installed_packages['apps'][app.name]['containers'])
|
||||||
self.purge_scripts(app.name)
|
self.purge_scripts(app.name)
|
||||||
self.unregister_app(app.name)
|
self.unregister_app(app.name)
|
||||||
@ -268,7 +263,7 @@ class PkgMgr:
|
|||||||
# Build containers and services
|
# Build containers and services
|
||||||
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
||||||
# Run update script and register the app
|
# Run update script and register the app
|
||||||
self.run_script(app.name, UPDATE_SCRIPT)
|
self.run_script(app.name, 'update')
|
||||||
self.register_app(app.name, self.online_packages['apps'][app.name])
|
self.register_app(app.name, self.online_packages['apps'][app.name])
|
||||||
app.stage = Stage.DONE
|
app.stage = Stage.DONE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user