#!/bin/sh

if [ -n "$D" ]; then
        grep -qE '^kids:' $D/etc/passwd
        if [[ $? -ne 0 ]] ; then
                echo 'kids:x:500:500:Linux User,,,:/media:/bin/false' >> $D/etc/passwd
                echo 'kids:!:16560:0:99999:7:::' >> $D/etc/shadow
        fi
fi

if [ -z "$D" ]; then
        [ -e /etc/samba/private/smbpasswd ] || touch /etc/samba/private/smbpasswd

        grep -qE '^root:' /etc/samba/private/smbpasswd
        if [[ $? -ne 0 ]] ; then
                smbpasswd -Ln root >/dev/null
        fi

        grep -qE '^kids:' /etc/passwd
        if [[ $? -ne 0 ]] ; then
                adduser -h /media -s /bin/false -H -D -u 500 kids 2>/dev/null || adduser -h /media -s /bin/false -H -D kids
        fi

        grep -qE '^kids:' /etc/samba/private/smbpasswd
        if [[ $? -ne 0 ]] ; then
                smbpasswd -Ln kids >/dev/null
        fi
fi

if [ -e $D/etc/samba/distro/smb-vmc.vmc ]; then
	rm $D/etc/samba/distro/smb-vmc.conf 2>/dev/null || true
	ln -s smb-vmc.vmc $D/etc/samba/distro/smb-vmc.conf
else
	rm $D/etc/samba/distro/smb-vmc.conf 2>/dev/null || true
	ln -s smb-vmc.samba $D/etc/samba/distro/smb-vmc.conf
fi
