#!/bin/sh
reso=$(xrandr | grep -m1 "*+" | awk '{ print $1 }' | cut -c -4)

if [ -z $(grep xhost /home/oem/.config/autostart/oem-setup.desktop | awk '{print $1}') ]; then
    sudo -u oem xhost +
fi

textcra="<font color=red size=5>Achtung!</font><p><font size=3>Bitte führen sie die Ersteinrichtung vollständig und ohne Unterbrechung durch.<br>Der Rechner ist erst nach einem Neustart am Ende der Einrichtung voll funktionsfähig.<br>Bitte stellen Sie sicher, dass der Rechner über genug Energie verfügt.<br>Im Zweifelsfall schließen sie ihn ans Stromnetz an. Eine LAN Verbindung ist von Vorteil.&nbsp;&nbsp;&nbsp;&nbsp;</font></p><br><font color=red size=5>Attention!</font><p><font size=3>Please carry out the initial setup completely and without interruption.<br>The computer is only fully functional after a restart at the end of the setup.<br>Please make sure that the computer has enough power.<br>If in doubt, connect it to the mains. A LAN connection is an advantage.<br><br></font></p>"

export breite=450

if [ "$reso" -ge 3840 ]; then
    export breite=850
elif [ "$reso" -ge 2400 ]; then
    export breite=650
fi

# Force Plasma themeing
export QT_PLATFORM_PLUGIN=kde
export KDE_FULL_SESSION=TRUE
export KDE_SESSION_VERSION=5
export QT_QPA_PLATFORMTHEME=Breeze

systemctl stop packagekit.service
systemctl mask packagekit.service
killall DiscoverNotifier
pkill tuxedo-control-


if [ -f /usr/bin/tomte ]; then
    while [ $(pgrep tomte| grep -v zenity) ]
    do
	echo "" > /dev/null
	sleep 1
    done | zenity --width=$breite --progress --text "tomte installiert noch fixes. Die Installation geht gleich weiter.\ntomte is installing fixes. The installation will continue afterwards" --title "tomte arbeitet / tomte is running" --no-cancel --pulsate --auto-close
fi


#kdialog --warningcontinuecancel "$textcra" --continue-label "Start" --cancel-label "Poweroff"
#if [ $? -ge 1 ]; then
#    poweroff
#fi

update-pciids

killall -9 tuxedo-tomte
systemctl stop tuxedo-tomte.timer
systemctl stop tuxedo-tomte.service
systemctl stop firstshutdown.service
systemctl stop rmfirstshutdown.service

if [ -f /etc/systemd/system/multi-user.target.wants/firstshutdown.service ]; then
    rm -f /etc/systemd/system/multi-user.target.wants/firstshutdown.service
    rm -f /etc/systemd/system/firstshutdown.service
fi
if [ -f /etc/systemd/system/multi-user.target.wants/rmfirstshutdown.service ]; then
    rm -f /etc/systemd/system/multi-user.target.wants/rmfirstshutdown.service
    rm -f /etc/systemd/system/rmfirstshutdown.service
fi

find /home/*/.config/autostart -name cryptshutdown* -delete
find /home/*/.config/autostart -name set-click* -delete
find /etc/skel/.config/autostart -name cryptshutdown* -delete
find /etc/skel/.config/autostart -name set-click* -delete
find /usr/local/bin -name cryptshutdown.sh -delete
find /usr/local/bin -name firstshutdown.sh -delete
find /usr/local/bin -name rmfirstshutdown.sh -delete


systemd-inhibit --what=idle:sleep /usr/bin/_tuxedo.calamares -d 8 --xdg-config

