Skip to content

Commit 80b7686

Browse files
committed
feat: implement livesys setup
Signed-off-by: Zeglius <[email protected]>
1 parent 2e9c9d3 commit 80b7686

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

main.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ TITANOBOA_HOOK_PREINITRAMFS=${TITANOBOA_HOOK_PREINITRAMFS:-}
5757
# File with a list of Flatpak applications to install in the rootfs.
5858
TITANOBOA_FLATPAKS_FILE=${TITANOBOA_FLATPAKS_FILE:-}
5959

60+
TITANOBOA_TOGGLE_LIVESYS=${TITANOBOA_TOGGLE_LIVESYS:-1}
61+
6062
####### endregion PUBLIC_ENVIROMENTAL_VARS #######
6163

6264
#
@@ -102,6 +104,7 @@ _TITANOBOA_BUILDER_IMAGE := ${_TITANOBOA_BUILDER_IMAGE}
102104
_TITANOBOA_BUILDER_DISTRO := ${TITANOBOA_BUILDER_DISTRO}
103105
TITANOBOA_PREINITRAMFS_HOOK := ${TITANOBOA_PREINITRAMFS_HOOK}
104106
TITANOBOA_FLATPAKS_FILE := ${TITANOBOA_FLATPAKS_FILE}
107+
TITANOBOA_TOGGLE_LIVESYS := ${TITANOBOA_TOGGLE_LIVESYS}
105108
EOF
106109
echo "################################################################################"
107110
}
@@ -265,6 +268,20 @@ RUNEOF
265268
echo >&2 "Finished ${FUNCNAME[0]}"
266269
}
267270

271+
_rootfs_setup_livesys() {
272+
273+
echo >&2 "Executing ${FUNCNAME[0]}..."
274+
275+
if [[ $TITANOBOA_TOGGLE_LIVESYS = 1 ]]; then
276+
echo >&2 "Setting up livesys..."
277+
echo >&2 " TITANOBOA_TOGGLE_LIVESYS=$TITANOBOA_TOGGLE_LIVESYS"
278+
_chroot /bin/pkg setup-livesys
279+
echo >&2 "Finished setting up livesys"
280+
fi
281+
282+
echo >&2 "Finished ${FUNCNAME[0]}"
283+
}
284+
268285
####### endregion BUILD_STAGES #######
269286

270287
#
@@ -293,6 +310,8 @@ main() {
293310

294311
_rootfs_include_flatpaks
295312

313+
_rootfs_setup_livesys
314+
296315
echo >&2 "TODO"
297316

298317
exit

pkg

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ _pkg_setupinitramfs() {
3939
return 1
4040
}
4141

42+
# Do additional tweaks to the rootfs to be more user friendly, like creating a live user, etc.
43+
# Is redeclared depending of the package manager, with a noop declaration as fallback.
44+
_pkg_setup_livesys() {
45+
echo >&2 "WARNING: Not implemented"
46+
return 0
47+
}
48+
4249
####### endregion INTERNAL_FUNCTIONS #######
4350

4451
#
@@ -51,6 +58,7 @@ _pkg_setupinitramfs() {
5158
# install
5259
# remove
5360
# setup-initramfs
61+
# setup-livesys
5462
_command=$1
5563
shift 2>/dev/null || {
5664
echo >&2 "ERROR: missing args"
@@ -87,6 +95,51 @@ elif [ -x "$(command -v dnf)" ]; then
8795
--force "$_initramfs_path" 2>&1 | grep -v -e "Operation not supported"
8896
unset -v _INSTALLED_KERNEL
8997
}
98+
_pkg_setuplivesys() {
99+
# DNF specific setup
100+
$_PKG_MANAGER_install livesys-scripts
101+
# Determine desktop environment. Must match one of /usr/libexec/livesys/sessions.d/livesys-{desktop_env}
102+
desktop_env=""
103+
_session_file="$(find /usr/share/wayland-sessions/ /usr/share/xsessions \
104+
-maxdepth 1 -type f -not -name '*gamescope*.desktop' -and -name '*.desktop' -printf '%P' -quit)"
105+
case $_session_file in
106+
budgie*) desktop_env=budgie ;;
107+
cosmic*) desktop_env=cosmic ;;
108+
gnome*) desktop_env=gnome ;;
109+
plasma*) desktop_env=kde ;;
110+
sway*) desktop_env=sway ;;
111+
xfce*) desktop_env=xfce ;;
112+
*)
113+
echo >&2 "ERROR: No Livesys Environment Found"
114+
return 1
115+
;;
116+
esac && unset -v _session_file
117+
sed -i "s/^livesys_session=.*/livesys_session=${desktop_env}/" /etc/sysconfig/livesys
118+
# Enable services
119+
systemctl enable livesys.service livesys-late.service
120+
# Set default time zone to prevent oddities with KDE clock
121+
cat >/usr/lib/tmpfiles.d/livesys-session-extra.conf <<EOF
122+
C /var/lib/livesys/livesys-session-extra 0755 root root - /usr/share/factory/var/lib/livesys/livesys-session-extra
123+
EOF
124+
mkdir -p /usr/share/factory/var/lib/livesys
125+
cat >/usr/share/factory/var/lib/livesys/livesys-session-extra <<'EOF'
126+
#!/bin/bash
127+
128+
. /etc/os-release
129+
130+
usermod -c "$NAME User" liveuser
131+
hostnamectl hostname "$ID"
132+
133+
timedatectl set-timezone UTC
134+
ln -s /usr/share/zoneinfo/UTC /etc/localtime
135+
136+
if [ -d /var/lib/livesys/livesys-session-extra.d ]; then
137+
find /var/lib/livesys/livesys-session-extra.d -type f -exec /bin/bash {} \;
138+
fi
139+
140+
EOF
141+
chmod 0644 /usr/share/factory/var/lib/livesys/livesys-session-extra
142+
}
90143

91144
elif [ -x "$(command -v pacman)" ]; then
92145

@@ -122,6 +175,10 @@ elif [ "$_command" = "setup-initramfs" ]; then
122175

123176
_pkg_setupinitramfs $_args
124177

178+
elif [ "$_command" = "setup-livesys" ]; then
179+
180+
_pkg_setuplivesys $_args
181+
125182
else
126183
echo >&2 "ERROR: unknown command"
127184
exit 1

0 commit comments

Comments
 (0)