#!/bin/sh
set -e

# Tag to allow some debhelper commands to inject relevant code
#DEBHELPER#

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 $priority
    done << EOF
blue 1280x1024.svg
blue 1600x1200.svg
blue 1920x1080.svg
blue 1920x1200.svg
blue 2560x1080.svg
anger 1280x1024.svg
anger 1600x1200.svg
anger 1920x1080.svg
anger 1920x1200.svg
anger 2560x1080.svg
gray 1280x1024.svg
gray 1600x1200.svg
gray 1920x1080.svg
gray 1920x1200.svg
EOF
    # *Last* remove background *highest priority* alternatives for active theme
    update-alternatives --remove desktop-background /usr/share/desktop-base/active-theme/wallpaper/contents/images/1920x1080.svg

    # 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 $priority
    done << EOF
blue
anger
gray
EOF
    # *Lastly* remove *highest priority* alternative for active theme
    update-alternatives --remove \
        desktop-background.xml \
        /usr/share/desktop-base/active-theme/wallpaper/gnome-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 $priority
    done << EOF
blue
EOF
    # *Last* remove *highest priority* alternative for active theme
    update-alternatives --remove \
        desktop-lockscreen.xml \
        /usr/share/desktop-base/active-theme/lockscreen/gnome-background.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
blue
anger
gray
EOF
    # *Last* remove *highest priority* alternative for active theme
    update-alternatives --remove \
        desktop-plasma5-wallpaper \
        /usr/share/desktop-base/active-theme/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
blue background.svg
anger background.svg
gray background.svg
EOF
    # *Last* remove *highest priority* alternative for active theme
    update-alternatives --remove \
        desktop-login-background \
        /usr/share/desktop-base/active-theme/login/background.svg

    # remove grub alternatives
    for background in \
          pardus-grub.png \
          pardus-grub-1920x1080.png \          
          ; do
        update-alternatives --remove desktop-grub /usr/share/images/desktop-base/$background
    done
fi

    # Remove theme package alternatives
    while read theme; do
        update-alternatives --remove \
            desktop-theme \
            /usr/share/desktop-base/$theme-theme
    done << EOF
anger
gray
EOF
    ## *Lastly* remove *highest priority* alternative
    update-alternatives --remove \
        desktop-theme \
        /usr/share/desktop-base/blue-theme

fi
