#!/bin/bash

if [ $0 != "./dme" ] ; then
    echo "This script must be run from folder with icons for menu and emblems"
    echo "Do not change it name to anything else than dme!"

    exit 1
fi

if [ -z $1 ] ; then
    echo "Specify linux distribution name to use"
    echo
    echo "Valid names are:"
    echo "arch"
    echo "debian"
    echo "fedora"
    echo "gentoo"
    echo "mandriva"
    echo "mint"
    echo "suse"
    echo "ubuntu"

    exit 2
else
    DNLN=$1
fi

WHOAMI=`/usr/bin/whoami`

if [ $WHOAMI != "root" ] ; then
    ICOL=$HOME/.icons
else
    ICOL=/usr/share/icons
fi

if [ -d "$ICOL/OSDark" ] ; then
    if [ -f ./${DNLN}.png ] & [ -f ./${DNLN}-16.png ] ; then
        rm $ICOL/OSDark/128x128/places/start-here.png
        rm $ICOL/OSDark/16x16/places/start-here.png

        cp ./${DNLN}.png $ICOL/OSDark/128x128/places/start-here.png
        cp ./${DNLN}-16.png $ICOL/OSDark/16x16/places/start-here.png
        cp ./emblem-${DNLN}.png $ICOL/OSDark/128x128/emblems/emblem-${DNLN}.png
    
        echo Icons successfully installed to $ICOL/OSDark icon theme directory
    else
        echo Linux $DNLN distribution is not supported!

        exit 3
    fi
fi

if [ -d "$ICOL/OSDark-blue" ] ; then
    if [ -f ./${DNLN}.png ] & [ -f ./${DNLN}-16.png ] ; then
        rm $ICOL/OSDark-blue/128x128/places/start-here.png
        rm $ICOL/OSDark-blue/16x16/places/start-here.png

        cp ./${DNLN}.png $ICOL/OSDark-blue/128x128/places/start-here.png
        cp ./${DNLN}-16.png $ICOL/OSDark-blue/16x16/places/start-here.png
        cp ./emblem-${DNLN}.png $ICOL/OSDark-blue/128x128/emblems/emblem-${DNLN}.png

        echo Icons successfully installed to $ICOL/OSDark-blue icon theme directory
    else
        echo Linux $DNLN distribution is not supported!

        exit 3
    fi
fi

if [ -d "$ICOL/OSDark-green" ] ; then
    if [ -f ./${DNLN}.png ] & [ -f ./${DNLN}-16.png ] ; then
        rm $ICOL/OSDark-green/128x128/places/start-here.png
        rm $ICOL/OSDark-green/16x16/places/start-here.png

        cp ./${DNLN}.png $ICOL/OSDark-green/128x128/places/start-here.png
        cp ./${DNLN}-16.png $ICOL/OSDark-green/16x16/places/start-here.png
        cp ./emblem-${DNLN}.png $ICOL/OSDark-green/128x128/emblems/emblem-${DNLN}.png

        echo Icons successfully installed to $ICOL/OSDark-green icon theme directory
    else
        echo Linux $DNLN distribution is not supported!

        exit 3
    fi
fi

exit 0
