#!/bin/sh

#      Copyright (C) 2005-2008 Team XBMC
#      http://www.xbmc.org
#
#  This Program 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, or (at your option)
#  any later version.
#
#  This Program 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 XBMC; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html

in-target dpkg-reconfigure xbmc-live

# Modify tvheadend user

cat > /target/tmp/setupTVH.sh << 'EOF'
xbmcUser=$(getent passwd 1000 | sed -e 's/\:.*//')
sed -i -e "/DAEMON_ARGS/s/-u xbmc/-u $xbmcUser/" /etc/default/tvheadend

mkdir -p /home/$xbmcUser/.hts/tvheadend
cat > /home/$xbmcUser/.hts/tvheadend/superuser << EEOF
{
"username": "xbmc",
"password": "xbmc"
}
EEOF

chown -R $xbmcUser:$xbmcUser /home/$xbmcUser/.hts
EOF

in-target sh /tmp/setupTVH.sh

rm /target/tmp/setupTVH.sh
