#!/bin/sh
#  This file is part of Atarashii.
#
#  Atarashii is free software: you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Atarashii is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License along with
#  Atarashii. If not, see <http://www.gnu.org/licenses/>.

# Exit on error!
set -e

# Remove icon
ICON_FILE="/usr/share/icons/atarashii.png"
ICON="`which xdg-icon-resource 2> /dev/null`"
if [ -x "$ICON" ]; then
    "$ICON" uninstall --size "128" "$ICON_FILE" "bonsaiden-atarashii"
    echo "Removed icon!"
fi


# Remove repository ------------------------------------------------------------
# ------------------------------------------------------------------------------
REPO_FILE=/etc/apt/sources.list.d/atarashii.list
AUTOSTART_FILE=~/.config/autostart/atarashii.desktop
CACHE_DIR=~/.cache/atarashii

action="$1"

# Only do complete clean-up on purge.
if [ "$action" != "purge" ] ; then
    echo "No --purge means no cleanup!"
    exit 0
fi

# Remove the avatar cache dir
echo "Removing avatar cache..."
if [ -e $CACHE_DIR ]; then
    echo "Directory found! Removing..."
    rm -r $CACHE_DIR
    echo "Done!"
else
    echo "Directory not found. Doing nothing."
fi

# Remove the autostart file
echo "Removing autostart file..."
if [ -e $AUTOSTART_FILE ]; then
    echo "File found! Removing..."
    rm $AUTOSTART_FILE
    echo "Done!"
else
    echo "File not found. Doing nothing."
fi

# Remove repo file
echo "Removing repository list..."
if [ -e $REPO_FILE ]; then
    echo "File found! Removing..."
    rm $REPO_FILE
    echo "Done!"
else
    echo "File not found. Doing nothing."
fi

