#!/bin/sh -e
set -e

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

if [ "${1}" = "upgrade" ]; then
    if dpkg --compare-versions ${2} lt 0.3.11 && dpkg --compare-versions ${2} gt 0.3.5; then
        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-Debian.png
        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-EvolvingTux.png
        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-Debian_red.png

        dpkg-divert --package desktop-base --rename \
            --divert /usr/share/pixmaps/splash/gnome-splash.png.orig \
            --remove /usr/share/pixmaps/splash/gnome-splash.png
    fi

    if dpkg --compare-versions ${2} lt "9.0.0~exp"; then
        # Remove desktop splash alternative that we don’t ship anymore
        update-alternatives --remove-all desktop-splash

        # Remove alternatives for Lines we now ship elsewhere as a theme pack
        ## Wallpaper
        for background in \
              lines-wallpaper_1280x1024.svg \
              lines-wallpaper_1600x1200.svg \
              lines-wallpaper_1920x1080.svg \
              lines-wallpaper_1920x1200.svg \
              lines-wallpaper_2560x1080.svg \
              ; do
            update-alternatives --remove desktop-background /usr/share/images/desktop-base/$background
        done
        update-alternatives --remove \
            desktop-background.xml \
            /usr/share/images/desktop-base/lines.xml
        ## Login background
        update-alternatives --remove desktop-login-background \
            /usr/share/desktop-base/lines-theme/login-background.svg
        update-alternatives --remove desktop-login-background \
            /usr/share/desktop-base/lines-theme/login-background-with-logo.svg

        ## Grub background
        while read background; do
            update-alternatives --remove \
                desktop-grub \
                /usr/share/images/desktop-base/$background
        done << EOF
lines-grub.png
lines-grub-1920x1080.png
EOF
    fi

fi
