#!/bin/bash

set -x
platform_id=`/usr/share/volatile/getID.sh`
check_package="oem-audio-hda-daily-dkms"
oem_audio=`dpkg -l | grep $check_package`
is_depend=false
bu=`cat /usr/share/volatile/bu`

# get whole meta packages
while read metas;
do
	# check whether there is depends of $check_package, need extactly same
	dep=`apt-cache depends $metas | grep -w "\b$check_package\b"`

	# get modalias from package
	modalias_id=`apt-cache show $metas | grep Modaliases | sed s/"Modaliases: oem-platform-meta(metainfo:bu${bu^^}p"//g | sed s/")"//g`
	
	if [ "$modalias_id" != "" ]; then
		if [ "${platform_id^^}" == "${modalias_id^^}" ] && [ ! -z "$dep" ]; then
			is_depend=true
			break
		fi
	
	fi	

done < <(dpkg -l | awk '{print $2}' | grep meta)


if [ "$is_depend" == false ];then
	dpkg -r $check_package
fi
