#!/bin/sh
################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
#
#  OpenELEC is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  OpenELEC is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

. /etc/profile

#
# setup XBMC sources
#

  if [ ! -f $HOME/.xbmc/userdata/sources.xml ]; then
    if [ -f /usr/share/xbmc/config/sources.xml ]; then
      # include project specific sources
      cp /usr/share/xbmc/config/sources.xml $HOME/.xbmc/userdata
    else
      cat > $HOME/.xbmc/userdata/sources.xml << EOF
  <sources>
    <video>
        <default pathversion="1"></default>
        <source>
            <name>Videos</name>
            <path pathversion="1">$HOME/videos/</path>
            <allowsharing>true</allowsharing>
        </source>
        <source>
            <name>TV Shows</name>
            <path pathversion="1">$HOME/tvshows/</path>
            <allowsharing>true</allowsharing>
        </source>
    </video>
    <music>
        <default pathversion="1"></default>
        <source>
            <name>Music</name>
            <path pathversion="1">$HOME/music/</path>
            <allowsharing>true</allowsharing>
        </source>
    </music>
    <pictures>
        <default pathversion="1"></default>
        <source>
            <name>Pictures</name>
            <path pathversion="1">$HOME/pictures/</path>
            <allowsharing>true</allowsharing>
        </source>
    </pictures>
  </sources>
EOF
    fi
  fi

#
# common setup guisettings
#

  if [ ! -f $HOME/.xbmc/userdata/guisettings.xml ] ; then
    echo "<settings>" > $HOME/.xbmc/userdata/guisettings.xml

    cat >> $HOME/.xbmc/userdata/guisettings.xml << EOF
    <debug>
        <screenshotpath pathversion="1">$HOME/screenshots/</screenshotpath>
    </debug>
EOF

  #
  # include project specific options
  #

    if [ -f /usr/share/xbmc/config/guisettings.xml ]; then
      cat /usr/share/xbmc/config/guisettings.xml >> $HOME/.xbmc/userdata/guisettings.xml
    fi

    echo "</settings>" >> $HOME/.xbmc/userdata/guisettings.xml
  fi
