#!/bin/sh -e

# Including helpers
. ./helpers.sh

# Sets ods user
log "Setting KIOSK user ..."

ODS_USR=lacaisse

# Removes boot message
log "Setting boot options in cmdline.txt ..."

# Something previsously broken, revert and restart
# if [ ! -f /boot/cmdline.bak ]; then
#     cp /boot/cmdline.txt /boot/cmdline.bak
#     cp -f /boot/ods-install/resources/cmdline.txt /boot/cmdline.txt
# fi


# Setup bootsplash
# https://linuxconfig.org/setup-bootsplash-on-debian-grub-silent-or-verbose-boot-mode
VERBOSE_MODE="GRUB_CMDLINE_LINUX_DEFAULT=\\\"\\\""
QUIET_MODE="GRUB_CMDLINE_LINUX_DEFAULT=\\\"quiet splash\\\""

# File to modify
GRUB_FILE="/etc/default/grub"

# Replace first occurrence of old_content with new_content
sed -i 's/$VERBOSE_MODE/$QUIET_MODE/g' $GRUB_FILE

sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"/g' /etc/default/grub

update-grub

# Puts a splash screen with plymouth
# plymouth-themes
## Copy files ...

sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/lacaisse/lacaisse.plymouth 100
sudo update-alternatives --config default.plymouth
sudo update-initramfs -u



# Autologin --> lightdm
/etc/lightdm/lightdm.conf




# Sets up LXDE autostart
log "Configuring LXDE autostart ..."

if [ -d /home/$ODS_USR/.config/lxsession/LXDE/ ]; then
    cp -f /boot/ods-install/resources/autostart /home/$ODS_USR/.config/lxsession/LXDE/
    chown $ODS_USR /home/$ODS_USR/.config/lxsession/LXDE/autostart
else
    log "Configuring LXDE autostart ... Error! Directory not found."
fi

# Hides trash icon
log "Configuring LXDE desktop (Hiding trash icon) ..."

if [ -d /home/$ODS_USR/.config/pcmanfm/LXDE/ ]; then
    cp -f /boot/ods-install/resources/desktop-items-0.conf /home/$ODS_USR/.config/pcmanfm/LXDE/
    chown $ODS_USR /home/$ODS_USR/.config/pcmanfm/LXDE/desktop-items-0.conf
else
    log "Configuring LXDE desktop (Hiding trash icon) ... Error! Directory not found."
fi


