#!/bin/bash
PKG_VERSION=`cat /home/jack/luci-app-myvpnconfig/Makefile|grep PKG_VERSION|awk -F "=" '{print $2}'`
PKG_RELEASS=`cat /home/jack/luci-app-myvpnconfig/Makefile|grep PKG_RELEASE|awk -F "=" '{print $2}'`
cd /home/jack/luci-app-myvpnconfig
tar zcvf back/luci-app-myvpnconfig-$PKG_VERSION-$PKG_RELEASS.tar.gz files
NEWPKG_RELEASS=$(($PKG_RELEASS+1))
sed -i "5s/$PKG_RELEASS/$NEWPKG_RELEASS/" /home/jack/luci-app-myvpnconfig/Makefile
#cd /home/jack/luci-app-myvpnconfig/update
#find $PWD -type f|xargs ls -ld|awk '{print $9}'|sed 's/\/home\/jack\/luci-app-myvpnconfig\/files//g' > myvpn_file_list
#DIR=`pwd`
#rm myvpn_file_md5 -rf
#rm md5  -rf
#for file in `cat myvpn_file_list`;do
#	filemd5=`md5sum $DIR$file|awk '{print $1}'`
#	if [ "$filemd5" != "" ];then
#	echo $filemd5 $file >>myvpn_file_md5
#	fi
#done
#rm myvpn_file_list


cd /home/jack/zbt-7628
#make package/luci-app-myvpnconfig/compile V=s
make -j16 V=s
if [ "$?" = "0" ];then
	echo Package ok.
	\cp /home/jack/zbt-7628/bin/ramips/openwrt-ramips-mt7628-mt7628-squashfs-sysupgrade.bin /home/jack/luci-app-myvpnconfig/openwrt/openwrt-7628-$PKG_VERSION-$NEWPKG_RELEASS.bin -r
	\cp /home/jack/zbt-7628/bin/ramips/openwrt-ramips-mt7628-mt7628-squashfs-sysupgrade.bin /home/jack/luci-app-myvpnconfig/openwrt/openwrt-7628-last.bin -r
	cd /home/jack/luci-app-myvpnconfig/openwrt
	rm md5 -rf
	md5sum * > md5
	\cp /home/jack/zbt-7628/bin/ramips/packages/base/luci-app-myvpnconfig* /home/jack/luci-app-myvpnconfig/ipk -r
	cd /home/jack/luci-app-myvpnconfig/ipk
	rm md5 -rf
	md5sum * > md5
	cd /home/jack/luci-app-myvpnconfig
	git remote set-url origin git+ssh://git@github.com/hk59775634/luci-app-myvpnconfig.git
	git add .
	git commit -m "upgrade `echo $PKG_VERSION`.`echo $NEWPKG_RELEASS` `date`"
	git push
	tar zcvf - * | ssh root@103.6.6.254 "cd /www/wwwroot/node.vps000.com/downloads;tar zxvf -"
	echo package ok.
else
	echo Package bad.
fi



