#!/bin/sh

PATH=/sbin:/usr/sbin:$PATH

# set default umask
umask 0022

if [ -f /etc/default/distro ]; then
    . /etc/default/distro
fi

common_flavours_settings() {
    ###
    # su-to-root -> sudo
    ###
    if which su-to-root >/dev/null; then
        touch "${HOME}/.su-to-rootrc"
        if grep -q '^SU_TO_ROOT_SU=' "${HOME}/.su-to-rootrc"; then
            sed -i 's|^SU_TO_ROOT_SU=.*|SU_TO_ROOT_SU=sudo|' \
            "${HOME}/.su-to-rootrc"
        else
           echo 'SU_TO_ROOT_SU=sudo' >> "${HOME}/.su-to-rootrc"
        fi
    fi

    ###
    # gksu -> sudo
    ###
    if which gconftool-2 >/dev/null; then
        gconftool-2 -s -t bool /apps/gksu/sudo-mode true
        gconftool-2 -s -t bool /apps/gksu/display-no-pass-info false
    fi

    ###
    # let mc use its own editor
    ###
    if which mc >/dev/null; then
        if [ ! -f "${HOME}/.config/mc/ini" ]; then
            mkdir -p "${HOME}/.config/mc/"
            cat >"${HOME}/.config/mc/ini" \
<<EOF
[Midnight-Commander]
use_internal_edit=1
EOF
	    fi
    fi

    ###
    # configure GnuPG if installed
    ###
    GNUPG_CONF="${HOME}/.gnupg/gpg.conf"
    KEY_SERVER='hkp://keyserver.noreply.org:80'
    if [ ! -f "${GNUPG_CONF}" ]; then
	    if which gpg >/dev/null; then
		    gpg -k >/dev/null 2>&1
		    if [ -f "${GNUPG_CONF}" ]; then
                sed -ri -e 's/^#.*keyserver-options auto-key-retrieve/keyserver-options auto-key-retrieve/' \
		            -e 's/^#.*charset utf-8/charset utf-8/' \
		            -e 's/^keyserver /#keyserver/' "${GNUPG_CONF}"
                    echo "keyserver ${KEY_SERVER}" >> "${GNUPG_CONF}"
                if which gpg-agent >/dev/null; then
                    sed -ri 's/^#.*use-agent/use-agent/' "${GNUPG_CONF}"
                fi
           fi
        fi
    fi
}

common_flavours_settings
