#!/bin/sh

work_dir=$1

echo "Update script is here"
old_version=`md5sum /etc/vpn_client/Info.plist |awk '{print $1}'`
cd $work_dir

curent_software=`dpkg -l | grep vpn-client-guomi  | cut -d' ' -f1`
if [ "$curent_software" != "ii" ];then
    echo "Curent version is not guomi"
    exit
else
    echo "Curent version is guomi"
fi 

echo "Uninstall old deb package"

sudo dpkg -r vpn-client-guomi

echo "Uninstall result: $?"

echo "Install the new package"
sudo dpkg -i vpn-client-guomi-arm64.deb

echo "Install result: $?"
new_version=`md5sum /etc/vpn_client/Info.plist |awk '{print $1}'`
if [ $old_version == $new_version ];then
    "The verison is same"
else
    killall QianxinVPN
    sleep 1
    /usr/sbin/QianxinVPN
fi
exit 0 
