#!/bin/sh
#101027 fixed nvidia bugs.
#101106 added $2
#101112 fixed path include supported_chips
#101114 nvidia-256 pet pkg does not work, using 01micko's nvidia-260 pet.
#110827 nvidia db entry may have dep |+linux_kernel&eq2.6.32|, so insert 'q'.
#110827 pkg split into nvidia_base and nvidiia_kmodule. 110829 bugfix.

DEVICEID="$1"
PET_DB_FILE="$2" #exs: Packages-puppy-wary5-official, Packages-puppy-lucid-official, Packages-puppy-5-official
dPATTERN='|'"$DEVICEID"'$'

. /usr/local/video_upgrade/supported_chips #101112

echo -n "" > /tmp/vuw_nvidia_pkg

KERNELVER="`uname -r`"
#110827 nvidia db entry may have dep |+linux_kernel&eq2.6.32|, so insert 'q'... pkg split...
kPATTERN='[kq]'"`echo -n "$KERNELVER" | sed -e 's%\.%\\\.%g'`"
PETS_NVIDIA="`grep -E '^nvidia\-|^nvidia_kmodule' /root/.packages/${PET_DB_FILE} | grep -i "${kPATTERN}" | cut -f 8 -d '|' | tail -n 1`"
if [ "`echo -n "$PETS_NVIDIA" | grep '^nvidia_kmodule'`" != "" ];then
 NVIDIA_VER="`grep "$PETS_NVIDIA" /root/.packages/${PET_DB_FILE} | cut -f 3 -d '|' | cut -f 1 -d '-'`" #ex: 71.86.14
 vPATTERN="^nvidia_base\-${NVIDIA_VER}"
 NVIDIA_BASE="`grep "$vPATTERN" /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
 PETS_NVIDIA="${NVIDIA_BASE}
${PETS_NVIDIA}"
fi


if [ "`echo "$NVIDIACHIPS_71" | grep -i "$dPATTERN"`" != "" ];then
 PETS="`echo "$PETS_NVIDIA" | grep -E '^nvidia\-71\.|^nvidia_kmodule\-71\.|^nvidia_base\-71\.'`"
 echo -n "$PETS" > /tmp/vuw_nvidia_pkg
 echo "PETS=$PETS"
 exit
fi

#if [ "`echo "$NVIDIACHIPS_256" | grep -i "$dPATTERN"`" != "" ];then
# PET="`echo "$PETS_NVIDIA" | grep '^nvidia\-256\.' | tail -n 1`"
# echo -n "$PET" > /tmp/vuw_nvidia_pkg
# echo "PET=$PET"
# exit
#fi

if [ "`echo "$NVIDIACHIPS_260" | grep -i "$dPATTERN"`" != "" ];then
 PETS="`echo "$PETS_NVIDIA" | grep -E '^nvidia\-260\.|^nvidia_kmodule\-260\.|^nvidia_base\-260\.'`"
 echo -n "$PETS" > /tmp/vuw_nvidia_pkg
 echo "PETS=$PETS"
 exit
fi

if [ "`echo "$NVIDIACHIPS_195" | grep -i "$dPATTERN"`" != "" ];then
 PETS="`echo "$PETS_NVIDIA" | grep -E '^nvidia\-195\.|^nvidia_kmodule\-195\.|^nvidia_base\-195\.'`"
 echo -n "$PETS" > /tmp/vuw_nvidia_pkg
 echo "PETS=$PETS"
 exit
fi

###END###
