#!/bin/sh

. config/options

$SCRIPTS/install glib
$SCRIPTS/install pciutils
$SCRIPTS/install usbutils
$SCRIPTS/install libusb-compat

PKG_DIR=`find $PACKAGES -type d -name $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

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

  cp $PKG_DIR/config/*.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
