#!/bin/bash

jsfile=$1
if [ ! -n "$jsfile" ] ; then
	echo '	$1:需要更新版本号的js文件' 
	exit 1
fi
if [ ${jsfile} == '-h' ] ; then
	echo '	$1:需要更新版本号的js文件' 
	exit 1
fi



cd `dirname $0`
root=`pwd`

# 版本号
timer=$2

if [ ! -n "$timer" ] ; then
	# 当前时间
	timer=`date +%s`
fi

echo "更新 ${jsfile} 版本号为 ${timer}"

#更新index中的js文件版本号
update_index_html_js_v(){
	conf_flie=$2
	conf_flie=${conf_flie/\//\\\/}
	echo $1
	sed -i 's/"'"$conf_flie"'.*"/"'"$conf_flie"'?v='"$timer"'"/g' $1
	sed -i 's/"'"version.bin"'.*"/"'"version.bin"'?v='"$timer"'"/g' $1
	sed -i 's/"'"ui.json"'.*"/"'"ui.json"'?v='"$timer"'"/g' $1
	sed -i 's/"'"template.bin"'.*"/"'"template.bin"'?v='"$timer"'"/g' $1
}


# 需要修改相应的index.htnml的版本号
for p in `ls ${root}/*.html`;
	do 
	update_index_html_js_v $p ${jsfile}
done;

if [ -z $1 ] ;then
	read -p "脚本执行完成,输入任意信息结束..." var
fi
exit 0


 

