#!/bin/sh

## 0045-sudo-trinity - Additional Configuration Script for Debian Live
## Copyright (C) 2011 David Hare <exe-linux@fastfishwebsolutions.com>
##
## live-config comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


Sudo_trinity ()
{
    # Checking if package is installed or already configured
    if [ ! -e /var/lib/dpkg/info/sudo.list ] || [ -e /var/lib/live/config/sudo-trinity ]; then return; fi

    echo -n " sudo-trinity"

    Configure_sudo_trinity
}

Configure_sudo_trinity ()
{
    ## make sure 003-sudo has run and left it's stat file
    if ! [ -e /var/lib/live/config/sudo ]; then return; fi

    if [ -f /opt/trinity/bin/kdesu ]; then TDESU_CONFIG=kdesurc; fi
    if [ -f /opt/trinity/bin/tdesu ]; then TDESU_CONFIG=tdesurc; fi

    sudo -u "${LIVE_USERNAME}" sh -c "umask 0077 && mkdir -p /home/${LIVE_USERNAME}/.trinity/share/config && cat > /home/${LIVE_USERNAME}/.trinity/share/config/$TDESU_CONFIG" << EOF
[super-user-command]
super-user-command=sudo
EOF

    if [ -e /opt/trinity/share/apps/konsole/sumc.desktop ]; then
	sudo -u "${LIVE_USERNAME}" sh -c "umask 0077 && mkdir -p /home/${LIVE_USERNAME}/.trinity/share/apps/konsole && sed -e 's/Exec=su.*$/Exec=sudo mc -c/' /opt/trinity/share/apps/konsole/sumc.desktop > /home/${LIVE_USERNAME}/.trinity/share/apps/konsole/sumc.desktop"
    fi

    if [ -e /opt/trinity/share/apps/konsole/su.desktop ]; then
	sudo -u "${LIVE_USERNAME}" sh -c "umask 0077 && mkdir -p /home/${LIVE_USERNAME}/.trinity/share/apps/konsole && sed -e 's/Exec=su.*$/Exec=sudo -i/' /opt/trinity/share/apps/konsole/su.desktop > /home/${LIVE_USERNAME}/.trinity/share/apps/konsole/su.desktop"
    fi

    # Creating state file
    touch /var/lib/live/config/sudo-trinity
}

Sudo_trinity
