#!/bin/sh
# this script only for SUSE

#variables
PKGPWD=`pwd`
kver=`uname -r`
install=""
der_ver=1.11
patch_ver=3
dist=""

#check dist
#test -f /etc/redhat-release && dist="rhel"
#test -f /etc/SuSE-release && dist="sles"
dist=`cat /etc/os-release | grep '^ID=' | cut -d "=" -f 2 | tr -d '"'`
dist_ver=`cat /etc/os-release | grep VERSION_ID | cut -d "=" -f 2 | tr -d '"'`

#check support in SRPM
cd SRPMS

if [ ! -f "ast-drm-$der_ver-$patch_ver-$dist$dist_ver.src.rpm" ]; then
	echo "The distribution is not in SRPMs support list"
	exit 1
fi

#start to install
echo "Check Previous Installation Package ...."
install=`rpm -qa | grep "ast-drm"`
if [ "$install" != "" ]; then
echo "Remove Previous Installation Package ...."
rpm -e $install
fi

if [ "$dist"="sles" ]; then
	echo "Rebuild SRPM on SUSE Distribution ...."
	rpmbuild --rebuild ast-drm-$der_ver-$patch_ver-$dist$dist_ver.src.rpm
	echo "Install Package on SUSE Distribution ...."
	rpm -ivh /usr/src/packages/RPMS/ast-drm.$der_ver.$patch_ver.rpm --force
	echo "Rebuilt Image ...."
	dracut -f
	sed -i "s/allow_unsupported_modules 0/allow_unsupported_modules 1/" /etc/modprobe.d/10-unsupported-modules.conf
	echo "Install Package Ready and Please Reboot System!!"

else
	echo "Cannot find proper package for this distribution."
	echo "Please update package manually."
fi

cd $PKGPWD

