69 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
a4b15378c3
setup: Fix a minor flake8 complaint
Tests:

- None

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2025-03-11 10:25:29 -07:00
Sunil Mohan Adapa
fa57610b07
setup: Fix issue with pending app update and force upgrade
Closes: #2490

- When app update and force upgrade are pending on an app, app.setup() is run
during initialization. During setup(), force upgrade is first run as expected.
However, force upgrade does not do it's job when an app needs version upgrade.
setup() then tries to run package install() for the app and fails because
configuration file prompt is pending.

Tests:

- On a fresh bookworm container, update all packages. Run freedombox and ensure
that first setup has been completed. Stop freedombox and increment the firewall
app version. Then change sources.list and change bookworm to testing. Run apt
update. Then start the fredombox service. Notice that firewall app setup is run.
During the setup, force upgrader is executed. It install the newer firewall
package with the newer configuration file and performs the configuration file
changes. After that setup process continues and completes successfully.
firewalld package has been upgraded from 1.3.x to 2.3.x. firewalld service is
running. In /etc/firewalld/firewalld.conf default zone is set to external and
backend is set to nftables.

- Rerun the above test without the patches and notice that force upgrader does
not recognize firewall as a package to upgrade and setup() fails when trying to
install() packages. This is run in a loop continuously.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2025-03-10 18:58:20 -04:00
Sunil Mohan Adapa
e9adc5ce68
setup: Translate errors when installing/updating/repairing apps
- Currently, we are taking a error string and formatting it before it can be
looked up for translation. This causes the lookups to always fail.

- Don't format the error messages and send them as is. Let the
Operation.translate_message and Notification take care of translation.
Formatting will be them after translation. Set the formatting keys as they need
so that exception string is inserted into the message

Tests:

- Set language to Spanish. Through code changes raise an exception in
bepasty.privileged.setup(). Try to install bepasty app. Setup will fail and
error message will shown. The error message will be localized and formatted with
the patch. This is true in the app error message and in the notification.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-10-21 12:47:13 -04:00
James Valleroy
d87685b95a
diagnostics: Add option for automatic repair
- Not enabled by default currently. This can be changed after further
  testing.

- Re-use existing operation from diagnostics run. However, this requires
  changing the app_id of the operation for each app.

Tests:

- Enable automatic repair, and run diagnostics. See that repairs are
  run.

- Enable automatic repair, and wait for daily diagnostics run. See that
  repairs are run.

Closes: #2399.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-06-24 12:06:20 -07:00
James Valleroy
35c2326261
setup: Add method to run app repair
- Repair is run within an operation.

- Diagnostics are run for the app first.

- Call app.repair, then re-run setup if needed.

- Add helper functions for apps or components to store error messages in thread
  local storage. These error messages are shown at the end.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Undo minor reformatting, due to automatic tool]
[sunil: Fix passing incorrect Exception argument to operation.on_update]
[sunil: Add full stop at the end of the success message to match install message]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-05-02 21:46:11 -07:00
Sunil Mohan Adapa
ade2d0c8f2
package: Drop special error message handling for package errors
- We have new way to show extra details with exceptions in HTML.

- This handling of error details in PackageException is mostly unused and
unnecessary complexity.

Tests:

- Introduce exception into package.install() and package.uninstall() methods.
Test that exceptions are being shown properly in Django error messages.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-03-19 11:46:26 -04:00
Sunil Mohan Adapa
bd4ddcf158
setup: Ensure that apt is updated before checking force upgrade
If the package cache is outdated and a check is performed for whether force
upgrade is needed, it might return negative. After the operation proceeds to run
setup, we perform 'apt update' before 'apt install' at this point the
configuration file prompt will cause failure.

Tests:

- Re-run firewalld upgrade from 1.3.x to 2.1.x with a re-run setup.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-02-15 19:47:51 -05:00
Sunil Mohan Adapa
e208bdbbca
setup: Ensure that force upgrade won't run when app is not installed
- This keep the initial setup of the app simple and efficient. Setup will be
less prone to any issues in force upgrade code. There are also fewer chances for
immediate regressions.

Tests:

- Tested as part of the patch series.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-02-15 19:47:48 -05:00
Sunil Mohan Adapa
56b58174b3
setup: Minor refactoring of force upgrader class instantiation
- It is okay to instantiate before shutdown to mark shutdown initiation.

- Still keep the instantiating lazy.

Tests:

- Tested as part of patch series.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-02-15 19:47:45 -05:00
James Valleroy
29d48e86b7
setup: Try force upgrade before running app setup
Avoid running setup if it would bypass a needed force upgrade.

Fixes: #2397

Tests:

- Rerun setup on an app and see that there are no errors.

- Install modified freedombox on bookworm and perform dist-upgrade to
  testing. Then rerun setup on Firewall app. It fails with the message "App
  firewall failed to force upgrade." firewalld package is not upgraded.

- Modify Firewall app to allow force upgrade to latest version. Then rerun
  setup on Firewall app. firewalld is successfully force upgraded.

  NOTE: In this case, Firewall setup is run twice, once by force upgrade, and
  again by rerun setup.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-02-15 19:47:41 -05:00
Sunil Mohan Adapa
a233bbfd9b
operation: Add unique ID for each operation
- Helps in retrieving an operation that is currently running.

- Prevent starting an operation that is already running.

Tests:

- Unit tests work.

- Installing, uninstalling an app works.

- For upgrading an app works.

- Running background diagnostics works.

- Updating tor configuration works.

- Updating torproxy configuration works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-10-07 04:52:17 +09:00
Sunil Mohan Adapa
da9b771627
app: Implement advanced option to rerun app setup
Tests:

- Install bepasty app. Notice the extra menu option in the advanced menu.
Clicking it installs the app and run setup. Progress is shown during the re-run
of setup. When operation is completed 'App updated' notification is shown.

- Test Zoph app setup page.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-07-31 19:47:15 -04:00
Sunil Mohan Adapa
0bda4843a7
*: Use privileged decorator for package actions
Tests:

- DONE: Check if package manager is busy works
  - DONE: Power app shows status in app/restart/shutdown pages
  - DONE: Upgrades app shows in app page and first boot wizard page
  - DONE: When attempting force upgrade, busy state results in a back-off
- DONE: An app's packages can be installed/uninstalled successfully
  - DONE: apt update is run before install
  - DONE: If network is not available during package install, error message is shown
- DONE: Filtering packages with configuration file prompts works. Tested with
  firewall 1.0.3 to 1.2.1.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:54:00 -04:00
Sunil Mohan Adapa
811e95f561
setup: Implement operation to uninstall an app
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 08:28:49 -04:00
Sunil Mohan Adapa
22fef4d521
setup: Drop check for already running operation
- Currently operations manager already ensures that all operations run serially.
Even in future, operations manager is unlikely to run parallel operations on a
single app.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 08:28:42 -04:00
Sunil Mohan Adapa
492d3a463c
setup: Allow starting installation when package manager is busy
Allows multiple apps to be queued up for installation. The operation for
installing the package will wait for the package manager to become available.
Wait for 24 hours before giving up.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:34 -04:00
Sunil Mohan Adapa
4cb1477c0d
setup: Drop setup_helper and use the new Operation API
- Task of managing an operation's progress is now performed by the new Operation
class. Drop them from setup helper.

- Task of providing install() method is now moved to package module. Instead of
storing operation specific data in setup_helper like objects, store them in
thread specific storage that can retrieved anywhere during the operation without
holding references.

- Progress of an operation show as a progress bar is currently missing. This
will be regression until fixed later.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:32 -04:00
Sunil Mohan Adapa
bb2cbace6c
*: Make force upgrading part of app rather than a module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:22 -04:00
Sunil Mohan Adapa
bfa11beb73
*: pylint: Don't inherit from 'object'
- This was required in Python 2 but useless in Python 3.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:46:15 -04:00
Sunil Mohan Adapa
2752cf55d3
package: Update package expression API and fix regressions
- Make terminology more consistent managed vs. possible, resolve vs. actual.

- Fix regression in security report caused by comparing package expressions with
package names.

- Fix regression in package upgrades caused by comparing package expressions
with package names.

- Update API method names to improve readability and prevent accidental
mismatching of package names and package expressions. Update variable names for
same reason during usage.

Tests:

- minetest install successfully in testing.

- Security report shows non-zero value in the current vulnerabilities column.

- When an unavailable package is added to list of packages in an app, the app
can't be installed.

- When PackageOr expressions is added to an essential package, running
  --list-dependencies shows an expressions with '|' in it.

- Unit tests succeed.

- Find a package with conffile prompt and add that to list of a packages in an
app like bepasty and implement a stub force_upgrade() method in the app. Run
'apt update' and that triggers and analysis of packages with conf file prompts.
This should call force_upgrade() method in bepasty and with proper argument for
list of packages.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-04-10 09:51:13 -04:00
Sunil Mohan Adapa
3421469825
setup: Work on apps instead of modules for force upgrade
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:39:33 -05:00
Sunil Mohan Adapa
b9dc2d38f6
setup: Use apps instead of modules to determine running first setup
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:39:22 -05:00
Sunil Mohan Adapa
7eab8a2cda
setup: List dependencies for apps instead of modules
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:39:13 -05:00
Sunil Mohan Adapa
a0a6e1d362
setup: Run setup on apps instead of modules
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:39:01 -05:00
Sunil Mohan Adapa
cf36a9d385
*: Drop use of module level is_essential flag
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:59 -05:00
Sunil Mohan Adapa
6f791d8806
setup: Drop unused API for app's state management
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:49 -05:00
Sunil Mohan Adapa
b609abe7e5
*: Use the App's state management API
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:40 -05:00
Sunil Mohan Adapa
929e7f6dba
packages: Move checking for unavailable packages to component
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:12 -05:00
Sunil Mohan Adapa
fb40bb7f42
*: Drop module level package_conflicts and use component API
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:37:03 -05:00
Joseph Nuthalapati
6e68614e21
setup: Use packages from Packages component
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Minor refactor in listing unavailable packages, add code comment]
[sunil: Fix listing dependencies by initializing modules before call]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-11-08 16:11:34 -08:00
Fioddor Superconcentrado
4b2162f3fd
setup: Show and remove conflicts before installation
Warn of installed conflicting packages before installing apps.

[sunil: Rename 'advice' to 'action']
[sunil: Action will be string constant, for better API and i18n]
[sunil: Don't show conflict warning if action is 'ignore']
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-10-10 19:22:19 -07:00
Sunil Mohan Adapa
b32d0f17f0
*: Use allow/denylist instead white/blacklist in comments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2021-09-25 07:44:15 +05:30
Sunil Mohan Adapa
f59fc5e33b
package: Add ability to reinstall a package
- Also add ability restore missing configuration files during reinstall.

- Reinstall is useful for restoring the original configuration files of the
package.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-09-14 16:49:51 -04:00
Sunil Mohan Adapa
5d3c010b2e
main: List dependencies without writing to disk
- Don't run the second phase of web framework initialization. This avoids
writing to the DB file.

- Set log level to ERROR so that no messages get printed even to stderr while
listing dependencies.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:02:02 -04:00
Sunil Mohan Adapa
146db8344a
setup: Fix regression to force-upgrade caused by Info changes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>

Reviewed-by: Nektarios Katakis <iam@nektarioskatakis.xyz>
2020-03-17 10:08:04 +00:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Sunil Mohan Adapa
526123b6dd
setup: Better log message when no apps need upgrades
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-09-08 09:49:18 -04:00
Sunil Mohan Adapa
acdcabcbed
setup: Clarify success log message when force upgrading
Currently, in cases of ignoring an upgrade and actually upgrading, the log
message says success which is somewhat confusing. Make the force_upgrade()
methods in apps return information about ignoring the upgrade and print log
message accordingly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-08-10 09:38:49 -04:00
Nikolas Nyby
ace339eabf
Introduce flake8 checking - #58
This introduces flake8 and fixes a bunch of flake8 errors.

flake8 is run with: ./venv/bin/flake8 plinth
if you're using a python3 venv.

We can eventually further integrate this with gitlab ci.

https://salsa.debian.org/freedombox-team/plinth/issues/58

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-07-24 14:01:54 -07:00
Nikolas Nyby
d2e987ef3c
Fix a handful of typos in docs and comments
Found with [codespell](https://github.com/codespell-project/codespell/)

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-07-24 12:39:11 -07:00
Sunil Mohan Adapa
3d57feac24
setup: Pass better data structure for force upgrade operation
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-03-01 23:50:34 -05:00
Sunil Mohan Adapa
ec68eb3d89
setup: Make additional info available for force upgrading
This includes list of packages for which conffile prompts will be shown. For
each package current version of the package, new version of the package and list
of configuration files that were modified.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-28 20:48:51 -05:00
Sunil Mohan Adapa
871215abb0
setup: Rush force upgrade in development mode
- So that developers don't have to wait a long time to see the changes.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:25 -05:00
Sunil Mohan Adapa
16252a10f3
setup: Trigger force upgrade for app that implement it
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:19 -05:00
Sunil Mohan Adapa
f03336253e
setup: Filter packages to force upgrade
- Ensure that force upgrade mechanism runs only once simultaneously.

- Multiple attempts.

- Wait before first attempt and after each attempt. Shutdown properly while
  waiting.

- Only consider managed packages of apps that implement force_upgrade() hook.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:11 -05:00
Sunil Mohan Adapa
d042026314
setup: Abstraction for getting managing packages of a module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:08 -05:00
Sunil Mohan Adapa
2df02b059c
dbus: Add new module for D-Bus services
- Implement listening for CacheUpdated notification.

- Configuration to allow only root to trigger the notification.

- Trigger the notification from an apt update hook.

- Retrieve the list of packages available for upgrade and print them to log.

- Add dependency on libglib2.0-bin for the gdbus command line tool.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:05 -05:00
Sunil Mohan Adapa
920d083301
setup: Add option to handle configuration prompts during install
This is optional and does not affect normal installations. However, when
performing configuration migration in FreedomBox (due to unattended-upgrades
refusing it), it is useful as a part of strategy to read configuration, force
install new configuration files and apply configuration again. This option can
be used on such cases.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-13 06:42:50 -05:00
Sunil Mohan Adapa
65f1af7a7b
setup: Minor flake8 fixes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-01-14 17:40:22 -05:00