#!/bin/sh
# KDE additions:
KDEDIR=/opt/kde
PATH=$PATH:$KDEDIR/bin
MANPATH="${MANPATH}:/opt/kde/man"
export KDEDIR PATH MANPATH
if [ "$DeployPath" = "" ] ; then
    # DeploymentStore should be set to a writable and persistant directory location
    # setDeploymentEnv finds a SLAX USB device if $DeploymentStore does not exit
    # setDeploymentEnv assumes 'sdx1_removable' is in the path
    export DeploymentStore=/mnt/sdz1_removable/DeploymentStore
    # setDeploymentEnv resets environment variable DeploymentStore in the likely event the path above is invalid
    # setDeploymentEnv set $DeployPath when setDeploymentEnv is invoked with the full path
    `/opt/deploy/bin/setDeploymentEnv`
    [ -x /store ] || ln -s $StoreDevice /store
    echo "Preparing PDK environment variables...."
    `/opt/deploy/bin/setDeploymentEnv`
    if [ "$DeployPath" = "" ] ; then
       echo "CRITICAL ERROR: DeployPath is not defined."
       sleep 180
    fi
    chmod -R 755 $DeployPath
    ldconfig
    echo "Initializing PDK hardware detect and log files...."
    prepareDeployment
    if [ $? -eq 0 ]
    then
        addLogRecord kde.sh INFO "Deployment started"
        customDeployment
    fi
    evaluateDeployment
    ret=$?
    echo "finished deployment with error level $ret"
    addLogRecord kde.sh INFO "Deployment finished with error level $ret"
    mv /etc/hosts /etc/hosts.OLD
    echo 127.0.0.1 localhost > /etc/hosts
    ifconfig | grep Bcast | awk '{ print $2 }' | awk -F: '{ print $2 " slax" }' >> /etc/hosts
    
    # I'm sure there's a reasonable explanation on why we're not storing files 
    # directly in .kde/share/config...
    mkdir -p /root/.kde/share/config
    
    # But moving *rc from /root is just not safe!
    #mv /root/*rc /root/.kde/share/config
    cp /etc/skel.root/k*rc /root/.kde/share/config
    mkdir -p  /root/.mozilla/firefox/PDK.default
    chmod 755 /root/Desktop/*
    
    echo "
    [General]
    StartWithLastProfile=1
    [Profile0]
    Name=default
    IsRelative=1
    Path=PDK.default
    " > /root/.mozilla/firefox/profiles.ini
    
    pushd /root/.mozilla/firefox/PDK.default
    mv /root/prefs.js .
    mv /root/bookmarks.html .
    popd
    
    # nfs-utils isn't installed by default in Slax6.  mount.nfs is added by acwong
    # in to the PXE+NFS version of Slax6 only!  It is in the custom initrd image:
    if [[ -x /mnt/live/bin/mount.nfs && ! -x /sbin/mount.nfs ]]; then
    ln -s /mnt/live/bin/mount.nfs /sbin/mount.nfs
    fi
    
    RPC_SVC=/etc/rc.d/rc.rpc
    # Let's make sure RPC is started
    if [ -a $RPC_SVC ]; then
    if [ ! -x $RPC_SVC ]; then
    chmod +x $RPC_SVC
    fi
    $RPC_SVC start
    fi
    
    # *Now* let's try mounting NFS shares:
    
    if [ "`ifconfig | grep ddr | grep 10.243.42.`" != "" ] ; then
        mkdir  /mnt/pub
        mkdir  /mnt/telco
        mkdir  /mnt/proj
        echo Mounting network shares .....
        mount -t nfs 10.243.42.200:/home/public            /mnt/pub &
        echo  /mnt/pub is mounting in the background....
        mount -t nfs sonapp3.so.intel.com:/vol/vol2/telco  /mnt/telco &
        echo  /mnt/telco is mounting in the background....
        mount -t nfs sonapp3.so.intel.com:/vol/vol1/SWDev  /mnt/proj &
        echo  /mnt/proj is mounting in the background....
    fi
    export PATH=$PATH:$BootDevice/bin:$BootDevice/mybin
fi
