#!/bin/bash
TARGET_VENDOR="0731"
TARGET_DEVICES=("1100" "1109" "f011" "f111" "ff11")
ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
check_target_devices() {
        for device in "${TARGET_DEVICES[@]}"; do
                if [ -n "$(lspci -d "${TARGET_VENDOR}:${device}")" ]; then
                        return 0
                fi
        done
        return 1
}

set_config(){
        if check_target_devices; then
                echo "/usr/lib/${DEB_HOST_MULTIARCH}/mwv207d/gbm/" | tee /etc/ld.so.conf.d/00-mwv207d.conf > /dev/null
                ldconfig -n /usr/lib/${DEB_HOST_MULTIARCH}/mwv207d/gbm/
        else
                if [ -f "/etc/ld.so.conf.d/00-mwv207d.conf" ]; then
                        rm /etc/ld.so.conf.d/00-mwv207d.conf > /dev/null
                        rm /usr/lib/${DEB_HOST_MULTIARCH}/mwv207d/gbm/libgbm.so.1
                fi
        fi
}

set_custom_config(){ :; }

. /etc/os-release
if [[ "$NAME" =~ [Uu][Oo][Ss] || "$NAME" =~ [Kk]ylin ]]; then
        set_config
        set_custom_config
fi

