
pre_install() {
  if [ ! -d /etc/rc.modules.d ]; then
    mkdir -p /etc/rc.modules.d
    grep -v "/sbin/depmod" < /etc/rc.modules > /etc/rc.modules.d/custom
    echo "/sbin/depmod -a" > /etc/rc.modules.d/depmod
    chmod 755 /etc/rc.modules.d/depmod
    chmod 755 /etc/rc.modules.d/custom
  fi
}

pre_upgrade() {

  if [ ! -d /etc/rc.modules.d ]; then
    echo ""
    echo "WARNING !!!"
    echo "We recently changed the rc.modules configuration so it supports multiple"
    echo "(separate) configuration files. This makes the hw autoconfiguration easier,"
    echo "but also brings some migration related issues."
    echo "Your /etc/rc.modules settings have been moved to /etc/rc.modules.d/custom"
    echo "in order to preserve your current configuration, but if you plan to do any"
    echo "future changes in the hardware configuration, please, split the content"
    echo "of the /etc/rc.modules.d/custom file manually into the corresponding"
    echo "configuration files located in the /etc/rc.modules.d/ directory or delete"
    echo "the file content and configure all hardware again."
    echo ""
  fi

  pre_install $1

}

post_upgrade() {
  mv -f /etc/rc.modules-d.migration.new /etc/rc.modules
}

op=$1
shift
$op $*
