From c4b6b4760606c9f70c30a88c9b20474e5698cc95 Mon Sep 17 00:00:00 2001 From: Arcitec <38923130+Arcitec@users.noreply.github.com> Date: Sat, 13 May 2023 02:00:54 +0200 Subject: [PATCH] fix: switch profile.d script to more robust technique - Now uses `sh`-style single-bracket `[]` POSIX syntax instead of the truly old-school `test` syntax. Both are equivalent and equally portable. In fact, `man test` explains everything that `[]` can do. - We now symlink the user's autostart file to the uBlue image's own file, and we do it in a backwards-compatible way which replaces the user's current legacy script file (if any). The previous system dumped a permanent file in the user's home-directory which never updated again after that, which meant that OS updates could never fix or improve the autostart scripts in the future. That's now possible, thanks to being a symlink. - If the user uninstalls uBlue, or switches to a flavor without `yafti`, then the leftover "autostart" symlink will simply be a minor nuisance that only causes some soft, invisible syslog warnings about the "broken symlink", which is an improvement over the previous system which kept a full `.desktop` file that attempted to run a binary and failed to find it. --- .../firstboot/launcher/login-profile.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/usr/share/ublue-os/firstboot/launcher/login-profile.sh b/usr/share/ublue-os/firstboot/launcher/login-profile.sh index fe1d6b6..f91fd27 100644 --- a/usr/share/ublue-os/firstboot/launcher/login-profile.sh +++ b/usr/share/ublue-os/firstboot/launcher/login-profile.sh @@ -1,6 +1,15 @@ -if test "$(id -u)" -gt "0" && test -d "$HOME"; then - if test ! -e "$HOME"/.config/autostart/ublue-firstboot.desktop; then +# Only process users with home directories, but skip the "root" user. +if [ "$(id -u)" != "0" ] && [ -d "$HOME" ]; then + # Ensure target file exists and is a symlink (not a regular file or dir). + if [ ! -L "$HOME"/.config/autostart/ublue-firstboot.desktop ]; then + # Remove any leftovers or incorrect (non-link) files with the same name. + rm -rf "$HOME"/.config/autostart/ublue-firstboot.desktop + + # Create symlink to uBlue's autostart runner. + # Note that "broken autostart symlinks" are harmless if they remain + # after distro switching, and just cause a minor syslog warning. The + # user can manually delete this file if they migrate away from uBlue. mkdir -p "$HOME"/.config/autostart - cp -f /usr/etc/skel.d/.config/autostart/ublue-firstboot.desktop "$HOME"/.config/autostart + ln -s "/usr/share/ublue-os/firstboot/launcher/autostart.desktop" "$HOME"/.config/autostart/ublue-firstboot.desktop fi -fi \ No newline at end of file +fi