version: list federated packages and their newer builds
shellcheck / shellcheck (push) Successful in 19s
shellcheck / shellcheck (push) Successful in 19s
Packages from CoreDesktop's own [federated] repo, such as the top bar menu (gnome-shell-extension-coredesktop), get their own section with any newer build update would install, a rebuild of the same version included. If checkupdates couldn't sync, it says so instead of implying they're current. A GNOME Shell extension that was installed or upgraded after the user logged in says to log out and back in to use it. Its metadata's version is the same for every build, so this compares the package's install date with when the user's GNOME Shell started. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+87
-2
@@ -22,8 +22,29 @@ setup() {
|
|||||||
fetch) exit 1 ;;
|
fetch) exit 1 ;;
|
||||||
esac'
|
esac'
|
||||||
stub uname 'echo "${KERNEL:-9.9.1-arch1-1}"'
|
stub uname 'echo "${KERNEL:-9.9.1-arch1-1}"'
|
||||||
# pacman -Q <package>: the versions in $INSTALLED, "name version" per line
|
# pacman -Q <package>: the versions in $INSTALLED, "name version" per line.
|
||||||
stub pacman 'grep "^$2 " <<< "$INSTALLED" || exit 1'
|
# pacman -Sl federated: $FEDERATED's names, as installed from that repo.
|
||||||
|
# pacman -Qlq <package>: a GNOME Shell extension's files for $EXTENSION_PKG.
|
||||||
|
stub pacman 'case "$1" in
|
||||||
|
-Sl)
|
||||||
|
[ "$2" = federated ] && [ -n "$FEDERATED" ] || exit 1
|
||||||
|
for name in $FEDERATED; do
|
||||||
|
echo "federated $name $(grep "^$name " <<< "$INSTALLED" | cut -d" " -f2) [installed]"
|
||||||
|
done ;;
|
||||||
|
-Qlq)
|
||||||
|
[ "$2" = "$EXTENSION_PKG" ] || exit 1
|
||||||
|
printf "%s\n" /usr/share/gnome-shell/ /usr/share/gnome-shell/extensions/ \
|
||||||
|
/usr/share/gnome-shell/extensions/menu@example.com/ \
|
||||||
|
/usr/share/gnome-shell/extensions/menu@example.com/extension.js ;;
|
||||||
|
*) grep "^$2 " <<< "$INSTALLED" || exit 1 ;;
|
||||||
|
esac'
|
||||||
|
# This user's GNOME Shell started $SHELL_AGE seconds ago, if it's set, with
|
||||||
|
# the extensions in $ENABLED turned on
|
||||||
|
stub pgrep '[ -n "$SHELL_AGE" ] && echo 4242 || exit 1'
|
||||||
|
stub ps 'echo " $SHELL_AGE"'
|
||||||
|
stub gsettings 'echo "$ENABLED"'
|
||||||
|
export FEDERATED="" EXTENSION_PKG="" SHELL_AGE="" ENABLED="@as []"
|
||||||
|
export PACMAN_LOCAL_DB="$BATS_TEST_TMPDIR/local"
|
||||||
stub checkupdates 'printf "%s" "$PENDING"; [ -n "$PENDING" ] || exit 2'
|
stub checkupdates 'printf "%s" "$PENDING"; [ -n "$PENDING" ] || exit 2'
|
||||||
export INSTALLED="mesa 1:26.2.6-1" PENDING=""
|
export INSTALLED="mesa 1:26.2.6-1" PENDING=""
|
||||||
# The mirror synced $SYNCED_HOURS ago (an hour by default)
|
# The mirror synced $SYNCED_HOURS ago (an hour by default)
|
||||||
@@ -94,6 +115,70 @@ setup() {
|
|||||||
[[ "$output" != *"mirror"* ]]
|
[[ "$output" != *"mirror"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# installed_at PACKAGE-VERSION SECONDS_AGO: pacman's record of when it was installed
|
||||||
|
installed_at() {
|
||||||
|
mkdir -p "$PACMAN_LOCAL_DB/$1"
|
||||||
|
printf '%%NAME%%\nx\n\n%%INSTALLDATE%%\n%s\n\n' "$(( $(date +%s) - $2 ))" > "$PACMAN_LOCAL_DB/$1/desc"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version leaves out federated packages when none are installed" {
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" != *"Federated"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version lists federated packages, with newer builds, even a rebuild" {
|
||||||
|
export INSTALLED=$'mesa 1:26.2.6-1\nfederated-calendar 52.alpha.r1-1\ngnome-shell-extension-coredesktop 1:1.0.r3.g9e514eb-1'
|
||||||
|
export FEDERATED="federated-calendar gnome-shell-extension-coredesktop"
|
||||||
|
export PENDING=$'gnome-shell-extension-coredesktop 1:1.0.r3.g9e514eb-1 -> 1:1.0.r3.g9e514eb-2\n'
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"Federated packages"$'\n'" federated-calendar 52.alpha.r1-1"$'\n'* ]]
|
||||||
|
[[ "$output" == *" gnome-shell-extension-coredesktop 1.0.r3.g9e514eb-1, 1.0.r3.g9e514eb-2 is available (run update)"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version says when it couldn't check federated packages for a newer build" {
|
||||||
|
rm "$STUB_BIN/checkupdates"
|
||||||
|
stub checkupdates 'exit 1'
|
||||||
|
export INSTALLED=$'mesa 1:26.2.6-1\nfederated-calendar 52.alpha.r1-1'
|
||||||
|
export FEDERATED="federated-calendar"
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *" federated-calendar 52.alpha.r1-1, couldn't check for a newer version"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version says to log out to use an extension upgraded since login" {
|
||||||
|
export INSTALLED=$'mesa 1:26.2.6-1\ngnome-shell-extension-coredesktop 1.0.r4-1'
|
||||||
|
export FEDERATED="gnome-shell-extension-coredesktop" EXTENSION_PKG="gnome-shell-extension-coredesktop"
|
||||||
|
export SHELL_AGE=3600 ENABLED="['other@example.com', 'menu@example.com']"
|
||||||
|
installed_at gnome-shell-extension-coredesktop-1.0.r4-1 60
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *" gnome-shell-extension-coredesktop 1.0.r4-1 (newer version installed, log out and back in to use it)" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version doesn't say to log out for an extension installed before login, or turned off" {
|
||||||
|
export INSTALLED=$'mesa 1:26.2.6-1\ngnome-shell-extension-coredesktop 1.0.r4-1'
|
||||||
|
export FEDERATED="gnome-shell-extension-coredesktop" EXTENSION_PKG="gnome-shell-extension-coredesktop"
|
||||||
|
export SHELL_AGE=3600 ENABLED="['menu@example.com']"
|
||||||
|
installed_at gnome-shell-extension-coredesktop-1.0.r4-1 7200
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" != *"log out"* ]]
|
||||||
|
|
||||||
|
installed_at gnome-shell-extension-coredesktop-1.0.r4-1 60
|
||||||
|
export ENABLED="['other@example.com']"
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" != *"log out"* ]]
|
||||||
|
|
||||||
|
# Nor when GNOME Shell isn't running, e.g. over ssh
|
||||||
|
export ENABLED="['menu@example.com']" SHELL_AGE=""
|
||||||
|
run bash "$CD/version"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" != *"log out"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
# sibling_repo NAME: a sibling at v1.0.0 whose origin has a newer v1.1.0
|
# sibling_repo NAME: a sibling at v1.0.0 whose origin has a newer v1.1.0
|
||||||
sibling_repo() {
|
sibling_repo() {
|
||||||
export GIT_AUTHOR_NAME=Test GIT_AUTHOR_EMAIL=test@example.com
|
export GIT_AUTHOR_NAME=Test GIT_AUTHOR_EMAIL=test@example.com
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
# because they come from Arch, not CoreDesktop, along with any newer release of
|
# because they come from Arch, not CoreDesktop, along with any newer release of
|
||||||
# either that update would install.
|
# either that update would install.
|
||||||
#
|
#
|
||||||
|
# Packages from CoreDesktop's own [federated] repo, such as its top bar menu
|
||||||
|
# (gnome-shell-extension-coredesktop), are listed with their versions, along
|
||||||
|
# with any newer build that update would install.
|
||||||
|
#
|
||||||
# Sibling projects (see sibling) are listed with their versions too. If any has
|
# Sibling projects (see sibling) are listed with their versions too. If any has
|
||||||
# a newer version, version asks, for each one, whether to update it now.
|
# a newer version, version asks, for each one, whether to update it now.
|
||||||
#
|
#
|
||||||
@@ -93,10 +97,14 @@ upstream() {
|
|||||||
|
|
||||||
# Packages with a newer version in the repos, as "name old -> new" lines.
|
# Packages with a newer version in the repos, as "name old -> new" lines.
|
||||||
# checkupdates syncs a copy of the package database, so it needs no root and
|
# checkupdates syncs a copy of the package database, so it needs no root and
|
||||||
# doesn't leave a partial upgrade behind. Empty if it couldn't check.
|
# doesn't leave a partial upgrade behind. Empty if it couldn't check, and then
|
||||||
|
# checked is empty too: checkupdates exits 2 when there's nothing to update and
|
||||||
|
# 1 when it couldn't sync, e.g. a repo was unreachable.
|
||||||
pending=""
|
pending=""
|
||||||
|
checked=""
|
||||||
if command -v checkupdates &> /dev/null; then
|
if command -v checkupdates &> /dev/null; then
|
||||||
pending="$(timeout 30 checkupdates 2> /dev/null)"
|
pending="$(timeout 30 checkupdates 2> /dev/null)"
|
||||||
|
case $? in 0 | 2) checked=1 ;; esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print the newer upstream version of package $1 if the repos have one. A
|
# Print the newer upstream version of package $1 if the repos have one. A
|
||||||
@@ -111,6 +119,18 @@ newer_package() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print the newer version of package $1 if the repos have one, even a rebuild
|
||||||
|
# of the same version. For CoreDesktop's own packages that's usually a fix.
|
||||||
|
newer_build() {
|
||||||
|
local name old _ new
|
||||||
|
while read -r name old _ new; do
|
||||||
|
[ "$name" = "$1" ] || continue
|
||||||
|
echo "${new#*:}"
|
||||||
|
return
|
||||||
|
done <<< "$pending"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
kernel="$(uname -r)"
|
kernel="$(uname -r)"
|
||||||
# The package the running kernel came from (linux, linux-lts, ...)
|
# The package the running kernel came from (linux, linux-lts, ...)
|
||||||
kernel_pkg="$(cat "/usr/lib/modules/$kernel/pkgbase" 2> /dev/null)"
|
kernel_pkg="$(cat "/usr/lib/modules/$kernel/pkgbase" 2> /dev/null)"
|
||||||
@@ -144,6 +164,52 @@ for pkg in nvidia-utils nvidia-580xx-utils mesa; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# When this user's GNOME Shell started, i.e. when they logged in, in seconds
|
||||||
|
# since the epoch. Empty if it isn't running.
|
||||||
|
shell_started=""
|
||||||
|
shell_pid="$(pgrep -u "$(id -u)" -xo gnome-shell 2> /dev/null)"
|
||||||
|
if [ -n "$shell_pid" ] && shell_age="$(ps -o etimes= -p "$shell_pid" 2> /dev/null)"; then
|
||||||
|
shell_age="${shell_age// /}"
|
||||||
|
[[ "$shell_age" =~ ^[0-9]+$ ]] && shell_started=$(( $(date +%s) - shell_age ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# pacman's record of installed packages, which says when each was installed
|
||||||
|
PACMAN_LOCAL_DB="${PACMAN_LOCAL_DB:-/var/lib/pacman/local}"
|
||||||
|
|
||||||
|
# True if package $1, at version $2, is a GNOME Shell extension this user has
|
||||||
|
# turned on, installed or upgraded after they logged in. GNOME Shell loads an
|
||||||
|
# extension's code only at login, so it's still running the older version.
|
||||||
|
# (The extension's metadata only has a version like 1.0, the same for every
|
||||||
|
# build, so the running shell can't say which build it loaded.)
|
||||||
|
extension_needs_login() {
|
||||||
|
local pkg="$1" ver="$2" uuid installed
|
||||||
|
[ -n "$shell_started" ] || return 1
|
||||||
|
uuid="$(pacman -Qlq "$pkg" 2> /dev/null |
|
||||||
|
sed -n 's|^/usr/share/gnome-shell/extensions/\([^/]\{1,\}\)/$|\1|p' | head -1)"
|
||||||
|
[ -n "$uuid" ] || return 1
|
||||||
|
[[ "$(gsettings get org.gnome.shell enabled-extensions 2> /dev/null)" == *"'$uuid'"* ]] || return 1
|
||||||
|
installed="$(sed -n '/^%INSTALLDATE%$/{n;p;q}' "$PACMAN_LOCAL_DB/$pkg-$ver/desc" 2> /dev/null)"
|
||||||
|
[[ "$installed" =~ ^[0-9]+$ ]] && (( installed > shell_started ))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Installed packages from the [federated] repo, as "name<TAB>version" lines,
|
||||||
|
# the version without its epoch but with its pkgrel, since a rebuild counts
|
||||||
|
federated=()
|
||||||
|
while read -r name; do
|
||||||
|
installed="$(pacman -Q "$name" 2> /dev/null)" || continue
|
||||||
|
installed="${installed#* }"
|
||||||
|
line="${installed#*:}"
|
||||||
|
if extension_needs_login "$name" "$installed"; then
|
||||||
|
line="$line (newer version installed, log out and back in to use it)"
|
||||||
|
fi
|
||||||
|
if [ -z "$checked" ]; then
|
||||||
|
line="$line, couldn't check for a newer version"
|
||||||
|
elif latest="$(newer_build "$name")"; then
|
||||||
|
line="$line, $latest is available (run update)"
|
||||||
|
fi
|
||||||
|
federated+=("$name"$'\t'"$line")
|
||||||
|
done < <(pacman -Sl federated 2> /dev/null | awk '$4 ~ /^\[installed/ { print $2 }')
|
||||||
|
|
||||||
# 10-pacman.sh rewrites this log on every update
|
# 10-pacman.sh rewrites this log on every update
|
||||||
if [ -f "$PACMAN_UPDATE_LOG" ]; then
|
if [ -f "$PACMAN_UPDATE_LOG" ]; then
|
||||||
last_update="$(date -r "$PACMAN_UPDATE_LOG" '+%Y-%m-%d %H:%M')"
|
last_update="$(date -r "$PACMAN_UPDATE_LOG" '+%Y-%m-%d %H:%M')"
|
||||||
@@ -164,6 +230,19 @@ echo "Kernel $kernel"
|
|||||||
[ -n "$driver" ] && echo "Video driver $driver"
|
[ -n "$driver" ] && echo "Video driver $driver"
|
||||||
echo "Last update $last_update"
|
echo "Last update $last_update"
|
||||||
|
|
||||||
|
if (( ${#federated[@]} > 0 )); then
|
||||||
|
echo
|
||||||
|
echo "Federated packages"
|
||||||
|
width=0
|
||||||
|
for entry in "${federated[@]}"; do
|
||||||
|
name="${entry%%$'\t'*}"
|
||||||
|
(( ${#name} > width )) && width=${#name}
|
||||||
|
done
|
||||||
|
for entry in "${federated[@]}"; do
|
||||||
|
printf ' %-*s %s\n' "$width" "${entry%%$'\t'*}" "${entry#*$'\t'}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
newer_siblings=()
|
newer_siblings=()
|
||||||
if [ -n "$siblings" ]; then
|
if [ -n "$siblings" ]; then
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user