#!/bin/sh

if [ -e "/Library/StartupItems/HWPortDetect_driver/StartupParameters.plist" ]
then
    sudo rm -Rf "/Library/StartupItems/HWPortDetect_driver/StartupParameters.plist"
fi

if [ -e "/Library/LaunchDaemons/com.huawei.hwportdetect_driver.plist" ]
then
    /bin/launchctl unload /Library/LaunchDaemons/com.huawei.hwportdetect_driver.plist
    su root -c "/bin/launchctl load /Library/LaunchDaemons/com.huawei.hwportdetect_driver.plist"
fi


killall -c CreateNetwork
echo "HHHHHHH begin"
cd "/Library/StartupItems/"

sudo mkdir HW_CreateNetwork
sudo tar  -zxf "$1/Contents/Resources/HW_CreateNetwork.tar.gz" ./ || sudo tar  -zxf "$1/Contents/Resources/HW_CreateNetwork.tar.gz" HW_CreateNetwork
sudo chmod -R 755 /Library/StartupItems/HW_CreateNetwork
sudo chown -R root:wheel /Library/StartupItems/HW_CreateNetwork
if [ -e "/Library/LaunchDaemons/com.huawei.hw_createnetwork.plist" ]
then
    /bin/launchctl unload /Library/LaunchDaemons/com.huawei.hw_createnetwork.plist
    su root -c "/bin/launchctl load /Library/LaunchDaemons/com.huawei.hw_createnetwork.plist"
fi

cd "$1"
echo "HHHHHHH end"
