#!/bin/sh

## (c) 2019 Arjen Balfoort (SolydXK). Based on :
## live-config(7) - System Configuration Scripts
## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
##
## This program 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.
##
## Purpose: Copy live installer desktop file to desktop

Cmdline ()
{
    # Reading kernel command line
    for _PARAMETER in ${LIVE_CONFIG_CMDLINE}
    do
        case "${_PARAMETER}" in
            live-config.username=*|username=*)
                LIVE_USERNAME="${_PARAMETER#*username=}"
                ;;
        esac
    done
}

Init ()
{
    # Checking if package is already configured
    if [ -e /var/lib/live/config/installer-icon ]
    then
        exit 0
    fi
    
    echo -n " installer-icon"
}

Config ()
{
    if [ -e /usr/share/applications/live-installer-3.desktop ]
    then
        if [ ! -e /home/${LIVE_USERNAME}/Desktop ]
        then
            mkdir -p /home/${LIVE_USERNAME}/Desktop                
        fi
        cp /usr/share/applications/live-installer-3.desktop /home/${LIVE_USERNAME}/Desktop/live-installer-3.desktop
        chmod 755 /home/${LIVE_USERNAME}/Desktop/live-installer-3.desktop
        chown ${LIVE_USERNAME}:${LIVE_USERNAME} "/home/${LIVE_USERNAME}/Desktop" -R        
    fi
    
    # Creating state file
    touch /var/lib/live/config/installer-icon
}

Cmdline
Init
Config
