Repository navigation
feat: add staged deployment update notifier #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arpit1385
wants to merge
6
commits into
get-aurora-dev:main
Choose a base branch
from
arpit1385:feat/deployment-notifier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11e17c9
feat: add staged deployment update notifier
arpit1385 ea9317f
refactor(notifier): always-on system checks, retriggerable user service
arpit1385 376d3ea
refactor(ujust): single gum entrypoint for the update notifier
arpit1385 36faa32
refactor(notifier): dedupe check/notifier services into aurora-deploy…
arpit1385 6d3c2c7
fix(notifier): readd RemainAfterExit to the notifier service
arpit1385 5ba14df
Merge branch 'main' into feat/deployment-notifier
arpit1385 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
system_files/shared/usr/lib/systemd/system-preset/85-aurora-deployment.preset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| enable aurora-deployment-check.timer |
12 changes: 12 additions & 0 deletions
12
system_files/shared/usr/lib/systemd/system/aurora-deployment-check.timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [Unit] | ||
| Description=Periodically check for staged Aurora deployments | ||
|
|
||
| [Timer] | ||
| OnBootSec=5min | ||
| OnUnitActiveSec=1h | ||
| AccuracySec=5min | ||
| Persistent=false | ||
| Unit=aurora-deployment@check.service | ||
|
|
||
| [Install] | ||
| WantedBy=timers.target |
7 changes: 7 additions & 0 deletions
7
system_files/shared/usr/lib/systemd/system/aurora-deployment@.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [Unit] | ||
| Description=Aurora staged deployment %i | ||
| Documentation=https://docs.getaurora.dev/ | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/libexec/aurora-deployment-%i |
2 changes: 2 additions & 0 deletions
2
...m_files/shared/usr/lib/systemd/system/aurora-deployment@check.service.d/dependencies.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [Unit] | ||
| After=uupd.service rpm-ostreed.service |
2 changes: 2 additions & 0 deletions
2
system_files/shared/usr/lib/systemd/system/uupd.service.d/aurora-deployment-check.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [Unit] | ||
| OnSuccess=aurora-deployment@check.service |
10 changes: 10 additions & 0 deletions
10
system_files/shared/usr/lib/systemd/user/aurora-deployment-notifier.path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Unit] | ||
| Description=Watch for staged Aurora deployment status | ||
| Documentation=https://docs.getaurora.dev/ | ||
|
|
||
| [Path] | ||
| PathExists=/run/aurora/staged-ready | ||
| Unit=aurora-deployment@notifier.service | ||
|
|
||
| [Install] | ||
| WantedBy=default.target |
7 changes: 7 additions & 0 deletions
7
system_files/shared/usr/lib/systemd/user/aurora-deployment@.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [Unit] | ||
| Description=Aurora staged deployment %i | ||
| Documentation=https://docs.getaurora.dev/ | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/libexec/aurora-deployment-%i |
2 changes: 2 additions & 0 deletions
2
..._files/shared/usr/lib/systemd/user/aurora-deployment@notifier.service.d/dependencies.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [Unit] | ||
| After=graphical-session.target |
2 changes: 2 additions & 0 deletions
2
system_files/shared/usr/lib/systemd/user/aurora-deployment@notifier.service.d/lifetime.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [Service] | ||
| RemainAfterExit=yes |
1 change: 1 addition & 0 deletions
1
system_files/shared/usr/lib/tmpfiles.d/aurora-deployment-notifier.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| d /run/aurora 0755 root root - |
113 changes: 113 additions & 0 deletions
113
system_files/shared/usr/libexec/aurora-deployment-check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| STATUS_DIR="${AURORA_DEPLOYMENT_STATUS_DIR:-/run/aurora}" | ||
| FLAG_FILE="${STATUS_DIR}/staged-ready" | ||
| STATUS_FILE="${STATUS_DIR}/deployment-status.json" | ||
|
|
||
| SOURCE="" | ||
| STAGED_ID="" | ||
| BOOTED_ID="" | ||
|
|
||
| write_status() { | ||
| local tmpfile | ||
| tmpfile="$(mktemp "${STATUS_DIR}/deployment-status.XXXXXX")" | ||
|
|
||
| jq -n \ | ||
| --arg source "${SOURCE}" \ | ||
| --arg staged_id "${STAGED_ID}" \ | ||
| --arg booted_id "${BOOTED_ID}" \ | ||
| --arg created_at "$(date --iso-8601=seconds)" \ | ||
| '{ | ||
| ready: true, | ||
| source: $source, | ||
| staged_id: $staged_id, | ||
| booted_id: $booted_id, | ||
| created_at: $created_at | ||
| }' > "${tmpfile}" | ||
|
|
||
| chmod 0644 "${tmpfile}" | ||
| mv -f "${tmpfile}" "${STATUS_FILE}" | ||
| printf 'ready\n' > "${FLAG_FILE}" | ||
| chmod 0644 "${FLAG_FILE}" | ||
| } | ||
|
|
||
| clear_status() { | ||
| rm -f "${FLAG_FILE}" "${STATUS_FILE}" | ||
| } | ||
|
|
||
| check_bootc() { | ||
| local bootc_json | ||
| local staged_id | ||
| local booted_id | ||
|
|
||
| command -v bootc >/dev/null 2>&1 || return 1 | ||
| bootc_json="$(bootc status --json 2>/dev/null)" || return 1 | ||
|
|
||
| staged_id="$(jq -er ' | ||
| .status as $status | ||
| | select($status.staged != null and $status.staged != {}) | ||
| | ( | ||
| $status.staged.image.imageDigest | ||
| // $status.staged.image.digest | ||
| // $status.staged.ostree.checksum | ||
| // $status.staged.checksum | ||
| // ($status.staged | tostring) | ||
| ) | ||
| ' <<< "${bootc_json}" 2>/dev/null)" || return 1 | ||
|
|
||
| booted_id="$(jq -r ' | ||
| .status.booted.image.imageDigest | ||
| // .status.booted.image.digest | ||
| // .status.booted.ostree.checksum | ||
| // .status.booted.checksum | ||
| // empty | ||
| ' <<< "${bootc_json}" 2>/dev/null)" | ||
|
|
||
| if [[ -n "${staged_id}" && "${staged_id}" != "${booted_id}" ]]; then | ||
| SOURCE="bootc" | ||
| STAGED_ID="${staged_id}" | ||
| BOOTED_ID="${booted_id}" | ||
| return 0 | ||
| fi | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| check_rpm_ostree() { | ||
| local ostree_json | ||
| local staged_json | ||
| local staged_id | ||
| local booted_id | ||
|
|
||
| command -v rpm-ostree >/dev/null 2>&1 || return 1 | ||
| ostree_json="$(rpm-ostree status --json 2>/dev/null)" || return 1 | ||
|
|
||
| staged_json="$(jq -ec '[.deployments[]? | select(.staged == true)] | first // empty' <<< "${ostree_json}" 2>/dev/null)" || return 1 | ||
| [[ -n "${staged_json}" ]] || return 1 | ||
|
|
||
| staged_id="$(jq -r '.checksum // .version // .origin // tostring' <<< "${staged_json}" 2>/dev/null)" | ||
| booted_id="$(jq -r '[.deployments[]? | select(.booted == true)] | first | .checksum // .version // .origin // empty' <<< "${ostree_json}" 2>/dev/null)" | ||
|
|
||
| if [[ -n "${staged_id}" && "${staged_id}" != "${booted_id}" ]]; then | ||
| SOURCE="rpm-ostree" | ||
| STAGED_ID="${staged_id}" | ||
| BOOTED_ID="${booted_id}" | ||
| return 0 | ||
| fi | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| main() { | ||
| install -d -m 0755 -o root -g root "${STATUS_DIR}" | ||
|
|
||
| if check_bootc || check_rpm_ostree; then | ||
| write_status | ||
| else | ||
| clear_status | ||
| fi | ||
| } | ||
|
|
||
| main "$@" |
36 changes: 36 additions & 0 deletions
36
system_files/shared/usr/libexec/aurora-deployment-notifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| STATUS_DIR="${AURORA_DEPLOYMENT_STATUS_DIR:-/run/aurora}" | ||
| FLAG_FILE="${STATUS_DIR}/staged-ready" | ||
| STATUS_FILE="${STATUS_DIR}/deployment-status.json" | ||
| STATE_DIR="${XDG_STATE_HOME:-${HOME}/.local/state}/aurora/deployment-notifier" | ||
| LAST_NOTIFIED_FILE="${STATE_DIR}/last-notified" | ||
|
|
||
| [[ -f "${FLAG_FILE}" ]] || exit 0 | ||
| command -v notify-send >/dev/null 2>&1 || exit 0 | ||
|
|
||
| staged_id="" | ||
| if [[ -f "${STATUS_FILE}" ]] && command -v jq >/dev/null 2>&1; then | ||
| staged_id="$(jq -r '.staged_id // empty' "${STATUS_FILE}" 2>/dev/null || true)" | ||
| fi | ||
|
|
||
| if [[ -z "${staged_id}" ]]; then | ||
| staged_id="$(sha256sum "${FLAG_FILE}" | cut -d ' ' -f 1)" | ||
| fi | ||
|
|
||
| mkdir -p "${STATE_DIR}" | ||
|
|
||
| if [[ -f "${LAST_NOTIFIED_FILE}" ]] && [[ "$(<"${LAST_NOTIFIED_FILE}")" == "${staged_id}" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| notify-send \ | ||
| --app-name="Aurora" \ | ||
| --icon="system-software-update" \ | ||
| --urgency=normal \ | ||
| "System update ready" \ | ||
| "Restart your device to finish applying the staged Aurora update." | ||
|
|
||
| printf '%s\n' "${staged_id}" > "${LAST_NOTIFIED_FILE}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
system_files/shared/usr/share/ublue-os/just/60-aurora-deployment-notifier.just
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Toggle Aurora staged deployment desktop notifications. | ||
| [group('Aurora')] | ||
| aurora-update-notifier ACTION="prompt": | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| action="{{ ACTION }}" | ||
| user_path="aurora-deployment-notifier.path" | ||
|
|
||
| current="disabled" | ||
| if [[ "$(systemctl --user is-enabled "${user_path}" 2>/dev/null || true)" == "enabled" ]]; then | ||
| current="enabled" | ||
| fi | ||
| echo "Aurora update notifications are currently ${current}." | ||
|
|
||
| if [[ "${action}" == "prompt" ]]; then | ||
| action="$(gum choose --header="Toggle Aurora update notifications?" "Enable" "Disable" "Status" "Cancel")" | ||
| if [[ "${action}" == "Cancel" || -z "${action}" ]]; then | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| case "${action}" in | ||
| [Ee]nable|on) | ||
| systemctl --user enable --now "${user_path}" | ||
| echo "Aurora update notifications enabled." | ||
| echo "You will be notified when a staged update is ready, until you reboot into it." | ||
| ;; | ||
| [Dd]isable|off) | ||
| systemctl --user disable --now "${user_path}" || true | ||
| rm -f "${XDG_STATE_HOME:-${HOME}/.local/state}/aurora/deployment-notifier/last-notified" | ||
| echo "Aurora update notifications disabled." | ||
| ;; | ||
| [Ss]tatus) | ||
| systemctl --user --no-pager status "${user_path}" || true | ||
| if [[ -f /run/aurora/deployment-status.json ]] && command -v jq >/dev/null 2>&1; then | ||
| jq -r '"Staged deployment ready: \(.staged_id) (via \(.source))"' /run/aurora/deployment-status.json | ||
| else | ||
| echo "No staged deployment pending." | ||
| fi | ||
| ;; | ||
| *) | ||
| echo "Usage: ujust aurora-update-notifier [enable|disable|status]" | ||
| exit 2 | ||
| ;; | ||
| esac | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.