#!/bin/bash
# -*- mode: shell-script; coding: utf-8 -*-
#
# Copyright 2002-2014 Cendio AB.
# For more information, see http://www.cendio.com
#
# This script renames KDE and GNOME dot-directories, so that when the user 
# restarts their desktop environment, they will get the default settings. 

conf_files=".config"
gnome_files=".gnome .gnome_private .sawfish .gnome2 .gnome2_private \
 .gnome-desktop .gconf .gconfd"
kde_files=".kde .kde2 .kderc .gtkrc-kde"
backup_dir="${HOME}/.old-thinlinc-desktop"

echo
echo "This program will reset all your desktop settings"
echo "(by moving .kde, .gnome etc to ${backup_dir})"
echo
echo -n "Are you sure you want to do this (yes/no)? "
read confirmation

if [ "${confirmation}" != "yes" ]; then
    echo "Aborted."
    exit 1
fi

# Take care of the case when backup_dir already exists
if [ -e ${backup_dir} ]; then
    echo "${backup_dir} already exists!"
    echo -n "Is it OK to clear this directory (yes/no)? "
    read confirmation

    if [ "${confirmation}" != "yes" ]; then
    	echo "Aborted."
    	exit 1
    fi

    echo "Clearing ${backup_dir}..."
    rm -rf ${backup_dir}
fi

# Create backup_dir
mkdir ${backup_dir} || exit 1

# Move files/directories
for file in ${gnome_files} ${kde_files} ${conf_files}; do
    if [ -e ${file} ]; then
        echo "Moving ${file}"
        mv ${file} ${backup_dir}
    fi
done
