diff --git a/bench/cli.py b/bench/cli.py index ad1c90fa..68c96f45 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -8,6 +8,7 @@ from bench.commands import bench_command logger = logging.getLogger('bench') from_command_line = False +change_uid_msg = "You should not run this command as root" def cli(): global from_command_line @@ -72,7 +73,7 @@ def change_uid(): drop_privileges(uid_name=frappe_user, gid_name=frappe_user) os.environ['HOME'] = pwd.getpwnam(frappe_user).pw_dir else: - log('You should not run this command as root', level=3) + log(change_uid_msg, level=3) sys.exit(1) def old_frappe_cli(bench_path='.'): diff --git a/bench/config/templates/frappe_sudoers b/bench/config/templates/frappe_sudoers index f87e01d5..567ccf06 100644 --- a/bench/config/templates/frappe_sudoers +++ b/bench/config/templates/frappe_sudoers @@ -1,3 +1,6 @@ +# This file is auto-generated by frappe/bench +# To re-generate this file, run "bench setup sudoers" + {% if service %} {{ user }} ALL = (root) {{ service }} {{ user }} ALL = (root) NOPASSWD: {{ service }} nginx * @@ -14,3 +17,4 @@ {{ user }} ALL = (root) NOPASSWD: /opt/certbot-auto Defaults:{{ user }} !requiretty + diff --git a/bench/patches/patches.txt b/bench/patches/patches.txt index 754068c5..7cb1a076 100644 --- a/bench/patches/patches.txt +++ b/bench/patches/patches.txt @@ -4,3 +4,4 @@ bench.patches.v3.redis_bind_ip bench.patches.v4.update_node bench.patches.v4.update_socketio bench.patches.v4.install_yarn #2 +bench.patches.v5.fix_user_permissions diff --git a/bench/patches/v5/__init__.py b/bench/patches/v5/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bench/patches/v5/fix_user_permissions.py b/bench/patches/v5/fix_user_permissions.py new file mode 100644 index 00000000..3bea08a6 --- /dev/null +++ b/bench/patches/v5/fix_user_permissions.py @@ -0,0 +1,17 @@ +# imports - standard imports +import subprocess + +# imports - module imports +from bench.utils import log, get_cmd_output, exec_cmd +from bench.cli import change_uid_msg + + +def execute(bench_path): + """fix supervisor using root then remove bench sudo later + chronology samajhiye""" + cmd = ["sudo", "-n", "bench"] + is_bench_sudoers_set = (not subprocess.call(cmd)) or (change_uid_msg in get_cmd_output(cmd)) + + if is_bench_sudoers_set: + exec_cmd("sudo bench setup supervisor --yes") + exec_cmd("sudo bench setup sudoers")