mirror of
https://github.com/trustedsec/hate_crack.git
synced 2026-04-28 12:03:11 -07:00
feat(update): install system deps (transmission-daemon/p7zip) on upgrade
Add _install_system_deps() called by _run_upgrade() after a successful git pull. Installs transmission-daemon (Linux) or transmission-cli brew formula (macOS) so users who upgrade don't need to re-run make install manually. Also corrects _run_upgrade to exit 1 on failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -946,6 +946,25 @@ def ascii_art():
|
||||
)
|
||||
|
||||
|
||||
def _install_system_deps():
|
||||
"""Best-effort install of system dependencies after an upgrade."""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
plat = sys.platform
|
||||
if plat == "darwin":
|
||||
if subprocess.run(["which", "brew"], capture_output=True).returncode == 0:
|
||||
print(" Installing/updating system dependencies via Homebrew...")
|
||||
subprocess.run(["brew", "install", "transmission-cli", "p7zip"])
|
||||
else:
|
||||
print(" [!] Homebrew not found — install transmission-cli and p7zip manually.")
|
||||
elif plat.startswith("linux"):
|
||||
print(" Installing/updating system dependencies via apt-get...")
|
||||
subprocess.run(["sudo", "apt-get", "install", "-y", "transmission-daemon", "p7zip-full"])
|
||||
else:
|
||||
print(f" [!] Unknown platform '{plat}' — install transmission-daemon and p7zip manually.")
|
||||
|
||||
|
||||
def _run_upgrade():
|
||||
"""Run `git pull && make clean && make && make install` in the repo root."""
|
||||
import subprocess
|
||||
@@ -986,10 +1005,12 @@ def _run_upgrade():
|
||||
shell=True,
|
||||
cwd=repo_root,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
print("\n Upgrade complete. Please restart hate_crack.\n")
|
||||
else:
|
||||
if result.returncode != 0:
|
||||
print("\n Upgrade failed. Check the output above for errors.\n")
|
||||
raise SystemExit(1)
|
||||
|
||||
_install_system_deps()
|
||||
print("\n Upgrade complete. Please restart hate_crack.\n")
|
||||
raise SystemExit(0)
|
||||
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ class TestCheckForUpdates:
|
||||
"subprocess.run", side_effect=[git_root_proc, make_proc]
|
||||
) as mock_run, patch("shutil.which", return_value="/usr/local/bin/uv"), patch(
|
||||
"os.path.isfile", return_value=True
|
||||
), pytest.raises(
|
||||
), patch.object(hc_module, "_install_system_deps"), pytest.raises(
|
||||
SystemExit
|
||||
):
|
||||
mock_requests.get.return_value = mock_resp
|
||||
@@ -236,7 +236,9 @@ class TestRunUpgrade:
|
||||
make_proc = MagicMock()
|
||||
make_proc.returncode = 0
|
||||
|
||||
with patch("subprocess.run", side_effect=[git_root_proc, make_proc]) as mock_run, pytest.raises(SystemExit) as exc:
|
||||
with patch("subprocess.run", side_effect=[git_root_proc, make_proc]) as mock_run, \
|
||||
patch.object(hc_module, "_install_system_deps"), \
|
||||
pytest.raises(SystemExit) as exc:
|
||||
hc_module._run_upgrade()
|
||||
|
||||
assert exc.value.code == 0
|
||||
@@ -259,7 +261,7 @@ class TestRunUpgrade:
|
||||
with patch("subprocess.run", side_effect=[git_root_proc, make_proc]), pytest.raises(SystemExit) as exc:
|
||||
hc_module._run_upgrade()
|
||||
|
||||
assert exc.value.code == 0
|
||||
assert exc.value.code == 1
|
||||
output = capsys.readouterr().out
|
||||
assert "Upgrade failed" in output
|
||||
|
||||
|
||||
Reference in New Issue
Block a user