From c7fb361c00c288692a77d6414383c55e59f10ea7 Mon Sep 17 00:00:00 2001 From: Tulip Blossom Date: Tue, 7 Jan 2025 20:36:24 -0300 Subject: [PATCH] feat: add ublue-changelog script to ublue-motd package (#105) That way we get some fancy changelogs on our images!! Yay! --- ublue/motd/src/ublue-changelog | 29 +++++++++++++++++++++++++++++ ublue/motd/src/ublue-motd | 3 ++- ublue/motd/ublue-motd.spec | 14 +++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 ublue/motd/src/ublue-changelog diff --git a/ublue/motd/src/ublue-changelog b/ublue/motd/src/ublue-changelog new file mode 100755 index 0000000..e9d16dd --- /dev/null +++ b/ublue/motd/src/ublue-changelog @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +get_config() { + CHANGELOG_CONFIG_FILE="${changelog_CONFIG_FILE:-/etc/ublue-os/changelog.json}" + QUERY="$1" + FALLBACK="$2" + shift + shift + OUTPUT="$(jq -r "$QUERY" "$CHANGELOG_CONFIG_FILE" 2>/dev/null || echo "$FALLBACK")" + if [ "$OUTPUT" == "null" ] ; then + echo "$FALLBACK" + return + fi + echo "$OUTPUT" +} + +DEFAULT_THEME="$(get_config '."default-theme"' "slate")" +TARGET_URL="$(get_config '."target-url"' "invalid")" +JQ_EXPRESSION="$(get_config '."jq-expression"' ".body")" +THEMES_DIRECTORY="$(get_config '."themes-directory"' "/usr/share/ublue-os/motd/themes")" + +THEME=$(dconf read /org/gnome/desktop/interface/accent-color 2>/dev/null || printf '%s' "\'$DEFAULT_THEME\'") +THEME=${THEME//\'/} +THEME=${CHANGELOG_FORCE_THEME:-$THEME} + + +curl -s "$TARGET_URL" | \ + jq -r "$JQ_EXPRESSION" | \ + glow -s "${THEMES_DIRECTORY}/${THEME}.json" -w 78 - $@ diff --git a/ublue/motd/src/ublue-motd b/ublue/motd/src/ublue-motd index 538ddd9..8e83e83 100755 --- a/ublue/motd/src/ublue-motd +++ b/ublue/motd/src/ublue-motd @@ -54,7 +54,8 @@ KEY_WARN_FILE="/run/user-motd-sbkey-warn.md" [ -e $KEY_WARN_FILE ] && KEY_WARN="**WARNING**: $(cat $KEY_WARN_FILE)" KEY_WARN_ESCAPED=$(escape "$KEY_WARN") -THEME=$(gsettings get org.gnome.desktop.interface accent-color 2>/dev/null || printf '%s' "\'$DEFAULT_THEME\'") + +THEME=$(dconf read /org/gnome/desktop/interface/accent-color 2>/dev/null || printf '%s' "\'$DEFAULT_THEME\'") THEME=${THEME//\'/} THEME=${MOTD_FORCE_THEME:-$THEME} diff --git a/ublue/motd/ublue-motd.spec b/ublue/motd/ublue-motd.spec index 9eaf26e..872a7f7 100644 --- a/ublue/motd/ublue-motd.spec +++ b/ublue/motd/ublue-motd.spec @@ -1,7 +1,7 @@ %global debug_package %{nil} Name: ublue-motd -Version: 0.1.0 +Version: 0.2.0 Release: 1%{?dist} Summary: MOTD scripts for Universal Blue images @@ -11,22 +11,26 @@ VCS: {{{ git_dir_vcs }}} Source: {{{ git_dir_pack }}} Requires: glow +Requires: jq +Requires: curl %description -MOTD script for Universal Blue +MOTD and changelogs script for Universal Blue %prep {{{ git_dir_setup_macro }}} %install -install -Dm0755 ./src/ublue-motd %{buildroot}%{_libexecdir}/ublue-motd -install -dm 0755 %{buildroot}%{_datadir}/ublue-os/motd/themes +install -dm0755 %{buildroot}%{_datadir}/ublue-os/motd/themes cp -rp ./src/themes/* %{buildroot}%{_datadir}/ublue-os/motd/themes +install -Dm0755 ./src/%{name} %{buildroot}%{_libexecdir}/%{name} +install -Dm0755 ./src/ublue-changelog %{buildroot}%{_libexecdir}/ublue-changelog install -Dm0755 ./src/vendor.sh %{buildroot}%{_sysconfdir}/profile.d/%{name}.sh install -Dm0755 ./src/vendor.fish %{buildroot}%{_datadir}/fish/vendor_conf.d/%{name}.fish %files -%{_libexecdir}/ublue-motd +%{_libexecdir}/%{name} +%{_libexecdir}/ublue-changelog %{_datadir}/ublue-os/motd/themes/* %{_sysconfdir}/profile.d/%{name}.sh %{_datadir}/fish/vendor_conf.d/%{name}.fish