#! /bin/bash

version=$1

if [ -n "$DEB_MAINT_PARAMS" ]; then
    eval set -- "$DEB_MAINT_PARAMS"
    if [ -z "$1" ] || [ "$1" != "remove" ]; then
        exit 0;
    fi
fi

# passing the kernel version is required
[ -z "$version" ] && exit 1

MODULEDIR=/lib/modules/$version
HEADERDIR=/usr/src/linux-headers-$version

test -d $MODULEDIR || exit 0

if [ -L $MODULEDIR/build ]; then
    linked_to=$(readlink -f $MODULEDIR/build)
    if [ "$HEADERDIR" = "$linked_to" ]; then
        rm -f $MODULEDIR/build
    fi
fi

exit 0
