#!/bin/sh

TGT=''
if [ -e /targets/links/scratchbox.config ] ; then
        . /targets/links/scratchbox.config
        TGT=$SBOX_TARGET_DIR
fi

USER=user
GROUP=users
HOME="$TGT/home/$USER"

rm -f /etc/osso-af-init/gconf-dir
ln -s /var/lib/gconf /etc/osso-af-init/gconf-dir

# startup wizard needs to be able to modify the locale
chown $USER.$GROUP /etc/osso-af-init/locale

update-rc.d af-services start 22 2 3 4 5 . stop 22 0 1 6 . > /dev/null
update-rc.d af-startup start 50 2 3 4 . stop 21 0 1 5 6 . > /dev/null
update-rc.d af-base-apps start 51 2 3 4 . stop 20 0 1 5 6 . > /dev/null

# create MMC mount point ("if" is for Scratchbox)
if [ -w / ]; then
  mkdir -p /media/mmc1 2> /dev/null
  if [ $? = 0 ]; then
    chown $USER.$GROUP /media/mmc1
  fi
fi

# create MyDocs and some special directories ("if" is for Scratchbox)
if [ -w $HOME ]; then
  MYDOCS=$HOME/MyDocs
  mkdir -p $MYDOCS/.sounds $MYDOCS/.videos \
    $MYDOCS/.documents/.games $MYDOCS/.images 2> /dev/null
  if [ $? = 0 ]; then
    chown -R $USER.$GROUP $MYDOCS
  fi
fi

touch $HOME/first-boot-flag
chown $USER.$GROUP $HOME/first-boot-flag
