remove some installation logic from install.py
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ import yaml
|
|||||||
|
|
||||||
from ..errors import InstallError
|
from ..errors import InstallError
|
||||||
from ..paths import PobsyncPaths
|
from ..paths import PobsyncPaths
|
||||||
from ..util import ensure_dir, is_absolute_non_root, write_text_atomic
|
from ..util import ensure_dir, is_absolute_non_root
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_EXCLUDES = [
|
DEFAULT_EXCLUDES = [
|
||||||
@@ -42,19 +41,6 @@ DEFAULT_RSYNC_ARGS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Canonical entrypoint: always run code from /opt/pobsync/lib (or the given prefix).
|
|
||||||
WRAPPER_SH_TEMPLATE = """#!/bin/sh
|
|
||||||
# managed-by=pobsync install
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
PREFIX="{prefix}"
|
|
||||||
export PYTHONPATH="${{PREFIX}}/lib"
|
|
||||||
export PYTHONUNBUFFERED=1
|
|
||||||
|
|
||||||
exec /usr/bin/python3 -m pobsync "$@"
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def build_default_global_config(pobsync_home: Path, backup_root: str, retention: dict[str, int]) -> dict[str, Any]:
|
def build_default_global_config(pobsync_home: Path, backup_root: str, retention: dict[str, int]) -> dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
"backup_root": backup_root,
|
"backup_root": backup_root,
|
||||||
@@ -113,27 +99,14 @@ def write_yaml(path: Path, data: dict[str, Any], dry_run: bool, force: bool) ->
|
|||||||
return f"write {path}"
|
return f"write {path}"
|
||||||
|
|
||||||
|
|
||||||
def _install_wrapper(prefix: Path, dry_run: bool) -> list[str]:
|
|
||||||
actions: list[str] = []
|
|
||||||
|
|
||||||
bin_dir = prefix / "bin"
|
|
||||||
actions.append(f"mkdir -p {bin_dir}")
|
|
||||||
if not dry_run:
|
|
||||||
ensure_dir(bin_dir)
|
|
||||||
|
|
||||||
wrapper_path = bin_dir / "pobsync"
|
|
||||||
content = WRAPPER_SH_TEMPLATE.format(prefix=str(prefix))
|
|
||||||
|
|
||||||
actions.append(f"write {wrapper_path}")
|
|
||||||
if not dry_run:
|
|
||||||
write_text_atomic(wrapper_path, content)
|
|
||||||
os.chmod(wrapper_path, 0o755)
|
|
||||||
|
|
||||||
actions.append(f"chmod 0755 {wrapper_path}")
|
|
||||||
return actions
|
|
||||||
|
|
||||||
|
|
||||||
def _ensure_system_log_dir(dry_run: bool) -> list[str]:
|
def _ensure_system_log_dir(dry_run: bool) -> list[str]:
|
||||||
|
"""
|
||||||
|
Best-effort: create /var/log/pobsync to match cron redirection.
|
||||||
|
Not fatal if it fails (e.g., insufficient permissions in a non-root install attempt).
|
||||||
|
|
||||||
|
Note: the canonical entrypoint (/opt/pobsync/bin/pobsync) is owned by scripts/deploy.
|
||||||
|
install only prepares the runtime layout and config.
|
||||||
|
"""
|
||||||
actions: list[str] = []
|
actions: list[str] = []
|
||||||
log_dir = Path("/var/log/pobsync")
|
log_dir = Path("/var/log/pobsync")
|
||||||
actions.append(f"mkdir -p {log_dir}")
|
actions.append(f"mkdir -p {log_dir}")
|
||||||
@@ -164,10 +137,8 @@ def run_install(
|
|||||||
global_cfg = build_default_global_config(paths.home, backup_root=backup_root, retention=retention)
|
global_cfg = build_default_global_config(paths.home, backup_root=backup_root, retention=retention)
|
||||||
actions.append(write_yaml(paths.global_config_path, global_cfg, dry_run=dry_run, force=force))
|
actions.append(write_yaml(paths.global_config_path, global_cfg, dry_run=dry_run, force=force))
|
||||||
|
|
||||||
# Option A canonical install support:
|
# Install polish: ensure cron log directory exists.
|
||||||
# - Provide a stable entrypoint at /opt/pobsync/bin/pobsync (or prefix/bin/pobsync)
|
# Code + entrypoint deployment is handled by scripts/deploy.
|
||||||
# - Ensure /var/log/pobsync exists for cron redirection
|
|
||||||
actions.extend(_install_wrapper(prefix, dry_run=dry_run))
|
|
||||||
actions.extend(_ensure_system_log_dir(dry_run=dry_run))
|
actions.extend(_ensure_system_log_dir(dry_run=dry_run))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user