#!/bin/bash
get_md5_of_file(){
    md5sum "$1" | awk '{print $1}'
}

get_md5_of_dri_lib(){
    [ -z "$1" ] && (echo FAIL: zero input && exit 1)
    cat /var/lib/dpkg/info/libgl1-mesa-dri:*.md5sums | grep "$1" | awk '{print $1}'
}
case "$1" in
    configure)

    for file in `cat /var/lib/dpkg/info/libgl1-mesa-dri:*.md5sums |  grep "\.so"| awk '{print $2}'`;do
        if [ "$(get_md5_of_file /$file)" != "$(get_md5_of_dri_lib $file)" ]; then
            [ "$(get_md5_of_file /${file}~)" == "$(get_md5_of_dri_lib $file)" ] && (rm -f /${file} && mv /${file}~ /${file} )
        fi
    done
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst 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
