#!/bin/sh
set -e

# Tag to allow some debhelper commands to inject relevant code
# Automatically added by dh_installdeb/12
dpkg-maintscript-helper rm_conffile /etc/default/kdm.d/10_desktop-base 9.0.0\~ desktop-base -- "$@"
# End automatically added section


if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then

    # Remove background alternatives for theme packages
    while read theme filename; do
        update-alternatives --remove \
            desktop-background \
            /usr/share/desktop-base/$theme-theme/wallpaper/contents/images/$filename
    done << EOF
e-legance 1920x1080.svg
EOF
    # *Last* remove background *highest priority* alternatives for active theme
    update-alternatives --auto desktop-background 

    # Remove desktop-background.xml alternatives
    # For theme packages
    while read theme; do
        update-alternatives --remove \
            desktop-background.xml \
            /usr/share/desktop-base/$theme-theme/wallpaper/gnome-background.xml
    done << EOF
e-legance
EOF
    # *Lastly* reset *highest priority* alternative for active theme
    update-alternatives --auto \
        desktop-background.xml 

    # Remove desktop-lockscreen.xml alternatives
    # For theme packages
    while read theme; do
        update-alternatives --remove \
            desktop-lockscreen.xml \
            /usr/share/desktop-base/$theme-theme/lockscreen/gnome-background.xml
    done << EOF
e-legance
EOF
    # *Last* reset *highest priority* alternative for active theme
    update-alternatives --auto \
        desktop-lockscreen.xml 

    # Remove Plasma 5/KDE wallpaper alternatives
    # For theme packages
    while read theme; do
        update-alternatives --remove \
            desktop-plasma5-wallpaper \
            /usr/share/desktop-base/$theme-theme/wallpaper
    done << EOF
e-legance
EOF
    # *Last* reset *highest priority* alternative for active theme
    update-alternatives --auto \
        desktop-plasma5-wallpaper

    # Remove login theme alternatives
    # For theme packages
    # Alternative for theme packages
    while read theme background; do
        update-alternatives --remove \
            desktop-login-background \
            /usr/share/desktop-base/$theme-theme/login/$background
    done << EOF
e-legance background.svg
EOF
    # *Last* reset *highest priority* alternative for active theme
    update-alternatives --auto \
        desktop-login-background

    # Remove GRUB background alternatives
    while read theme ratio; do
        update-alternatives --remove \
            desktop-grub \
            /usr/share/desktop-base/$theme-theme/grub/grub-$ratio.png
    done << EOF
e-legance 4x3
e-legance 16x9
EOF
    ## *Lastly* reset *highest priority* alternative
    update-alternatives --auto \
        desktop-grub.sh
    update-alternatives --auto \
        desktop-grub \

    # Remove theme package alternatives
    while read theme; do
        update-alternatives --remove \
            desktop-theme \
            /usr/share/desktop-base/$theme-theme
    done << EOF
e-legance
EOF
    ## *Lastly* reset *highest priority* alternative
    update-alternatives --auto \
        desktop-theme 

fi
