#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2011 Stephan Raue (stephan@openelec.tv)
#
#  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 OpenELEC.tv; 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
################################################################################

. config/options $1

ROOT_PWD="`$ROOT/$TOOLCHAIN/bin/cryptpw $ROOT_PASSWORD`"
USER_PWD="`$ROOT/$TOOLCHAIN/bin/cryptpw $USER_PASSWORD`"

  add_user root "$ROOT_PWD" 0 0 "Root User" "/storage" "/bin/sh"
  add_group root 0
  add_group users 100

  add_user $USER_NAME "$USER_PWD" 1000 1000 "User" "/storage" "/bin/sh"
  add_group $USER_GROUP 1000

  cp -PR $BUILD/busybox*/_install-system/* $INSTALL
    echo "chmod 4755 $INSTALL/bin/busybox" >> $FAKEROOT_SCRIPT

  mkdir -p $INSTALL/usr/bin
    cp $PKG_DIR/scripts/createlog $INSTALL/usr/bin/
    cp $PKG_DIR/scripts/lsb_release $INSTALL/usr/bin/

  mkdir -p $INSTALL/sbin
    cp $PKG_DIR/scripts/init $INSTALL/sbin/

  mkdir -p $INSTALL/etc
    cp $PKG_DIR/config/profile $INSTALL/etc

  # /etc/fstab is needed by...
    touch $INSTALL/etc/fstab

  # /etc/hosts must be writeable
    ln -sf /var/cache/hosts $INSTALL/etc/hosts

  # /etc/mtab is needed by udisks etc...
    ln -sf /proc/self/mounts $INSTALL/etc/mtab

  # create /etc/hostname
    echo $HOSTNAME > $INSTALL/etc/hostname

  mkdir -p $INSTALL/etc/modprobe.d
    cp $PKG_DIR/modprobe.d/* $INSTALL/etc/modprobe.d

  # add user modprobe.d dir
    mkdir -p $INSTALL/usr/config/modprobe.d
