下载服务器优化--自动下载,移动,部署。(imvipdlsvr)

来源:互联网 发布:ubuntu下dd制作img 编辑:程序博客网 时间:2024/04/29 10:18

#!/bin/bash
# This program package the original APK into a release-able format
# .apk
# Parameters
# Exit Code
# 0     Execution completed successfully.
# 1 Warning!
#255 Error!
#
#set +x
BASE_DIR=$(dirname $0)/..
. $BASE_DIR/boot
# read configuration
. $CONF_DIR/imvipdlsvr.conf
#
#import libraries
#. $LIB_DIR/core || exit 255
#. $LIB_DIR/core.android || exit 255
#. $LIB_DIR/log || exit 255

#exce update 1.0.0 android
#input order format
if [ $(whoami) != "root" ];then
 echo "Warning:you is not root user"
 exit 1;
fi
if [ $# == 0 ];then
 echo "usage:  repo <command> [--version] [--program] "
 echo "The most commonly used repo commands are"
 echo "   deploy: download program version in a special dir"
 echo "   for example: ./repo deploy 1.0.0 android "
 exit 255
fi
if [ $# == 1 ] || [ $# == 2 ] && [ $1 == "deploy" ];then
 echo "error: this command is not deploy or input command incorrect"
 echo "Try './repo'"
 exit 255
fi
if [ $# == 1 ] || [ $# == 2 ] && [ $1 != "deploy" ];then
 echo "error: this command is not deploy or input command incorrect"
 echo "Try './repo'"
 exit 255
fi
if  [ $# == 3 ] && [ $1 != "deploy" ];then
 echo "error: this command is not deploy or input command incorrect"
 echo "Try './repo'"
 exit 255
fi
if [ $# == 3 ] && [ $1 == "deploy" ];then
 ##
 ##cut android download address
 ##
 var=`sed -n '/ANDROID_SRC_URL2/P' $CONF_DIR/imvipdlsvr.conf | sed "s/||v||/$2/g"`
 androidurl=`echo ${var#*ANDROID_SRC_URL2=}`
 
 ## 
 ##test android-1.0.*.apk exit?
 find $DATA_DIR/src_pkg/$3/$3-$2.apk
 if [ $? == 0 ];then
 echo "Warning:$3-$2.apk is exist!"
 exit 1
 fi 
 ##not exit download android-1.0.0.apk
        tmp_dir=$(mktemp -d  $BASE_DIR/tmp.XXXXXX)
 wget -P $tmp_dir $androidurl
 #download success move to DATA_DIR/src_pkg
 if [ $? != 0 ];then
 echo "Warning:there is not the correct version program!"
 echo  "Warning:DOWNLOAD IS FAILURE!"
 exit 1
 fi
 if [ ! -d $DATA_DIR/src_pkg/$3 ];then
 mkdir $DATA_DIR/src_pkg/$3
 sudo chown www-data:www-data $DATA_DIR/src_pkg/$3
 fi
 if [ -e $DATA_DIR/src_pkg/$3/$3-$2.apk ];then
 echo "Warning:*/data/src_pkg have $3-$2.apk!"
 exit 1
 fi
 mv $tmp_dir/$3-$2.apk $DATA_DIR/src_pkg/$3/
 if [ $? != 0 ];then
 echo "Warning:Moving havn't successful!"
 sudo rm -r $tmp_dir
 exit 1
 fi
 sudo rm -r $tmp_dir
 write verison to android
 find $DATA_DIR/latest_ver/$3
 if [ $? != 0 ];then
 touch $DATA_DIR/latest_ver/$3
 sudo chown www-data:www-data $DATA_DIR/latest_ver/$3
 echo $2 > $DATA_DIR/latest_ver/$3
        echo "DOWNLOAD IS SUCCESSFUL!"
 exit 0
 fi
 sudo chown www-data:www-data $DATA_DIR/latest_ver/$3
 echo $2 > $DATA_DIR/latest_ver/$3
 echo "DOWNLOAD IS SUCCESSFUL!"
 exit 0
fi
 

原创粉丝点击