Skip to content

Commit

Permalink
feat: Add the option to specify external script files in addition to …
Browse files Browse the repository at this point in the history
…inline scripts
  • Loading branch information
cr7pt0gr4ph7 committed May 22, 2024
1 parent 2079eb5 commit 91e481d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ Each entry in the `checks.scripts` array must specify the following settings:

* `name`: an optional human-readable name for this check

The parameters `run` and `file` are mutually exclusive, but at least one must be specified.
The `shell` parameter is mandatory when using `run`.

The custom script should use its exit code to indicate whether the updater should proceed
(`exit code = 0`) or whether updates should be inhibited right now (any non-0 exit code).
If `message` is not specified but the script has written text to `stdout`,
Expand Down Expand Up @@ -167,6 +170,11 @@ print("Python also works when installed")
exit(1)
"""

[[checks.scripts]]
name = "Example external script"
# shell = "bash" # specifying a shell is optional for external scripts/programs
file = "/bin/true"

[notify]
dbus_notify = false # Do not show notifications
```
Expand Down
21 changes: 13 additions & 8 deletions src/ublue_update/update_inhibitors/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@


def run_custom_check_script(script) -> dict:
if script.get('shell') != 'bash':
raise Exception('checks.scripts.*.shell must be set to \'bash\'')
if 'run' in script and 'shell' not in script:
raise Exception('checks.scripts.*: \'shell\' must be specified when \'run\' is used')

if 'run' in script and 'file' in script:
raise Exception('checks.scripts.*: Only one of \'run\' and \'file\' must be set for a given script')

log.debug(f"Running script {script}")

# Run the specified custom script via bash
script_result = subprocess.run(
['bash', '-c', script['run']],
capture_output=True,
check=False,
)
# Run the specified custom script
if 'run' in script:
run_args = [script['shell'], '-c', script['run']]
elif 'shell' in script:
run_args = [script['shell'], script['file']]
else:
run_args = [script['file']]
script_result = subprocess.run(run_args, capture_output=True, text=True, check=False)

# An exit code of 0 means "OK", a non-zero exit code
# means "Do not download or perform updates right now"
Expand Down

0 comments on commit 91e481d

Please sign in to comment.