mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #188 from YunoHost/install_as_root
Use the root user for app installation
This commit is contained in:
commit
d00ed6cacf
3 changed files with 15 additions and 11 deletions
|
@ -416,7 +416,7 @@ def app_upgrade(auth, app=[], url=None, file=None):
|
||||||
|
|
||||||
# Execute App upgrade script
|
# Execute App upgrade script
|
||||||
os.system('chown -hR admin: %s' % INSTALL_TMP)
|
os.system('chown -hR admin: %s' % INSTALL_TMP)
|
||||||
if hook_exec(extracted_app_folder +'/scripts/upgrade', args=args_list, env=env_dict) != 0:
|
if hook_exec(extracted_app_folder + '/scripts/upgrade', args=args_list, env=env_dict, user="root") != 0:
|
||||||
logger.error(m18n.n('app_upgrade_failed', app=app_instance_name))
|
logger.error(m18n.n('app_upgrade_failed', app=app_instance_name))
|
||||||
else:
|
else:
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
@ -545,7 +545,7 @@ def app_install(auth, app, label=None, args=None, no_remove_on_failure=False):
|
||||||
try:
|
try:
|
||||||
install_retcode = hook_exec(
|
install_retcode = hook_exec(
|
||||||
os.path.join(extracted_app_folder, 'scripts/install'),
|
os.path.join(extracted_app_folder, 'scripts/install'),
|
||||||
args=args_list, env=env_dict)
|
args=args_list, env=env_dict, user="root")
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
install_retcode = -1
|
install_retcode = -1
|
||||||
except:
|
except:
|
||||||
|
@ -562,7 +562,7 @@ def app_install(auth, app, label=None, args=None, no_remove_on_failure=False):
|
||||||
# Execute remove script
|
# Execute remove script
|
||||||
remove_retcode = hook_exec(
|
remove_retcode = hook_exec(
|
||||||
os.path.join(extracted_app_folder, 'scripts/remove'),
|
os.path.join(extracted_app_folder, 'scripts/remove'),
|
||||||
args=[app_instance_name], env=env_dict_remove)
|
args=[app_instance_name], env=env_dict_remove, user="root")
|
||||||
if remove_retcode != 0:
|
if remove_retcode != 0:
|
||||||
logger.warning(m18n.n('app_not_properly_removed',
|
logger.warning(m18n.n('app_not_properly_removed',
|
||||||
app=app_instance_name))
|
app=app_instance_name))
|
||||||
|
@ -632,7 +632,7 @@ def app_remove(auth, app):
|
||||||
env_dict["YNH_APP_INSTANCE_NAME"] = app
|
env_dict["YNH_APP_INSTANCE_NAME"] = app
|
||||||
env_dict["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
|
env_dict["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
|
||||||
|
|
||||||
if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, env=env_dict) == 0:
|
if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, env=env_dict, user="root") == 0:
|
||||||
logger.success(m18n.n('app_removed', app=app))
|
logger.success(m18n.n('app_removed', app=app))
|
||||||
|
|
||||||
if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path)
|
if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path)
|
||||||
|
|
|
@ -234,7 +234,7 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
env_dict["YNH_APP_BACKUP_DIR"] = tmp_app_bkp_dir
|
env_dict["YNH_APP_BACKUP_DIR"] = tmp_app_bkp_dir
|
||||||
|
|
||||||
hook_exec(tmp_script, args=[tmp_app_bkp_dir, app_instance_name],
|
hook_exec(tmp_script, args=[tmp_app_bkp_dir, app_instance_name],
|
||||||
raise_on_error=True, chdir=tmp_app_bkp_dir, env=env_dict)
|
raise_on_error=True, chdir=tmp_app_bkp_dir, env=env_dict, user="root")
|
||||||
except:
|
except:
|
||||||
logger.exception(m18n.n('backup_app_failed', app=app_instance_name))
|
logger.exception(m18n.n('backup_app_failed', app=app_instance_name))
|
||||||
# Cleaning app backup directory
|
# Cleaning app backup directory
|
||||||
|
@ -525,7 +525,7 @@ def backup_restore(auth, name, hooks=[], ignore_hooks=False,
|
||||||
|
|
||||||
# Execute app restore script
|
# Execute app restore script
|
||||||
hook_exec(app_script, args=[tmp_app_bkp_dir, app_instance_name],
|
hook_exec(app_script, args=[tmp_app_bkp_dir, app_instance_name],
|
||||||
raise_on_error=True, chdir=tmp_app_bkp_dir, env=env_dict)
|
raise_on_error=True, chdir=tmp_app_bkp_dir, env=env_dict, user="root")
|
||||||
except:
|
except:
|
||||||
logger.exception(m18n.n('restore_app_failed', app=app_instance_name))
|
logger.exception(m18n.n('restore_app_failed', app=app_instance_name))
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ def backup_restore(auth, name, hooks=[], ignore_hooks=False,
|
||||||
# Execute remove script
|
# Execute remove script
|
||||||
# TODO: call app_remove instead
|
# TODO: call app_remove instead
|
||||||
if hook_exec(app_script, args=[app_instance_name],
|
if hook_exec(app_script, args=[app_instance_name],
|
||||||
env=env_dict_remove) != 0:
|
env=env_dict_remove, user="root") != 0:
|
||||||
logger.warning(m18n.n('app_not_properly_removed',
|
logger.warning(m18n.n('app_not_properly_removed',
|
||||||
app=app_instance_name))
|
app=app_instance_name))
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
hook_args = pre_callback(name=name, priority=priority,
|
hook_args = pre_callback(name=name, priority=priority,
|
||||||
path=path, args=args)
|
path=path, args=args)
|
||||||
hook_exec(path, args=hook_args, chdir=chdir, env=env,
|
hook_exec(path, args=hook_args, chdir=chdir, env=env,
|
||||||
no_trace=no_trace, raise_on_error=True)
|
no_trace=no_trace, raise_on_error=True, user="root")
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
state = 'failed'
|
state = 'failed'
|
||||||
logger.error(e.strerror, exc_info=1)
|
logger.error(e.strerror, exc_info=1)
|
||||||
|
@ -292,7 +292,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
|
|
||||||
|
|
||||||
def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
chdir=None, env=None):
|
chdir=None, env=None, user="admin"):
|
||||||
"""
|
"""
|
||||||
Execute hook from a file with arguments
|
Execute hook from a file with arguments
|
||||||
|
|
||||||
|
@ -303,10 +303,10 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
no_trace -- Do not print each command that will be executed
|
no_trace -- Do not print each command that will be executed
|
||||||
chdir -- The directory from where the script will be executed
|
chdir -- The directory from where the script will be executed
|
||||||
env -- Dictionnary of environment variables to export
|
env -- Dictionnary of environment variables to export
|
||||||
|
user -- User with which to run the command
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from moulinette.utils.process import call_async_output
|
from moulinette.utils.process import call_async_output
|
||||||
from yunohost.app import _value_for_locale
|
|
||||||
|
|
||||||
# Validate hook path
|
# Validate hook path
|
||||||
if path[0] != '/':
|
if path[0] != '/':
|
||||||
|
@ -327,7 +327,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
cmd_script = path
|
cmd_script = path
|
||||||
|
|
||||||
# Construct command to execute
|
# Construct command to execute
|
||||||
command = ['sudo', '-n', '-u', 'admin', '-H', 'sh', '-c']
|
if user == "root":
|
||||||
|
command = ['sh', '-c']
|
||||||
|
else:
|
||||||
|
command = ['sudo', '-n', '-u', user, '-H', 'sh', '-c']
|
||||||
|
|
||||||
if no_trace:
|
if no_trace:
|
||||||
cmd = '/bin/bash "{script}" {args}'
|
cmd = '/bin/bash "{script}" {args}'
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue