71 Commits

Author SHA1 Message Date
James Valleroy
ddc9b434a7
diagnostics: Add optional component_id to DiagnosticCheck
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-05-02 21:45:12 -07:00
Sunil Mohan Adapa
1612318b60
package: Don't remove packages of other apps on uninstall
Fixes: #2376.
Fixes: #2317.

When an app is removed, its packages are purged. However, there is another
installed app that needs these packages, we should keep those packages. We have
already implemented checking the packages against other apps' packages. However,
we are not checking if we are removing dependencies of other apps' packages.
This will still result in removal apps' packages.

To solve this problem, get list of packages of all the apps, then iterate over
their dependencies recursively and compile a comprehensive list of packages to
keep. Use this to reduce the set of packages to remove.

Tests:

- Without the patch, install bepasty and janus. Uninstall janus app and notice
that bepasty package is removed. With the patch, the problem is not observed.

- Printing the comprehensive list of packages to keep shows an extensive set
computed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-03-23 18:31:38 -04: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
4b09d91f93
*: Add type hints for diagnose method
Helps: #2410.

- Ensure that diagnostics methods and parameters are type checked so that we can
catch any potential issues.

- Move plinth/modules/diagnostics/check.py to plinth/diagnostic_check.py to
avoid many circular dependencies created. This is due to
plinth.modules.diagnostics automatically imported when
plinth.modules.diagnostics.check is imported. Also app.py is already (type)
dependent on diagnostic_check due to diagnose() method. To make the Check
classes independent of diagnostic module is okay.

Tests:

- Run make check-type.

- Run full diagnostics with following apps installed: torproxy, tor.
  - Test to netcat to 9051 in tor works.
  - Test 'port available for internal/external networks' in firewall works.
  - Test 'Package is latest' works.
  - Test 'Access url with proxy' in privoxy works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
[jvalleroy: Also move tests for diagnostic_check]
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2024-03-09 14:23:33 -05:00
James Valleroy
3fcd6b9e58
diagnostics: Translate descriptions only in view
Tests:

- Enable all apps, and run diagnostics. Diagnostic descriptions are formatted
  as expected.

- Change the language to Spanish, and view the diagnostic results. Diagnostic
  descriptions are translated as expected.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-01-18 22:19:05 -08:00
James Valleroy
4612df954d
diagnostics: Add parameters to DiagnosticCheck
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-01-18 22:18:47 -08:00
Sunil Mohan Adapa
465e452daf
diagnostics: Refactor check IDs, tests and background checks
- Ensure that each diagnostic test category can be identified by easy prefix
matching on the test ID.

- Give a different unique IDs each different kind of test. More specific tests
of a type get a different kind of ID.

- Make comparison of diagnostic test results in test cases more comprehensive.

- Simplify code that shows the number if issues identified.

- In many languages, there is complex logic to write plural forms. Plurals
can't be handled by assuming singular = 1 item and plural is > 1. Translation of
messages in Notification does not support plurals properly. Avoid this for now
by using sometimes incorrect plural form.

- For i18n we should avoid joining phrases/words. Words don't always maintain
order after translation.

- Notify about the total number of issues in diagnostics and not just the most
severe category. This is likely to draw more attention and avoid i18n
complexity.

- Dismiss the diagnostic notification if the latest run succeeded completely.

Tests:

- Unit tests pass.

- Diagnostics for following apps works: networks (drop-in config),
apache (daemon, listen address, internal firewall, external firewall),
tor (netcat), torproxy (internal only firewall, torproxy url, torproxy using
tor), privoxy (privoxy url, package available, package latest),

- Untested: Is release file available method in upgrades app.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-10-07 04:52:22 +09:00
James Valleroy
79f36e6a0c
diagnostics: Add DiagnosticCheck dataclass
- Set unique check_id for each diagnostic check.

- Result is a string-based enumeration. The default value (NOT_DONE) can be
  used for diagnostic checks that have not been completed yet.

- Result is StrEnum so that the return value of check_url can still be used
  directly as a diagnostic result.

Closes: #2375

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-10-07 04:52:13 +09:00
Sunil Mohan Adapa
38ece87c6c
*: Utilize newer 3.10 syntax for type hints
Tests:

- mypy does not show any errors.

- Installing ejabberd app works. Privileged actions run fine.

- Unit tests work.

- No additional testing was done as type annotations don't have any effect at
runtime.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-09-25 20:03:34 -04:00
Sunil Mohan Adapa
85bfe40c87
packages: Purge packages on uninstall
The primary reason for the existence of uninstall feature is to clean up the
existing working or non-working setup and re-install freshly. It is not to
remove the effects of the installed app since disable works well for that. It is
seldom to free up space since even on a microSD card, the space occupied by most
apps is negligible.

Tests:

- Unit tests pass

- Functional tests for all apps pass (except for known failures).

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-06-16 11:16:07 -04:00
Sunil Mohan Adapa
16cb8ee021
package: Don't uninstall packages that are in use by other apps
Closes: #2262.

Tests:

- Unit tests work

- Uninstall of email app succeeds without uninstalling openssl package.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-01-02 20:59:19 -05:00
Sunil Mohan Adapa
0b9d567493
package, email: Move conflicting package removal to framework
- Warning that exim4 will be removed is incorrectly not shown during email app
installation. Fix that.

Tests:

- Unit tests pass.

