#!/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

add_group cdrom 11
add_group dialout 18
add_group disk 6
add_group floppy 19
add_group kmem 9
add_group lp 7
add_group tape 33
add_group tty 5
add_group video 39

mkdir -p $INSTALL/sbin
  cp $PKG_BUILD/$1/udevadm $INSTALL/sbin
  cp $PKG_BUILD/$1/udevd $INSTALL/sbin

mkdir -p $INSTALL/usr/lib
  cp -PR $PKG_BUILD/libudev/.libs/libudev.so* $INSTALL/usr/lib
  cp -PR $PKG_BUILD/extras/gudev/.libs/libgudev*.so* $INSTALL/usr/lib
  rm -rf $INSTALL/usr/lib/libgudev*.*T

mkdir -p $INSTALL/lib/udev
  for i in accelerometer ata_id cdrom_id collect firmware input_id mtd_probe path_id scsi_id usb-db usb_id v4l_id; do
    cp $PKG_BUILD/extras/$i/$i $INSTALL/lib/udev
  done
  cp $PKG_BUILD/extras/usb-db/pci-db $INSTALL/lib/udev

mkdir -p $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/accelerometer/61-accelerometer.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/firmware/50-firmware.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/50-udev-default.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/cdrom_id/60-cdrom_id.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/60-persistent-alsa.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/60-persistent-input.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/60-persistent-serial.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/60-persistent-storage-tape.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/60-persistent-storage.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/v4l_id/60-persistent-v4l.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/mtd_probe/75-probe_mtd.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/78-sound-card.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/80-drivers.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/95-udev-late.rules $INSTALL/lib/udev/rules.d

mkdir -p $INSTALL/lib/udev/devices

mkdir -p $INSTALL/etc/udev
  cp $PKG_BUILD/udev.conf $INSTALL/etc/udev
  ln -sf /dev/rules.d $INSTALL/etc/udev/rules.d
