论坛首页 综合技术论坛

一个自动化打包上传的简单shell工具

浏览 1891 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-11-02  

开发完成之后,需要将本地的环境进行打包,并部署到测试环境,一般需要经过这几个步骤, 1.mvn install 2.执行make-rpm.sh脚本 3.执行scp将本地的rpm包拷贝到测试服务器中。每次的敲代码也比较人肉,所以写了一个shell脚本,将这几部串起来。因为考虑到有些时候,我们其中一步失败,而不想重头在来,所以脚本我支持通过1,2,3的数字进行选择,具体看代码吧。

 

#!/bin/bash
#install

command=$1
username=$2
host=$3



function info(){
	echo 'use ./deploy.sh command [username] [host]'
	echo 'command:'
	echo '0  -- exec all action,contains:install makeRpm upload'
	echo '1  -- exec install'
	echo '2  -- exec makeRpm'
	echo '3  -- exec upload,the username and host only affect this action.'
}

function all(){
	install 
	makeRpm
	upload
}

function install(){
	echo 'mvn install'
	mvn clean install -Denv=release -Dmaven.test.skip=true >>/dev/null
}

function makeRpm(){
	echo 'make-rpm,please make u rpm version is 4.4.x'
	./make-rpm.sh>>/dev/null
}

function upload(){
	echo 'upload the rpm to server'
	if [ -z $username ];then
		username='xxx'
	fi
	if [ -z $host ];then
		host='xx.xx.xx.xx'
	fi
	scp ./target/rpm/RPMS/noarch/*.rpm $username@$host:/home/$username/ >>/dev/null
}

#start execute
info
echo 'deploy start'
if [ -z $command -o $command = 0 ];then  #这里面-o是或的关系,-a是and关系
		all
	elif [ $command = 1 ];then
		install
	elif [ $command = 2 ];then
		makeRpm	
	elif [ $command = 3 ];then
		upload	
fi

echo 'deploy success!'
 
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics