#!/bin/sh

ULBSD_DIR="/usr/local/share/ulbsd"

# Turn bell off
xset b off

# If ogain is present, make sure its turned up
MIXOUT="`mixer -s`"
echo $MIXOUT | grep "ogain " >/dev/null 2>/dev/null
if [ "$?" == "0" ]
then
    mixer ogain 100:100
fi

USER="`id -u`"

if [ "${USER}" != "0" ]
then
    is_copy_need="1"

    cd ${ULBSD_DIR}/skel
    for i in `ls -A`
    do
        if [ -e ~/"${i}" ] ; then is_copy_need="0"; break
        fi
    done

    if [ "${is_copy_need}" == "1" ]; then
        for i in `ls -A`
        do
            cp -R "${i}" ~/
        done
    fi

    mkdir -p ~/.config
    version="`cat ${ULBSD_DIR}/version`"
    echo "[General]" > ~/.config/kcm-about-distrorc
    echo "Name=ULBSD" >> ~/.config/kcm-about-distrorc
    echo "Version=" >> ~/.config/kcm-about-distrorc
    echo "LogoPath=/usr/local/share/icons/ulbsd-logo.png" >> ~/.config/kcm-about-distrorc
    echo "Website=http://ulbsd.ru" >> ~/.config/kcm-about-distrorc
    echo "Variant=${version}" >> ~/.config/kcm-about-distrorc

    mkdir -p ~/.local/share/applications
    cp ${ULBSD_DIR}/apps/user/* ~/.local/share/applications/

    lo_installed=`pkg info | grep ru-libreoffice`
    if [ "$lo_installed" == "" ]; then
        rm ~/.local/share/applications/libreoffice* 
    fi

    cups_installed=`pkg info | grep cups`
    if [ "$cups_installed" == "" ]; then
        rm ~/.local/share/applications/cups* 
    fi

    freerdp3_installed=`pkg info | grep freerdp3`
    if [ "$freerdp3_installed" == "" ]; then
        rm ~/.local/share/applications/*freerdp3* 
    fi

    cd ~

    if [ -f /var/db/AccountsService/icons/$LOGNAME ]; then
        ln -fs /var/db/AccountsService/icons/$LOGNAME .face.icon
    fi
fi
