Fix script cwd handling
This commit is contained in:
parent
be36199640
commit
41156fe424
@ -15,10 +15,6 @@ from . import lxcmgr
|
||||
from . import svcmgr
|
||||
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):
|
||||
QUEUED = 1
|
||||
DOWNLOAD = 2
|
||||
@ -103,11 +99,11 @@ class PkgMgr:
|
||||
# Run setup scripts
|
||||
app.stage = Stage.INSTALL
|
||||
# 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
|
||||
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
||||
# 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])
|
||||
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)
|
||||
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
|
||||
script_dir = os.path.join(REPO_CACHE_DIR, 'apps', app)
|
||||
script_path = os.path.join(script_dir, script)
|
||||
cache_dir = os.path.join(REPO_CACHE_DIR, 'apps', app)
|
||||
script_dir = os.path.join(cache_dir, action)
|
||||
script_path = '{}.sh'.format(script_dir)
|
||||
if os.path.exists(script_path):
|
||||
# Change working directory, so the script doesn't have to figure out paths to packaged files
|
||||
cwd = os.getcwd()
|
||||
os.chdir(script_dir)
|
||||
subprocess.run(script_path, check=True)
|
||||
os.chdir(cwd)
|
||||
# Run the script in its working directory, if there is one, so it doesn't have to figure out paths to packaged files
|
||||
cwd = script_dir if os.path.exists(script_dir) else cache_dir
|
||||
subprocess.run(script_path, cwd=cwd, check=True)
|
||||
|
||||
def register_app(self, app, metadata):
|
||||
# Register installed app in list of installed apps
|
||||
@ -240,7 +235,7 @@ class PkgMgr:
|
||||
app.stage = Stage.DONE
|
||||
return
|
||||
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.purge_scripts(app.name)
|
||||
self.unregister_app(app.name)
|
||||
@ -268,7 +263,7 @@ class PkgMgr:
|
||||
# Build containers and services
|
||||
self.create_containers(self.online_packages['apps'][app.name]['containers'])
|
||||
# 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])
|
||||
app.stage = Stage.DONE
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user