#!/bin/bash
#if [ -z $(grep xhost /home/oem/.config/autostart/oem-setup.desktop) ]; then
#    sudo -u oem xhost +
#fi

cleanup() {
    # fix wrong uid and gid
    echo "fixing wrong uid and gid"
    username=$(ls /home | grep -v oem)
    usermod -u 1000 "$username"
    groupmod -g 1001 "$username"
    chown -R "$username":"$username" /home/"$username"
    # tuxedo fixes
    echo "systemctl unmask packagekit.service"
    systemctl unmask packagekit.service
    echo "dpkg-reconfigure -f noninteractive keyboard-configuration"
    dpkg-reconfigure -f noninteractive keyboard-configuration
    echo "backup /etc/default/grub"
    cp /etc/default/grub /tmp/grub.default
    echo "remove all rc-flagged packages"
    apt-get -y purge $(dpkg -l | awk '/^rc/{print $2}')
    echo "make sure, /etc/default/grub is there"
    if [ ! -f /etc/default/grub ]; then
	cp /tmp/grub.default /etc/default/grub
    fi
    echo "make sure, we have snapd pinned to -1"
    if [ ! -f /etc/apt/preferences.d/10-tuxedo-snap ]; then
	cp -f /usr/share/tuxedo/oemconf/10-tuxedo-snap /etc/apt/preferences.d/
    fi
    echo "systemctl enable packagekit.service"
    systemctl enable packagekit.service
    echo "apt-mark manual cryptsetup cryptsetup-bin lvm2, we want that packages"
    apt-mark manual cryptsetup cryptsetup-bin lvm2
    /usr/bin/maliit-fix
}
cleanup

