mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
privileged_daemon: Introduce a command line client for the API
- Similar call signature as actions/actions.
Tests:
- Running make install places a binary file in /usr/bin/freedombox-cmd
- Running 'freedombox-cmd upgrades get_log --no-args' works.
- Running 'freedombox-cmd upgrades activate_backports --no-args' works.
- Running 'freedombox-cmd storage usage_info --no-args' works.
- Running 'freedombox-cmd sshfs is_mounted --no-args' works.
- echo '{"args": ["USERNAME", "AUTH_USER", "AUTH_PASSWORD"], "kwargs": {}}' |
sudo freedombox-cmd users remove_user.
- Distribution upgrade from Bookworm to Trixie works.
- Snapshots are disabled and re-enabled during upgrade.
- /etc/apt/sources.list changes are completed on completion.
- If a command fails, the return code is not 0.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
1 parent
143e4a00bd
commit
a580437de2
11 files changed
+83
-33
No files matched your search
@@ -146,12 +146,12 @@ def mount(mountpoint: str, remote_path: str, ssh_keyfile: str | None = None,
|
||||
# 'reconnect', 'ServerAliveInternal' and 'ServerAliveCountMax' allow the
|
||||
# client (FreedomBox) to keep control of the SSH connection even when the
|
||||
# SSH server misbehaves. Without these options, other commands such as
|
||||
# '/usr/share/plinth/actions/actions storage usage_info --no-args', 'df',
|
||||
# '/usr/share/plinth/actions/actions sshfs is_mounted --no-args', or
|
||||
# 'mountpoint' might block indefinitely (even when manually invoked from
|
||||
# the command line). This situation has some lateral effects, causing major
|
||||
# system instability in the course of ~11 days, and leaving the system in
|
||||
# such state that the only solution is a reboot.
|
||||
# 'freedombox-cmd storage usage_info --no-args', 'df', 'freedombox-cmd
|
||||
# sshfs is_mounted --no-args', or 'mountpoint' might block indefinitely
|
||||
# (even when manually invoked from the command line). This situation has
|
||||
# some lateral effects, causing major system instability in the course of
|
||||
# ~11 days, and leaving the system in such state that the only solution is
|
||||
# a reboot.
|
||||
cmd = [
|
||||
'sshfs', remote_path, mountpoint, '-o',
|
||||
f'UserKnownHostsFile={user_known_hosts_file}', '-o',
|
||||
|
||||
@@ -247,7 +247,7 @@ def _snapshot_run_and_disable() -> Generator[None, None, None]:
|
||||
if snapshot_module.is_apt_snapshots_enabled(aug):
|
||||
logger.info('Disabling apt snapshots during dist upgrade...')
|
||||
subprocess.run([
|
||||
'/usr/share/plinth/actions/actions',
|
||||
'/usr/bin/freedombox-cmd',
|
||||
'snapshot',
|
||||
'disable_apt_snapshot',
|
||||
], input='{"args": ["yes"], "kwargs": {}}'.encode(), check=True)
|
||||
@@ -260,8 +260,7 @@ def _snapshot_run_and_disable() -> Generator[None, None, None]:
|
||||
if reenable:
|
||||
logger.info('Re-enabling apt snapshots...')
|
||||
subprocess.run([
|
||||
'/usr/share/plinth/actions/actions', 'snapshot',
|
||||
'disable_apt_snapshot'
|
||||
'/usr/bin/freedombox-cmd', 'snapshot', 'disable_apt_snapshot'
|
||||
], input='{"args": ["no"], "kwargs": {}}'.encode(), check=True)
|
||||
else:
|
||||
logger.info('Not re-enabling apt snapshots, as they were disabled '
|
||||
@@ -388,8 +387,8 @@ def _trigger_on_complete():
|
||||
subprocess.run([
|
||||
'systemd-run', '--unit=freedombox-dist-upgrade-on-complete',
|
||||
'--description=Finish up upgrade to new stable Debian release',
|
||||
'/usr/share/plinth/actions/actions', 'upgrades',
|
||||
'dist_upgrade_on_complete', '--no-args'
|
||||
'/usr/bin/freedombox-cmd', 'upgrades', 'dist_upgrade_on_complete',
|
||||
'--no-args'
|
||||
], check=True)
|
||||
|
||||
|
||||
@@ -443,7 +442,7 @@ def start_service():
|
||||
f'--property=BindPaths={temp_sources_list}:{sources_list}'
|
||||
]
|
||||
subprocess.run(['systemd-run'] + args + [
|
||||
'systemd-inhibit', '/usr/share/plinth/actions/actions', 'upgrades',
|
||||
'systemd-inhibit', '/usr/bin/freedombox-cmd', 'upgrades',
|
||||
'dist_upgrade', '--no-args'
|
||||
], check=True)
|
||||
|
||||
|
||||
@@ -266,17 +266,14 @@ def test_snapshot_run_and_disable(is_supported, is_apt_snapshots_enabled, run):
|
||||
call(['snapper', 'create', '--description', 'before dist-upgrade'],
|
||||
check=True),
|
||||
call([
|
||||
'/usr/share/plinth/actions/actions', 'snapshot',
|
||||
'disable_apt_snapshot'
|
||||
'/usr/bin/freedombox-cmd', 'snapshot', 'disable_apt_snapshot'
|
||||
], input=b'{"args": ["yes"], "kwargs": {}}', check=True)
|
||||
]
|
||||
run.reset_mock()
|
||||
|
||||
assert run.call_args_list == [
|
||||
call([
|
||||
'/usr/share/plinth/actions/actions', 'snapshot',
|
||||
'disable_apt_snapshot'
|
||||
], input=b'{"args": ["no"], "kwargs": {}}', check=True)
|
||||
call(['/usr/bin/freedombox-cmd', 'snapshot', 'disable_apt_snapshot'],
|
||||
input=b'{"args": ["no"], "kwargs": {}}', check=True)
|
||||
]
|
||||
|
||||
|
||||
@@ -419,8 +416,8 @@ def test_trigger_on_complete(run):
|
||||
run.assert_called_with([
|
||||
'systemd-run', '--unit=freedombox-dist-upgrade-on-complete',
|
||||
'--description=Finish up upgrade to new stable Debian release',
|
||||
'/usr/share/plinth/actions/actions', 'upgrades',
|
||||
'dist_upgrade_on_complete', '--no-args'
|
||||
'/usr/bin/freedombox-cmd', 'upgrades', 'dist_upgrade_on_complete',
|
||||
'--no-args'
|
||||
], check=True)
|
||||
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@
|
||||
{% blocktrans trimmed %}
|
||||
Delete these accounts from command line and refresh the page to create
|
||||
an account that is usable with {{ box_name }}. On the command line run
|
||||
the command "echo '{"args": ["USERNAME", "PASSWORD"], "kwargs": {}}' |
|
||||
sudo /usr/share/plinth/actions/actions users remove_user". If an
|
||||
account is already usable with {{ box_name }}, skip this step.
|
||||
the command "echo '{"args": ["USERNAME", "AUTH_USER", "AUTH_PASSWORD"],
|
||||
"kwargs": {}}' | sudo freedombox-cmd users remove_user". If an account
|
||||
is already usable with {{ box_name }}, skip this step.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
|
||||
Reference in new issue
Block a user