Skip to content

Commit

Permalink
feat: added uv option to create_server_installer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ-Jackson committed Dec 31, 2024
1 parent 7630ef2 commit a39ac93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 23 additions & 1 deletion create_server_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Place public keys here
ssh_authorized_keys = []
# Use uv
uv = false
# The format is TOML
""".strip()

Expand Down Expand Up @@ -58,10 +61,24 @@

doas_permission = []

uv_stub = None
if toml_config.get("uv", False):
uv_stub = pathlib.Path(f"{current_path}/uv_stub.py").read_text("utf-8").strip() + "\n"


def copy(src: str, dest: str):
if uv_stub:
src_str = pathlib.Path(src).read_text("utf-8").removeprefix("#!/usr/bin/env python3").strip()
dest_str = f'{uv_stub}{src_str}' + "\n"
pathlib.Path(dest).write_text(dest_str, 'utf-8')
else:
shutil.copy(src, dest)


for run_deploy_path in pathlib.Path(f"{current_path}/{toml_config['edition']}").glob('*.py'):
run_deploy_path = str(run_deploy_path)
run_deploy_target_path = f"opt/run-deploy/bin/{os.path.basename(run_deploy_path).removesuffix('.py')}"
shutil.copy(run_deploy_path, run_deploy_target_path)
copy(run_deploy_path, run_deploy_target_path)
os.chmod(run_deploy_target_path, 0o700)
if run_deploy_target_path.endswith("-cli"):
doas_permission.append(
Expand All @@ -75,6 +92,11 @@
if os.path.exists(f"{current_path}/{toml_config['edition']}/_opt"):
shutil.copytree(f"{current_path}/{toml_config['edition']}/_opt", "opt/run-deploy", dirs_exist_ok=True)

if uv_stub:
for python_script in pathlib.Path("opt/run-deploy/script").glob("*.py"):
python_script = str(python_script)
copy(python_script, python_script)

systemd_symlinks = []
systemd_cmd = []
systemd_paths = pathlib.Path("opt/run-deploy/systemd/system").glob("run-deploy-*")
Expand Down
5 changes: 5 additions & 0 deletions uv_stub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env -S uv run --quiet --script
# /// script
# requires-python = ">=3.13"
# dependencies = []
# ///

0 comments on commit a39ac93

Please sign in to comment.