#!/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
#  cp $PKG_BUILD/extras/floppy/create_floppy_devices $INSTALL/lib/udev
  cp $PKG_BUILD/extras/firmware/firmware $INSTALL/lib/udev
  cp $PKG_BUILD/extras/rule_generator/rule_generator.functions $INSTALL/lib/udev
  cp $PKG_BUILD/extras/rule_generator/write_cd_rules $INSTALL/lib/udev
  cp $PKG_BUILD/extras/rule_generator/write_net_rules $INSTALL/lib/udev
    chmod +x $INSTALL/lib/udev/write_*_rules
#  cp $PKG_BUILD/extras/keymap/keymap $INSTALL/lib/udev
#  cp $PKG_BUILD/extras/keymap/keyboard-force-release.sh $INSTALL/lib/udev
#    chmod +x $INSTALL/lib/udev/keyboard-force-release.sh
#  cp -R $PKG_BUILD/extras/keymap/keymaps $INSTALL/lib/udev
#  cp -R $PKG_BUILD/extras/keymap/force-release-maps $INSTALL/lib/udev/keymaps/force-release

  for i in ata_id cdrom_id collect edd_id fstab_import path_id scsi_id usb_id v4l_id; do
    cp $PKG_BUILD/extras/$i/$i $INSTALL/lib/udev
  done
  cp $PKG_BUILD/extras/input_id/input_id $INSTALL/lib/udev
  cp $PKG_BUILD/extras/usb-db/usb-db $INSTALL/lib/udev
  cp $PKG_BUILD/extras/usb-db/pci-db $INSTALL/lib/udev

mkdir -p $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/cdrom_id/*.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/edd_id/*.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/firmware/*.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/fstab_import/*.rules $INSTALL/lib/udev/rules.d
#  cp $PKG_BUILD/extras/keymap/*.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/rule_generator/*.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/extras/v4l_id/*.rules $INSTALL/lib/udev/rules.d
#  cp $PKG_BUILD/rules/packages/40-alsa.rules $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/rules/rules.d/50-udev-default.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/75-net-description.rules $INSTALL/lib/udev/rules.d
#  cp $PKG_BUILD/rules/rules.d/75-tty-description.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/60-persistent-storage.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/etc/udev
  cp $PKG_BUILD/udev.conf $INSTALL/etc/udev
  ln -sf /dev/rules.d $INSTALL/etc/udev/rules.d
