373. Creating the homes
This page explains how the home of the image’s user account is made. Read it if you add a file to /etc/skel, or if a home on the live medium is missing a folder or holds a file it should not.
fs/etc/passwd declares the accounts the image ships, and the one human account, kdos, has its home at /home/kdos. The home cannot come from fs/:
- git records no owner and no empty directory;
- the
fs/copy runs in10_bootstrap, before any package exists.
script/phases/70_image/070_user.sh therefore makes the home here, from /etc/skel, once every package and the theme have written their part of that template. It also sets the modes git cannot carry on two mail files, and removes the account files’ backups.
Fixing /etc/skel first
for _s in .msmtprc .mbsyncrc; do
[ -f "/etc/skel/$_s" ] && chmod 600 "/etc/skel/$_s"
done
script/phases/70_image/070_user.sh, lines 33–35
.msmtprc and .mbsyncrc hold, or will hold, a password or the command that prints one. git records only the execute bit, so the fs/ copy lands them at mode 644. msmtp refuses to send through an .msmtprc that has a password line and is not mode 600, so both go to 600 here, after every package phase, since a port may install one of these paths as well. aerc’s accounts.conf is not shipped: aerc’s own wizard writes it at 600 on first run.
if [ -d /etc/skel/.config ]; then
find /etc/skel/.config -mindepth 1 -type d -empty -delete
fi
script/phases/70_image/070_user.sh, lines 43–45
The fs/ manifest removes files fs/ has dropped but never the directory a removal emptied, and git cannot carry an empty directory, so an empty directory under /etc/skel/.config is never one fs/ asked for. Left alone it would be copied into every home. Only .config is pruned: the generated icon and theme trees have empty directories that belong there.
The account backups
rm -f /etc/passwd- /etc/group- /etc/shadow- /etc/gshadow-
script/phases/70_image/070_user.sh, lines 52–52
shadow’s tools write /etc/passwd-, group-, shadow- and gshadow- beside each file they change, and those copies carry the password hashes of the accounts as the build left them. The image ships none of them.
Each home
while IFS=: read -r name _pw uid gid _gecos home shell; do
case "$uid" in
''|*[!0-9]*) continue ;;
esac
[ "$uid" -ge 1000 ] || continue
[ "$uid" -lt 65534 ] || continue
[ -n "$home" ] || continue
script/phases/70_image/070_user.sh, lines 54–60
The loop reads /etc/passwd and makes a home for each ordinary account: a numeric UID from 1000 to 65533, with a home directory named. The service accounts, below 1000, and any UID from 65534 up are skipped. On a KDOS root that is kdos alone.
case "$home" in
/home/.*|/home/*/*|/home/) echo "FATAL: $name's home is '$home', not one directory under /home" >&2; exit 1 ;;
/home/?*) ;;
*) echo "FATAL: $name's home is '$home', not under /home" >&2; exit 1 ;;
esac
echo " $name ($uid:$gid) -> $home"
# THE HOME IS REBUILT FROM NOTHING. This only ever runs against the build
# tree, where the home is a build artifact made of skel and the directories
# below. cp -r overwrites but never deletes, so a home kept from an earlier
# build would ship every file and directory skel or this list has since
# dropped: a launcher whose file name changed would stay under its old name
# and the app library would list the app twice.
rm -rf "$home"
mkdir -p "$home"
if [ -d /etc/skel ]; then
cp -r /etc/skel/. "$home"/ 2>/dev/null || true
fi
script/phases/70_image/070_user.sh, lines 62–79
The home is made again from nothing on every run. In the build tree it is an artifact, the template plus the directories below, and cp -r overwrites but never deletes: a home kept from an earlier build would ship every file and directory the template or the list has since dropped, such as a boxed-application launcher 030_launchers.sh renamed in /etc/skel, which the menu would then list twice. The home is written into the root the step runs in, the image stage or under KDOS_IMAGE=full build/fs, and anything edited by hand in it is gone at the next image build. A home that is not one directory directly under /home stops the build before anything is removed.
for _d in Desktop Downloads Documents Mail Music Pictures \
Pictures/Screenshots Projects Videos Public Templates .local/bin \
.local/share/applications .local/share/calendars/personal \
.local/share/addressbooks/personal; do
mkdir -p "$home/$_d"
done
script/phases/70_image/070_user.sh, lines 98–103
git cannot carry these directories either, so they are made here. Each is a directory a program expects and will not create before its first use:
| Directory | Why it is made |
|---|---|
The folders /etc/xdg/user-dirs.defaults lists (Desktop, Downloads, Documents and the rest) |
The first Plasma login’s xdg-user-dirs-update records them in ~/.config/user-dirs.dirs, and Dolphin’s Places shows them from the start |
Pictures/Screenshots |
Where Spectacle saves |
Mail |
notmuch and mbsync both name it, and both report an error rather than create it |
.local/share/calendars/personal |
The one empty calendar under the .local/share/calendars/* glob khal’s shipped configuration reads; without it, khal import has no calendar to write into |
.local/share/addressbooks/personal |
The address book khard’s configuration names. It is kept out of .local/share/contacts, because Akonadi’s default address book claims that directory and everything in it. |
.local/bin, .local/share/applications |
A user’s own commands and desktop entries |
chown -R "$uid:$gid" "$home"
chmod 0700 "$home"
script/phases/70_image/070_user.sh, lines 105–106
The copy gives the two mail files the template’s mode, 600. The whole home is then given to the account’s UID and GID, and the home directory itself is mode 0700.
Why it runs here
It runs after 030_launchers.sh and 050_theme.sh, which write into /etc/skel. Anything written into /etc/skel after this step reaches no home on the image.
What it leaves
On the image, /home/kdos, owned by kdos (1000:1000) and mode 0700, holding a copy of /etc/skel and the empty directories above; /etc/skel/.msmtprc and .mbsyncrc at 600; and no /etc/passwd-, group-, shadow- or gshadow-.
See also
- Syncing fs/: the
fs/copy and the trees/etc/skelowns - Users and groups: accounts on the running system
- Modes and owners git cannot carry: what the bootstrap sets instead