From 8148f23898638d7798f30ba7ffc111c85042b59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Gon=C3=A7alves?= Date: Wed, 25 Nov 2026 13:00:11 -0300 Subject: [PATCH] Give new users a BigLinux avatar sddm-fix assigned the avatars, so systems without SDDM never got one. The package that ships them now gives each new user one at random through AccountsService, unless the account was created with a picture. It runs whenever /etc/passwd changes and at boot, for users an installer created offline. The install script records the users already there, so existing accounts keep what they have. --- .../lib/biglinux-base-icons/default-avatars | 51 +++++++++++++++++++ .../system/biglinux-default-avatars.path | 8 +++ .../system/biglinux-default-avatars.service | 37 ++++++++++++++ .../biglinux-default-avatars.conf | 2 + .../biglinux-default-avatars.conf | 2 + pkgbuild/PKGBUILD | 1 + pkgbuild/biglinux-base-icons.install | 8 +++ systemd-exposure.json | 3 ++ 8 files changed, 112 insertions(+) create mode 100755 biglinux-base-icons/usr/lib/biglinux-base-icons/default-avatars create mode 100644 biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.path create mode 100644 biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.service create mode 100644 biglinux-base-icons/usr/lib/systemd/system/multi-user.target.d/biglinux-default-avatars.conf create mode 100644 biglinux-base-icons/usr/lib/systemd/system/paths.target.d/biglinux-default-avatars.conf create mode 100644 pkgbuild/biglinux-base-icons.install create mode 100644 systemd-exposure.json diff --git a/biglinux-base-icons/usr/lib/biglinux-base-icons/default-avatars b/biglinux-base-icons/usr/lib/biglinux-base-icons/default-avatars new file mode 100755 index 0000000..64ee05f --- /dev/null +++ b/biglinux-base-icons/usr/lib/biglinux-base-icons/default-avatars @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Gives each new user a BigLinux avatar, chosen at random, unless AccountsService +# already holds a picture for it. A user is new when the previous run did not see +# it; the first run only records the users already there. + +state=/var/lib/biglinux-base-icons/users +icons=/var/lib/AccountsService/icons +avatars=(/usr/share/plasma/avatars/big*.png) +[[ -f ${avatars[0]} ]] || exit 0 + +# Sets the avatar through AccountsService, which login screens and account +# settings read, unless it already reports a picture. +give_avatar() { + local name=$1 uid=$2 reply path picture + reply=$(busctl call org.freedesktop.Accounts /org/freedesktop/Accounts \ + org.freedesktop.Accounts FindUserById x "$uid") || return + # busctl prints the reply's type, a space and the value in quotes. + path=${reply:3:-1} + reply=$(busctl get-property org.freedesktop.Accounts "$path" org.freedesktop.Accounts.User IconFile) || return + [[ -f ${reply:3:-1} ]] && return + # SDDM reads the picture from this file, not from AccountsService. + picture=$icons/$name + [[ -f $picture ]] || cp "${avatars[RANDOM % ${#avatars[@]}]}" "$picture" || return + busctl call org.freedesktop.Accounts "$path" org.freedesktop.Accounts.User SetIconFile s "$picture" +} + +declare -A seen +first_run=1 +if [[ -f $state ]]; then + first_run=0 + while read -r name; do + [[ -n $name ]] && seen[$name]=1 + done <"$state" +fi + +status=0 +users=() +while IFS=: read -r name _ uid _; do + # 65534 is nobody; the accounts below 1000 belong to system services. + ((uid >= 1000 && uid != 65534)) || continue + # A user whose avatar failed stays out of the list, so the next run retries. + if ((first_run)) || [[ -v seen[$name] ]] || give_avatar "$name" "$uid"; then + users+=("$name") + else + status=1 + fi +done "$state.new" && mv "$state.new" "$state" || status=1 +exit "$status" diff --git a/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.path b/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.path new file mode 100644 index 0000000..7a06d78 --- /dev/null +++ b/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.path @@ -0,0 +1,8 @@ +# useradd and the account settings rewrite /etc/passwd, so a new user gets a +# picture right away; the service's boot run covers users made offline. +[Unit] +Description=Watch for new users to give them a BigLinux avatar + +[Path] +PathChanged=/etc/passwd +Unit=biglinux-default-avatars.service diff --git a/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.service b/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.service new file mode 100644 index 0000000..5e97662 --- /dev/null +++ b/biglinux-base-icons/usr/lib/systemd/system/biglinux-default-avatars.service @@ -0,0 +1,37 @@ +[Unit] +Description=Give new users a BigLinux avatar +ConditionPathExists=/usr/share/dbus-1/system-services/org.freedesktop.Accounts.service +Before=display-manager.service + +[Service] +Type=oneshot +# A user whose avatar is not set in time is retried on the next run. +TimeoutStartSec=15s +ExecStart=/usr/lib/biglinux-base-icons/default-avatars +ProtectSystem=strict +ReadWritePaths=/var/lib/AccountsService/icons +StateDirectory=biglinux-base-icons +ProtectHome=yes +CapabilityBoundingSet= +PrivateTmp=yes +PrivateDevices=yes +PrivateNetwork=yes +RestrictAddressFamilies=AF_UNIX +NoNewPrivileges=yes +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectKernelLogs=yes +ProtectControlGroups=yes +ProtectClock=yes +ProtectHostname=yes +ProtectProc=invisible +ProcSubset=pid +RestrictNamespaces=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +LockPersonality=yes +MemoryDenyWriteExecute=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service +SystemCallFilter=~@privileged @resources +UMask=0022 diff --git a/biglinux-base-icons/usr/lib/systemd/system/multi-user.target.d/biglinux-default-avatars.conf b/biglinux-base-icons/usr/lib/systemd/system/multi-user.target.d/biglinux-default-avatars.conf new file mode 100644 index 0000000..4574a96 --- /dev/null +++ b/biglinux-base-icons/usr/lib/systemd/system/multi-user.target.d/biglinux-default-avatars.conf @@ -0,0 +1,2 @@ +[Unit] +Wants=biglinux-default-avatars.service diff --git a/biglinux-base-icons/usr/lib/systemd/system/paths.target.d/biglinux-default-avatars.conf b/biglinux-base-icons/usr/lib/systemd/system/paths.target.d/biglinux-default-avatars.conf new file mode 100644 index 0000000..7871422 --- /dev/null +++ b/biglinux-base-icons/usr/lib/systemd/system/paths.target.d/biglinux-default-avatars.conf @@ -0,0 +1,2 @@ +[Unit] +Wants=biglinux-default-avatars.path diff --git a/pkgbuild/PKGBUILD b/pkgbuild/PKGBUILD index 2fe9a1b..eb7e96c 100644 --- a/pkgbuild/PKGBUILD +++ b/pkgbuild/PKGBUILD @@ -9,6 +9,7 @@ url="https://github.com/biglinux/biglinux-base-icons" pkgdesc="Icons and fixes to themes" source=("git+https://github.com/biglinux/biglinux-base-icons.git") md5sums=(SKIP) +install=${pkgname}.install package() { diff --git a/pkgbuild/biglinux-base-icons.install b/pkgbuild/biglinux-base-icons.install new file mode 100644 index 0000000..ccff75c --- /dev/null +++ b/pkgbuild/biglinux-base-icons.install @@ -0,0 +1,8 @@ +# The first run records the users already there; the units assign the avatars. +post_install() { + [ -e /var/lib/biglinux-base-icons/users ] || /usr/lib/biglinux-base-icons/default-avatars +} + +post_upgrade() { + post_install +} diff --git a/systemd-exposure.json b/systemd-exposure.json new file mode 100644 index 0000000..ce977bd --- /dev/null +++ b/systemd-exposure.json @@ -0,0 +1,3 @@ +{ + "biglinux-default-avatars.service": 0.9 +}