#!/bin/bash

case "$1" in
    remove)
        rm -rf /usr/share/calamares/init-ready
        echo "Removing calamares-settings..."
        if grep -q "^initer:" /etc/passwd; then
            deluser initer --remove-all-files || true
        fi
        if [ -f /etc/sddm.conf ]; then
            if [ "$(md5sum /etc/sddm.conf | awk '{print $1}')" = "a34a85f1537e91b1f892ea5e3f2c7fb0" ]; then
                if [ -d /usr/share/calamares ]; then
                    mv /etc/sddm.conf /usr/share/calamares/
                else
                    rm -rf /etc/sddm.conf
                fi            
            fi
        fi
        ;;
    purge)
        echo "Purging calamares-settings..."
        if [ -f /usr/share/calamares/sddm.conf ]; then
            if [ "$(md5sum /usr/share/calamares/sddm.conf | awk '{print $1}')" = "a34a85f1537e91b1f892ea5e3f2c7fb0" ]; then
                rm -rf /usr/share/calamares/sddm.conf
            fi
        fi
        ;;
esac

exit 0