From 3613d3dd0cc9c2d3a45dcea737b552e5e5c086df Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 8 Jan 2024 20:11:26 -0500 Subject: [PATCH] Fix installed extension ownership on FreeBSD --- lib/stweak.py | 7 ++++++- port-jobs/CHOWN.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 port-jobs/CHOWN.py diff --git a/lib/stweak.py b/lib/stweak.py index baf9671..a25e891 100644 --- a/lib/stweak.py +++ b/lib/stweak.py @@ -718,7 +718,12 @@ def wrapped_entry(_gm_device_type, _gm_top_message='configuration options:'): # install with privilege escalation (outside of curses) from tempfile import gettempdir _exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini" - run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir)) + # PORT START TWEAK-EXT-CHOWN + if uname()[0] == 'FreeBSD': + run((_escalator, 'chown', 'root:wheel', _exe_dir, _ini_dir)) + else: + run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir)) + # PORT END TWEAK-EXT-CHOWN run((_escalator, 'mv', _exe_dir, f"/usr/lib/sshyp/{_ext_name}")) run((_escalator, 'mv', _ini_dir, f"/usr/lib/sshyp/extensions/{_ext_name}.ini")) else: diff --git a/port-jobs/CHOWN.py b/port-jobs/CHOWN.py new file mode 100755 index 0000000..7019f3a --- /dev/null +++ b/port-jobs/CHOWN.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import re +from sys import argv + +# read arguments +arguments = argv[1:] + +# define PORT target +string1 = '# PORT START TWEAK-EXT-CHOWN' +string2 = '# PORT END TWEAK-EXT-CHOWN' + +# define replacement text depending on arguments +if len(arguments) > 0 and arguments[0] == 'BSD': + replacement = "run((_escalator, 'chown', 'root:wheel', _exe_dir, _ini_dir))" +else: + replacement = "run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir))" + +# read input file +text = open('working/stweak.py', 'r').read() + +# compile regex and modify text +regex = re.compile(f"{string1}.*?{string2}", re.DOTALL) + +# find and replace the defined PORT target +new_text = re.sub(regex, replacement, text) + +# write updated text +open('working/stweak.py', 'w').write(new_text)