- On a fresh testing container, trying to install email app shows the warning
message that exim will be removed. Installing the email app succeeds. exim is
removed during installation.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-12-18 17:30:27 -05: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
a1c6c7b6a7
package: Implement uninstall in Package component
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 08:28:47 -04:00
Sunil Mohan Adapa
1908bd5366
package: Implement low-level methods for uninstalling
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 08:28:35 -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
c6b69b2f41
package: Run installation operation using app_id instead of module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:10 -04:00
Sunil Mohan Adapa
22a120d979
*: pylint: Avoid calling super() with arguments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:46:23 -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
James Valleroy
2537ffd64c
package: Fix comment and type annotations
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2022-04-10 08:29:35 -04:00
James Valleroy
691817477f
package: Fail diagnostic when not able to resolve
When a package expression cannot be resolved (i.e. not installable),
add a diagnostic failure result with appropriate message.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2022-04-10 08:29:34 -04:00
James Valleroy
45820fbdfa
package: Use package expressions in Packages component
- managed_packages() finds all possible packages that could be
  installed. This is used for the check in the action script.

- resolve() finds actual packages to be installed. This is used in
  setup, diagnose, and has_unavailable_packages.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2022-04-10 08:29:34 -04:00
James Valleroy
31a457029c
package: Add package expressions
- Package represents a package to potentially be installed.

- PackageOr allows an alternate package, in case the first one is not
  available.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2022-04-10 08:29:34 -04:00
Sunil Mohan Adapa
85149cb5d1
package: Add diagnostic to check if a package is the latest version
Closes: #2148.

Tests:

- For an app with older version of package installed, run diagnostics. A warning
is shown. Latest version available is shown correctly in the message.

- For an app with latest version of package installed, run diagnostics. Test
shows as passed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-01-02 11:05:03 -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
82876a6e23
package: Introduce component API for package conflicts
This is help in eliminating the module level package_conflicts declarations.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:36:53 -05:00
Sunil Mohan Adapa
d1b040cdb6
package: Implement installing packages in the component
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:34:22 -05:00
Sunil Mohan Adapa
2157cb33b7
package: Add parameter to specify skipping package recommendations
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-12-04 16:34:12 -05:00
Joseph Nuthalapati
53fbaf27f2
components: Add docstrings & tutorial for Packages
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Include the new component reference in the components index]
[sunil: Minor changes to component doc string]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-11-08 16:12:00 -08: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
Joseph Nuthalapati
cd4bd17173
components: Introduce new component - Packages
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: isort all files]
[sunil: Remove component in datetime component as managed_packages is empty]
[sunil: Minor refactor in minidlna for consistency]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-11-08 16:03:42 -08:00
Sunil Mohan Adapa
148d1ea311
package: Remove unused import to fix pipeline
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-10-10 19:43:13 -07:00
Fioddor Superconcentrado
24f7ffe3cf
package: Add functions for removing packages
Functions needed to spot and remove installed conflicting packages
before installation of apps.

- Remove all packages in a single operation as this way apt can search for
solutions to conflicts more easily.

- Use type hints rather than a lot of type checking. Type hints shall later be
enforced using offline checking (with mypy) or at runtime (with enforce, etc.).

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Run single remove operation on all packages]
[sunil: Use type hints instead of extensive type checking]
[sunil: Trim down the test case as it would only succeed after install]
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>

package
2021-10-10 19:22:16 -07:00
Sunil Mohan Adapa
74214c18ae
*: Use Django gettext functions instead of ugettext
- ugettext functions will be removed in Django 4.0. Each use emits a warning
when running with Django 3.2. Since we have warnings enabled in developer mode,
we see quite a few messages because of this.

- ugettext is already a simple alias of gettext. So, no regressions are
expected.

Tests:

- Accessing an affected app in UI with Django 3.2 and Django 2.2 works fine.

- Using Django 3.2 there are no warnings related to removal of ugettext
functions.

- Ran regular unit tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-09-20 16:50:16 -04:00
Fioddor Superconcentrado
d1f9f4bfcc
package: i18n: Mark progress status strings for translation
Help: #1938.

- package.py: ugettext_lazy applied to 'installing', 'downloading' and other
statuses.
- setup.html: trans function applied to "Check again" in template.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Mark remaining to status strings also]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-20 11:56:57 -07:00
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
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
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
c8b2ba8c99
package: Helper method to filter packages that need conffile prompt
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-02-26 06:24:17 -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
Joseph Nuthalapati
3d38b8a686
backports: Add buster-backports to apt sources list
Fixes freedombox-team/freedom-maker#149

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-02-05 14:58:27 -08:00
Joseph Nuthalapati
45138fcdf0
packages: Button to refresh package lists
- This is a fallback solution to manually refresh package lists on AWS images
  since they come with no apt package lists.
- This can also be occasionally useful for people running the testing
  distribution where packages might be frequently added and removed.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-07-02 19:30:13 -04:00
James Valleroy
c511dab7ff
package: Add option to skip recommends
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2018-07-02 19:00:24 -04:00
Sunil Mohan Adapa
79276f14df
Don't use async for method parameters
async is a reserved keyword in Python 3.7. It can no longer be used as method
parameter. Change the name so that we are ready for Python 3.7.

See: https://www.python.org/dev/peps/pep-0492/#deprecation-plans

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-24 19:14:13 +01:00
Sunil Mohan Adapa
90f2117554
Rename Plinth to FreedomBox in comments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:45 -05:00
Sunil Mohan Adapa
dea4af17fb
Rename Plinth to FreedomBox in license headers
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:09 -05:00
Vikas Singh
5c83dea442
actions: Allow not printing error when an action fails
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2018-01-30 10:57:48 +05:30