#!/bin/sh -e

PREREQS=""

prereqs() { echo "$PREREQS"; }

case "$1" in
    prereqs)
    prereqs
    exit 0
    ;;
esac

root_over_the_network() {
  if   egrep -q '^/dev/(nbd|nd[a-z]|etherd/e)[^[:space:]]+[[:space:]]+/[[:space:]]' /etc/fstab; then
    return 0
  elif egrep -q '^[^[:space:]#]+[[:space:]]+/[[:space:]]+nfs[234]?[[:space:]]' /etc/fstab; then
    return 0
  fi
  return 1 # false
}

. /usr/share/initramfs-tools/hook-functions

# udevd uses unix domain sockets for communication
force_load unix

copy_exec /sbin/udevd      /sbin
copy_exec /sbin/udevadm    /sbin

mkdir -p $DESTDIR/etc/udev
cp -p /etc/udev/udev.conf $DESTDIR/etc/udev/

mkdir -p $DESTDIR/lib/udev/rules.d/
for rules in 50-udev-default.rules 60-persistent-storage.rules \
	80-drivers.rules 91-permissions.rules \
	64-md-raid.rules 60-persistent-storage-lvm.rules \
	55-dm.rules 60-persistent-storage-dm.rules; do
  if   [ -e /etc/udev/rules.d/$rules ]; then
    cp -p /etc/udev/rules.d/$rules $DESTDIR/lib/udev/rules.d/
  elif [ -e /lib/udev/rules.d/$rules ]; then
    cp -p /lib/udev/rules.d/$rules $DESTDIR/lib/udev/rules.d/
  fi
done

# try to autodetect the value of this configuration option
if [ -z "$NEED_PERSISTENT_NET" ] && root_over_the_network; then
  NEED_PERSISTENT_NET='yes'
fi

# Copy the rules for persistent network interface names for the benefit of
# systems which need to boot over the network. If this is enabled then the
# initramfs must be rebuilt every time a new network interface is added.
# See #414287 for details.
case "$NEED_PERSISTENT_NET" in
YES|yes|Yes|Y|y)
  if [ -e /etc/udev/rules.d/70-persistent-net.rules ]; then
    cp -p /etc/udev/rules.d/70-persistent-net.rules $DESTDIR/lib/udev/rules.d/
  fi
  ;;
esac

cp /lib/udev/hotplug.functions $DESTDIR/lib/udev/
for program in firmware.agent ata_id edd_id path_id scsi_id usb_id; do
  copy_exec /lib/udev/$program /lib/udev
done
copy_exec /sbin/blkid /sbin

if [ -x /lib/udev/vio_type ]; then
  copy_exec /lib/udev/vio_type /lib/udev
fi

