#!/bin/sh
#
# Script args:
# $0: full path to script
# $1: full path to top level package dir, no trailing slash
# $2: full path to installed location
# $3:  ????? Path to install Volume????
# $4:  ?????


cp -f "$1/Contents/Resources/HUAWEI Mobile Connect - 3G Modem" "/System/Library/Modem Scripts/HUAWEI Mobile Connect - 3G Modem"

if sw_vers -productVersion |grep -c 10.5; then
cp -rf "$1/Contents/Resources/HUAWEI Mobile.ccl" "/System/Library/Modem Scripts/"
fi

cp -f "$1/Contents/Resources/HUAWEI Mobile Connect - 3G Modem" "/Library/Modem Scripts/HUAWEI Mobile Connect - 3G Modem"
cp -f "$1/Contents/Resources/OperatorList.lst" "/System/Library/Extensions/OperatorList.lst"
cp -f "$1/Contents/Resources/scheme.cfg" "/System/Library/Extensions/scheme.cfg"
chmod a+wr "/System/Library/Extensions/scheme.cfg"

chown -R root /System/Library/Extensions/HuaweiDataCardDriver_power.kext
chgrp -R wheel /System/Library/Extensions/HuaweiDataCardDriver_power.kext

chown -R root /System/Library/Extensions/HuaweiDataCardDriver_intel.kext
chgrp -R wheel /System/Library/Extensions/HuaweiDataCardDriver_intel.kext

chown -R root /System/Library/Extensions/USBExpressCardCantWake.kext
chgrp -R wheel /System/Library/Extensions/USBExpressCardCantWake.kext


chown -R root /System/Library/Extensions/OperatorList.lst
chgrp -R wheel /System/Library/Extensions/OperatorList.lst



if system_profiler SPHardwareDataType |grep -c PowerPC; then
rm -rf /System/Library/Extensions/HuaweiDataCardDriver.kext
mv -f "/System/Library/Extensions/HuaweiDataCardDriver_power.kext" "/System/Library/Extensions/HuaweiDataCardDriver.kext"
fi

if system_profiler SPHardwareDataType |grep -c Intel; then
rm -rf /System/Library/Extensions/HuaweiDataCardDriver.kext
mv -f "/System/Library/Extensions/HuaweiDataCardDriver_intel.kext" "/System/Library/Extensions/HuaweiDataCardDriver.kext"
fi

mv -f "/System/Library/Extensions/USBExpressCardCantWake.kext" "/System/Library/Extensions/USBExpressCardCantWake.kext"

rm -rf "/System/Library/Extensions/HuaweiDataCardDriver_intel.kext"
rm -rf "/System/Library/Extensions/HuaweiDataCardDriver_power.kext"

rm -rf /Applications/MobileConnect.app

if system_profiler SPHardwareDataType |grep -c PowerPC; then
mv -f "/System/Library/Extensions/MobileConnect power.app" "/Applications/MobileConnect.app"
fi

if system_profiler SPHardwareDataType |grep -c Intel; then
mv -f "/System/Library/Extensions/MobileConnect intel.app" "/Applications/MobileConnect.app"
fi

rm -rf "/System/Library/Extensions/MobileConnect.app"
rm -rf "/System/Library/Extensions/MobileConnect.app"

rm /System/Library/Extensions.kextcache
kextcache -k /System/Library/Extensions
PID=`ps -axc | grep kextd | perl -e '($a,$r,$z)=split /  */, <>; print $r;'`
kill -HUP $PID
exit 0
