Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions biglinux-base-icons/usr/lib/biglinux-base-icons/default-avatars
Original file line number Diff line number Diff line change
@@ -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 </etc/passwd

mkdir -p "${state%/*}"
printf '%s\n' "${users[@]}" >"$state.new" && mv "$state.new" "$state" || status=1
exit "$status"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
Wants=biglinux-default-avatars.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
Wants=biglinux-default-avatars.path
1 change: 1 addition & 0 deletions pkgbuild/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions pkgbuild/biglinux-base-icons.install
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions systemd-exposure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"biglinux-default-avatars.service": 0.9
}