#!/bin/sh
# prerm script for oem-fix-eth-rtl-mac-pass-through
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    remove|upgrade|deconfigure)
        DMI_SKU_PATH="/sys/class/dmi/id/product_sku"
        DMI_BIOS_VENDOR="/sys/class/dmi/id/bios_vendor"
        if [ ! -e "${DMI_SKU_PATH}" ] || [ ! -e "${DMI_BIOS_VENDOR}" ]; then
            echo "Can't check the function is supported or not"
            exit 0
        fi
        BIOS_VENDOR=$(cat "${DMI_BIOS_VENDOR}")
        BIOS_ID=$(cat < "${DMI_SKU_PATH}" | tr '[:upper:]' '[:lower:]')
        if [ "${BIOS_VENDOR}" != "Dell Inc." ]; then
            echo "The vendor is not supported"
            exit 0
        fi
        case "$BIOS_ID" in
            ( '0a9d' | '0a9e' ) # Delta V/VII
                rm /usr/lib/udev/rules.d/50-usb-realtek-net.rules
                dpkg-divert --rename --remove /usr/lib/udev/rules.d/50-usb-realtek-net.rules.orig
                ;;
            *) # default
                echo "The platform is not supported"
                exit 0
                ;;
        esac
    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
