#!/usr/bin/sh
#
# live-sway: sway specific setup for livesys
# SPDX-License-Identifier: GPL-3.0-or-later
#

SWAY_SESSION_FILE="sway.desktop"

# set up autologin for user liveuser
if [ -f /etc/sddm.conf ]; then
sed -i 's/^#User=.*/User=liveuser/' /etc/sddm.conf
sed -i "s/^#Session=.*/Session=${SWAY_SESSION_FILE}/" /etc/sddm.conf
else
cat > /etc/sddm.conf << SDDM_EOF
[Autologin]
User=liveuser
Session=${SWAY_SESSION_FILE}
SDDM_EOF
fi

# Show harddisk install on the desktop
sed -i -e 's/NoDisplay=true/NoDisplay=false/' /usr/share/applications/liveinst.desktop
mkdir /home/liveuser/Desktop

# echoing type liveinst to start the installer
echo "echo 'Please type liveinst and press Enter to start the installer'" >> /home/liveuser/.bashrc

# use sway configuration files for live environment
if [ "$(ls /usr/share/sway/config.live.d/*.conf 2>/dev/null)" ]; then
    mkdir -p /home/liveuser/.config/sway/config.d/
    ln -sf -t /home/liveuser/.config/sway/config.d /usr/share/sway/config.live.d/*.conf;
fi
