#!/bin/sh -e
#
# firmware loader agent
#

cd /lib/udev/
. ./hotplug.functions

if [ ! -e /sys/$DEVPATH/loading ]; then
    mesg "/sys/$DEVPATH/ does not exist"
    exit 1
fi

for DIR in $FIRMWARE_DIRS; do
    [ -e "$DIR/$FIRMWARE" ] || continue
    echo 1 > /sys/$DEVPATH/loading
    cat "$DIR/$FIRMWARE" > /sys/$DEVPATH/data
    echo 0 > /sys/$DEVPATH/loading
    exit 0
done

# modification for d-i
echo "$PHYSDEVDRIVER $FIRMWARE" >>/tmp/missing-firmware

# the firmware was not found
echo -1 > /sys/$DEVPATH/loading

debug_mesg "Cannot find the $FIRMWARE firmware"
exit 1

