#!/bin/sh
module="powerfip"

DRV_DIR=/lib/modules/$(uname -r)/kernel/drivers/fip
RULES_DIR=/etc/udev/rules.d

# remove module from kernel if loaded
if [ 'lsmod | grep ${module} | wc -l' ];
then
    rmmod ${module}
fi

# remove the module from the driver directory
rm ${DRV_DIR}/${module}.ko

# remove the rules from udev.rules.d
rm ${RULES_DIR}/10-${module}.rules

# delete the driver directory if empty
if [ `ls ${DRV_DIR} | wc -l` -eq 0 ];
then
    rmdir ${DRV_DIR}
fi

# update modules map files
depmod -a
