bash脚本:depweb.sh% r, D! @9 U. V$ b
运行环境:linux/UNIX操作系统,CVS配置管理库,ant工具,JDK
局限性:只对java代码进行构建
实现功能:取出全量版本标签(代码基线标签)代码,进行构建,封装打包(tar ball)
把包发布给部署人员进行部署,部署完毕通知测试人员可以对此版本产品进行测试。" ~) |( }$ q* ^& `% |
编写此脚本的目的:简化基于java代码项目的编译,完成一个通用java代码的构建脚本,通过对配置文件的设置来达到对多个项目进行构建。; o, ]% | ^4 j7 n$ F2 N6 g
运行前可以通过执行
depweb.sh -h 来查看脚本的帮助(简明使用方法)# |# w! b+ k- p2 g, V8 r& f
运行前需要设置配置文件,可以通过执行2 u& r' O: h% Q8 a
depweb.sh -i project ' w. }% k" X# s2 b! ^1 b8 Z$ V
生成project-build.properties配置文件,配置文件内容填写实例如下:)
- # Must set the "CVSROOT" environment variable
- CVSROOT=:pserver:user:passwd@cvs-server:/cvs/repository/root# I# G+ d. l( T- R% I1 H9 v) Y
- # Must set the module name of project in CVS Repository( Q1 H* A! a3 |5 v2 \6 o6 H
- MODULE_NAME=projectsample' I, \) }( O J
- # Must set the "$module" source code path relative to \$CVSROOT5 z# j* v3 w _; b3 ]0 f' K
- SRC_PATH=projectsample/codepath/ L F6 T8 u3 J$ E
- ( z# J& ^( D; k" |+ ] }4 x
- # Must set the java files path relative to $SRC_HOME
- javadir=src"
- # Must set the class files path relative to $DST_HOME4 j" V, ~$ v& b& o! m3 L* u4 q9 B
- classdir=WEB-INF/classes
- 6 h p7 ?' d3 v5 _$ q
- # Must set the jars path relative to \$SRC_PATH3 ?. m* P& h0 H1 [7 X
- srclib=WEB-INF/lib
- - m3 J* |) O) S
- # The absolute common lib path
- svrlib=/userhome/soft/tomcat/common/lib
- 以下内容为脚本内容,此内容包含整个构建打包过程以及一个build.xml的模板
- ####################################################
- #prog:depweb.sh # C6 u$ X+ `" N+ ~& ~6 e
- #func:Web Application build create and tar package #+ v7 @1 n( ?" G5 _, v- T- @
- #vern:1.6 #
- #auth:liurs #
- #comp:FORLINK #1 p* `6 k3 O9 r% r) x
- ####################################################+ V! n9 t2 K, |9 o/ y2 \
- #!/bin/sh
- 2 g# K4 V1 a% z1 N+ H
- usage()
- {* P" S3 \3 u$ K6 V
- clear5 s1 _0 t' z& j5 y- y5 ?& a
- echo "USAGE: $PROG [-a|--add] [-h|--help] [-i|--initial] [-c|--complete]"
- echo 5 `" O4 }7 O, e( d7 q0 j
- echo "WHERE: -h --help = Display help infomation"
- echo "Usage: $PROG -h|--help" & W4 ~& k' V' n: e% t
- echo
- echo " -i --initial = 设置配置文件,初始化构建环境"
- echo "Usage: $PROG -i <模块名>"
- echo; ^7 ^1 r: `6 F" r) x4 T* I; }: f
- echo " -a --add = 直接增量部署,用如下格式:"
- echo "Usage: $PROG -a <增量标签> <模块名>"
- echo
- echo " -c --complete = 初始全量部署,用如下格式:"5 [. G A) u3 Y% L
- echo "Usage: $PROG -c <全量标签> <模块名>"
- echo: l% Z4 b. S8 Y; _1 V+ C& H
- echo "正常全量部署,用如下格式:") B2 f8 d5 r& F9 s& O0 u( B+ T. t P) h
- echo "Usage: $PROG <全量标签> <模块名>"; e8 ?" r+ |. s2 W
- echo( \. H. a. T: N, ?, [
- return 0
- }
- 0 b9 Y. o3 X. l
- setsample()+ [7 W: N8 E0 Y# ~
- {
- clear- ^7 M# K, V+ Z7 w4 C" S
- echo "PREREQUISITES:"7 K/ |9 `0 W# u- L% ]! [- y- k! `" w0 l
- echo6 k) I8 m5 j9 u: W8 J3 z$ k% M8 T. R
- echo "* The $HOME/build/\$MODULE-build.properties must be set", s, a3 a! ^" |1 I- b
- echo "* such as: "
- echo
- echo "# Must set the "CVSROOT" environment variable"3 s* M; P M+ X0 ~7 j
- echo "CVSROOT=:pserver:user:passwd@cvs-server:/cvs/repository/root"7 f. m ?: Q+ Q; X! J% c5 I
- echo
- echo "# Must set the module name of project in CVS Repository"
- echo "MODULE_NAME=projectsample", P# {* ?; y3 Q; H$ j/ e5 ~! i
- echo% o4 {, i! M! g( n2 B( g# s, P/ J
- echo "# Must set the "$module" source code path relative to \$CVSROOT"! q9 z9 l+ l r5 _6 a3 X
- echo "SRC_PATH=projectsample/codepath/"
- echo
- echo "# Must set the java files path relative to $SRC_HOME"
- echo "javadir=src"
- echo
- echo "# Must set the class files path relative to $DST_HOME"
- echo "classdir=WEB-INF/classes"$ a: P. O' m! @/ d" S3 A
- echo4 J5 K0 A3 b4 Y/ n
- echo "# Must set the jars path relative to \$SRC_PATH"! \, w8 m5 I. R
- echo "srclib=WEB-INF/lib"6 g7 d4 M$ P6 g4 R4 {& Z. g
- echo2 ?" w4 }# p: x. O6 P6 I* J
- echo "# The absolute common lib path"
- echo "svrlib=/userhome/soft/tomcat/common/lib"
- echo8 I" \9 Q$ Z% `$ ]: M' @- K
- return 0 5 C% R' J0 ?; t
- }
- 8 _: \9 \9 w* k' q
- echoxml()
- {" [' i* C, j3 E( D
- echo '
; n, ?/ }# x! y4 f -
-
* G5 L6 c9 C$ D -
-
3 c4 G! G+ F7 w -
-
-
-
" T# ~: U% `; b! A+ c8 G -
-
/ p% E) B& n0 x% E( U6 j& g -
-
-
-
/ {% w" [* w' D s -
-
$ O' [% G% N- q2 H! E* Q; | -
' g/ g' n6 Z. z) W, n -
-
- ' M' r/ N" b( g. ?4 T# }; S+ d; `
-
-
4 _5 J9 p E3 F) ]& s -
: i5 ^! y8 n3 X! u5 r - - L* _9 e) J! v0 h7 q' G
- 8 a0 a3 E" J4 e( c
-
- : ?/ c7 H' R0 n* u
-
' e* E# P7 h" { _1 Z* w -
-
-
, o5 X4 h8 O/ D+ e* G - 6 T6 R6 g1 z$ R0 F6 E2 a, H
-
! t6 Y9 [- C" t5 q* a3 u/ i -
-
: v n: Q3 O) S. q - 1 }% t2 }: I( U
- / z- ^) }& D7 z3 S% `0 N4 T% F
- + K7 V7 N) d, ^: K# q4 Z1 M0 V7 J
-
-
6 J0 A3 O( U) P$ ^ -
-
-
- * n2 [1 d+ h- n7 N
- 0 T+ n6 G5 e: d- B# [5 q* @$ F
- 8 G* G( E* z+ a3 F9 R
-
-
9 h& i3 L" P! S. [- n% Y) ~$ N -
/ H4 W* K Y8 L! P4 E# ]2 I. [ -
. @, n4 Z6 V2 p: n/ e: ~ -
-
2 ]" R5 I$ ^9 y* C% i) X - 6 o. `. i8 `' h0 }- p* ~
-
7 H9 K5 A/ o/ w5 z) c, ? -
! a) f( L( r- Z -
) c1 ^& B: h& d- z, j. {. i9 F! K4 e -
- : Q6 v( k" j; g- E0 x, X
- 3 r9 F3 f. w4 }' q. \) c( G3 O4 ^
- S+ S1 E. M O5 l6 E; ^, B
-
% D% ~. V1 r1 `+ ]3 z. F -
-
7 L* u3 V+ G* N! `- J -
-
F' r8 S& ?, o8 Q/ E -
9 n. T$ x+ d4 U - ' E p7 y+ o/ S X |
- 2 |. S L# u) t6 x _: b w
-
-
! I2 a2 I! B) W - ! Q3 ]0 ^, a7 t7 |: I' r, V# w. B
-
Y5 ?0 R* H+ ~- c- f+ O& c* Z# \ -
: }2 S$ p+ P' n ]3 ^+ ~ -
- '
- return 0
- }
- : C5 Y, w" v$ z( k9 v# l6 E6 F
- echocfg()4 m+ w' O) S5 C; Z0 d C7 W
- {! C8 I) x" L5 d) j9 x4 \, I
- echo '#The config file of depweb.sh and build.xml
- ) [* s# _% Z; _6 f( I' u1 I! _
- # Must set the value of "CVSROOT" environment variable
- CVSROOT=
- # Must set the module name of project in CVS Repository
- MODULE_NAME= n, Y1 U. |7 @9 c
- - D" s; G5 d% N
- # Must set the "$module" source code path relative to \$CVSROOT3 o" q, h4 G1 v' A: b
- SRC_PATH=
- 7 y- z) w( m+ V( S* U" q; k5 z
- # Must set the java files path relative to \$SRC_HOME
- javadir=7 ]/ s6 j1 p$ R5 t
- # Must set the class files path relative to \$DST_HOME( s1 o. d, C# t7 B& T7 W; Q: t9 ]
- classdir=
- # Must set the jars path relative to \$SRC_PATH: W# I; P* N9 |; q) w5 i h# J
- srclib=) b* v# J: K0 t" Q/ m
- # Set the absolute common lib path* i0 n5 _$ d7 r `
- svrlib=
- '6 I/ B o' \" K4 o0 x. z
- return 0/ v1 }% X6 y a" h# F6 P
- }( d" Z* d7 P6 k) x
- cmpdir()
- {
- echo '. a* `1 N- v; P: C
- #!/bin/sh( M* m5 [0 {' o
- cmp_dir()3 n0 d% l* `: K% k: A7 v
- {
- RET=0
- cd $HOME_DIR
- DIFF_NAME=$HOME_DIR/diff.err# b: O( _- \# x: M1 e3 ~
- EXIST_NAME=$HOME_DIR/$3.exist.err* m7 R6 t/ S4 ^0 I
- >$EXIST_NAME
- >$DIFF_NAME/ V7 c' \3 A7 \9 ^1 Y+ c( b" w
- if [ ! -d $1 ]
- then, V7 n5 A* m& y9 K
- echo directory $1 does not exit!
- exit 1% {* h% B, L6 |2 M! Z, F
- fi8 w' M2 Q2 H( N/ C/ E
- if [ ! -d $2 ]
- then
- echo directory $2 does not exit!
- exit 2
- fi4 m: `# }6 ^9 @- ]
- cd $1
- for i in `find . -type f ! -path "*\ *"`( \& I8 U% W6 w4 V4 M
- do
- if [ -f $2/$i ]& H* C! [& s1 Q# u
- then
- cmp $1/$i $2/$i >/dev/null 2>/dev/null5 @/ `: }6 p+ U3 q
- if [ $? -ne 0 ]
- then8 J- Y4 v( o# S: B
- #echo $1/$i9 y' H% {4 n/ F
- RET=15 P3 I+ f8 C+ c; e
- echo $i >>$DIFF_NAME
- fi
- else3 Z; M/ v6 @* v4 H5 W6 t+ B
- #echo $HOME_DIR/$2/$i >>$EXIST_NAME0 m# ?+ ?. [' c Z, C1 u9 W
- #echo $i
- RET=1
- echo $i >>$EXIST_NAME) g1 I9 z+ t: V/ X( \5 f5 O
- fi4 q. \& R/ C% o& ]" v0 w
- done
- cd $HOME_DIR' g) T4 G; |, k/ |9 I) A
- return $RET
- }* d2 I+ p, K, d7 u
- 3 {/ T8 U" h8 I. ` i
- HOME_DIR=`pwd`
- if [ $# -ne 2 ]4 C! T& c) I9 r8 S2 N
- then
- echo "Usage: `basename $0` 目录1 目录2"
- exit -1% l( o+ \2 e4 C7 |! ~, D
- fi) i0 I3 E% F( r' C
- : u0 C# H4 q, M) P6 b, z! U, T
- DIR_1=$1
- DIR_2=$2
- 2 |8 w0 b- i% Q# I0 `
- if [ `expr substr $1 1 1` != "/" ]- v: {0 R: X; T
- then7 n; K$ O; M5 E# X
- DIR_1="$HOME_DIR""/""$1"
- fi
- if [ `expr substr $2 1 1` != "/" ]. q' ]0 M0 j/ x, V% |( m
- then+ g# n3 _' D+ g. h
- DIR_2="$HOME_DIR""/""$2"
- fi
- 7 M7 Z$ d: f8 y- N
- #echo 第一个目录
- cmp_dir $DIR_1 $DIR_2 1
- RET1=$?; N# g7 c" r [0 g1 w1 O# i
- #echo 第二个目录
- cmp_dir $DIR_2 $DIR_1 2" v! Q% T3 }- Q& x* R. W
- RET2=$?
- RET=0! F9 C! w! L0 s3 B, i
- cd $HOME_DIR) h7 G. J0 i6 o! V
- if [ $RET1 -ne 0 -o $RET2 -ne 0 ]
- then, D) N2 ?+ I! k6 r
- echo "不同"$ i1 f; c( i- C0 S9 Y1 K+ Z7 T
- ls -l 1.exist.err 2.exist.err diff.err: L1 J! Z9 ]% M" R+ f
- RET=15 H( B9 U6 [3 u
- fi; o1 ^4 M: i2 H. Y
- exit $RET'2 \ f. @/ V2 ^6 p$ U" _
- return 0& r; P+ \+ C: U
- }3 q7 ~3 |/ A' t6 ^/ e
- ! G. c0 c* E @0 G; R
- #check environment
- if [ -z $JAVA_HOME ]
- then/ S: H3 @# `" q$ C1 W% S
- echo "Environment is wrong,please check the environment!"
- exit 1: M( g* f8 u2 k7 k9 z. J/ m
- fi6 N' q, o4 T- X8 W6 ~6 T% i
- & k9 D- Z' q4 r( ?0 J
- if [ -z $CVSROOT ]- f( C* H/ t* _$ B- d G/ W" O
- then
- echo "The CVSROOT environment variable isn't setted"
- #exit 1
- fi" h4 K9 X' d; Q% [) y9 B
- + J: H, B( V9 q' E% o# L" L& X% E# p
- if [ ! `which cvs` ]
- then
- echo "The cvs command is not setted in \$PATH or cvs isn't installed!"
- echo "Please check the environment or installed"
- exit 1
- fi) `" G1 {# w2 q$ ?( X7 D* x9 M
- 3 g" h1 {9 c6 C. i9 `8 F+ Z
- if [ ! `which ant` ]
- then
- echo "The ant isn't installed"
- echo "Please install the ant"
- exit 1
- fi
- if [ ! `which cmp_dir` ]
- then
- if [ ! -d $HOME/bin ]/ I, W3 d: F2 i; u5 R, S
- then9 F0 U# y3 Q3 ~7 N& n3 w3 x) C
- mkdir -p $HOME/bin
- fi
- cmpdir >$HOME/bin/cmp_dir
- chmod +x $HOME/bin/cmp_dir
- export PATH=$HOME/bin:.:$PATH6 P' v" h* H8 g! r% r0 q+ }
- fi& b& `" F8 ]' {5 ^$ h; F3 n- v
- PROG=`basename $0`, T& W# b- g1 v3 o5 G, b
- ARGV="$@"
- ARGC="$#"
- export DATE=`date +%Y%m%d`
- if [ `uname` = Linux ]' r$ k/ w) K! a8 m/ M
- then
- export LANG=zh_CN.GB23121 {% o7 f7 G R: _ l
- elif [ `uname` = HP-UX ]
- then
- export LANG=zh_CN.hp15CN
- else/ g! E, F. _3 U8 H
- LANG=`echo $LANG`" x! s* H+ G$ I3 t
- fi
- if [ $ARGC -lt 1 -o $ARGC -gt 3 ]
- then
- usage;exit 1;
- fi/ `& N( i, W- h5 o
- if [ `uname` = Linux ]
- then8 D# a7 ]/ [: ?; @2 C9 b; T
- OPTS=`getopt -n 'depweb.sh' -o haic -l help,add,initial,complete -- "$@"`& `9 Z3 f, N9 F
- else \. h# j$ @: v% i
- OPTS=`getopt haic: $*`
- fi6 U! R, y: P+ F0 Q: j6 g
- if [ $? -ne 0 ]; h9 _% T* [/ K0 p& H, [8 V( m+ N
- then
- echo "Please use $PROG -h"
- exit 1
- fi
- #eval set -- "$OPTS"% [3 j, ?- p8 e4 q! |) e% l' A- g; T
- for args in $OPTS
- do
- case "$args" in0 _. y+ b. X4 U+ b% m: G' H( X
- -h|--help) . ~/ i% _/ v3 N6 q! e
- if [ $ARGC -ne 1 ]8 P7 ~4 i" m! g' k/ y: r
- then
- usage "HELP";exit 1; # Help requested3 O" j# C4 d* w# Y5 g- b
- fi
- usage;exit 0;; G& ?, Y" O. e6 R8 P" R+ N
- -a|--add)
- if [ $ARGC -ne 3 ]( ]: ?6 d. F+ S' @! _
- then
- usage;exit 1;
- fi/ ^% T, a% W' C5 v/ ~( S
- export CVSTAG=$23 O' o4 p F1 B2 [5 V" O( w' G
- export MODULE=$3
- BUD_CFG="$HOME/build/"$MODULE"-build.properties" 7 Y% f( O; L2 J" U$ d9 q
- if [ ! -f "$BUD_CFG" ]
- then 1 H- Q2 K" ?# [
- echo "Please initial the $MODULE" 6 k4 p0 o+ u# ~" I
- echo "Please use: "depweb.sh -i <$MODULE>""
- exit 1
- fi 2 w r2 T$ d- V: }8 V
- FLAG="add";; v) |+ y. u, v! y5 _
- break;;
- #shift;; #add files deploy* {9 ]' g( y& t+ Z5 w
- -i|--initial)
- if [ $ARGC -ne 2 ]
- then
- usage;exit 1; * |% W2 T8 Y! D. z2 @6 @5 E
- fi9 Q. v, h* D- U" G. N1 {- h7 f
- if [ ! `which vi` ]; P0 f$ O/ V1 C( U7 V2 F% D
- then * G5 c, q R, H0 E6 R- \0 Q
- echo "Not install vim"
- exit 13 X$ |# O* U* G( W
- fi. c2 w5 z0 a+ L2 H# \8 v" |
- export MODULE="$2"
- BUD_CFG="$HOME/build/"$MODULE"-build.properties"
- if [ ! -f "$BUD_CFG" ]
- then
- if [ ! -d $HOME/build ]! b. k2 o! D( c) F
- then1 @: V. q5 W/ w) h& E/ Y6 k" ]
- mkdir -p $HOME/build
- fi" s) `; y! e+ G6 {1 o
- echocfg>"$BUD_CFG"
- fi- W( |9 |; {( I% G& J
- setsample;
- echo "********************************************"8 P0 i& H! z! N- z% p. g
- echo "Please set the properties file"9 C" N+ c5 A& J1 J7 H
- sleep 3) n' r) T4 v( l; R
- vi "$BUD_CFG"3 f) ~8 a, l/ v. K) [
- exit 0 ;;
- #break;;
- #shift;; #increase files deploy
- -c|--complete)
- if [ $ARGC -ne 3 ] 8 Z% o+ o; q' G' n7 @, N
- then1 s; U& z: F; i9 A r/ a |
- usage;exit 1;
- fi
- export CVSTAG=$2
- export MODULE=$35 X" Q0 {) T" @7 w, D$ ~# |
- BUD_CFG="$HOME/build/"$MODULE"-build.properties"
- if [ ! -f "$BUD_CFG" ]
- then
- echo "Please initial the $MODULE" ' [: K6 v# h! c7 m; g' z: U8 G# b
- echo "Please use: "depweb.sh -i <$MODULE>"": E, ^: w# O2 F3 t
- exit 1 : C5 L: B7 [ n) n2 y4 L
- fi
- FLAG="complete";' d' s4 V4 U- W$ f" m0 R1 d+ X
- break;;' F1 n- W0 H! I( K. f" B0 Q
- #shift;; # complete files deploy
- --) 2 K6 d0 e* G$ G! ?8 \
- if [ $ARGC -ne 2 ]
- then
- usage3 B+ l0 m- S/ O3 N
- exit 17 q. P V% L3 J& f! L/ {
- fi
- export CVSTAG=$12 ? @! \5 {. q* u4 T4 _( X
- export MODULE=$2
- FLAG="cmpold"
- break;;
- #shift; break;; % |8 m4 b" b b5 \
- *) 9 F+ x7 C/ i8 m( a
- usage; exit 1 ;;8 L8 R! ~! F U ]9 }
- esac4 y% ^7 \5 ~4 w: Y3 z6 V+ e# V7 [
- done1 B+ s! S& t* Z$ n0 H& C( E
- #init part/ f; \, z" `% i7 R
- ' J% h$ L5 O8 W
- rm -rf $HOME/build/src! h* @7 y1 ^# T8 \' [% f, u: F
- if [ ! -d $HOME/bin/tmpdir ]
- then$ t% u) { d. h. P0 u+ y
- mkdir -p $HOME/bin/tmpdir& H! @" _, V% F+ N0 B
- fi
- if [ ! -d $HOME/build ]
- then . L7 U `& U0 U6 V
- mkdir -p $HOME/build
- fi
- if [ ! -d $HOME/build/src ]
- then ]2 h% H9 H2 u% ~. D
- mkdir -p $HOME/build/src+ t! [. s) s9 _6 H( r8 o a# Y
- fi) P7 g, l: }( B. N, r1 V# ~ n
- if [ ! -d $HOME/build/dest ]
- then3 Q9 D# ?; D0 Z" |
- mkdir -p $HOME/build/dest
- fi
- if [ ! -d $HOME/build/deploy ]
- then" F0 ^ A2 `- f) `/ U
- mkdir -p $HOME/build/deploy, T8 D0 @# `, ?- Y; N# N
- fi
- if [ ! -d $HOME/deploy ]
- then0 ~ r3 A; q2 T0 l8 O
- mkdir -p $HOME/deploy
- fi
- export SRC_HOME=$HOME/build/src1 j' A( \2 u D2 ^8 Y4 |/ ^
- export DST_HOME=$HOME/build/dest; `3 @& I: q# J8 O* Q; @
- export DEP_HOME=$HOME/build/deploy
- export WWW_HOME=$HOME/build/deploy/$MODULE4 `& D f4 E' o
- ; O5 H9 j# J( \; G( ]
- BUD_XML="$HOME/build/build.xml"
- . g% S5 t( R' d3 F, h# ^9 [
- if [ ! -f "$BUD_XML" ]
- then
- touch $BUD_XML5 l Z5 l/ \6 M) K5 e
- echoxml >$BUD_XML* U9 W! I5 d1 E6 \1 x# M
- fi
- BUD_CFG="$HOME/build/"$MODULE"-build.properties"
- * a- I& D' |% K! ^: @& X4 C
- if [ ! -f "$BUD_CFG" ]. ] B) D8 F4 b; {2 p
- then/ W* W/ i0 l N/ N
- echo "The $MODULE has not been initialed!"
- echo "Please use: "depweb.sh -i \<$MODULE\>" to initial the \<$MODULE\> module"
- exit 1
- fi; Q- K1 H: V3 J+ h
- " R1 A% K; [' J
- export CVSROOT=`grep "CVSROOT=" "$BUD_CFG"|awk -F = '{print $2}'`' T6 ^1 _4 N, k1 `* ]# i' ^
- SRCPATH=`grep "SRC_PATH=" "$BUD_CFG"|awk -F = '{print $2}'`4 O9 r. k; q I' f7 _
- if [ ! "$SRCPATH" ]# n! [2 R# a- O% T/ v
- then
- echo "Not appoint the path of source code in the $DEP_CFG"/ T) M3 p8 A- G/ u/ f. Y
- setsample! m0 w2 @* |# p+ j) I
- exit 1
- fi
- ( b$ C$ V8 G( }6 |1 Q7 T
- CONFLST=`cat $HOME/build/config.lst`
- DEPFILE=""$MODULE"-"$CVSTAG".tar"
- JAVADIR=`grep -w javadir "$BUD_CFG"|awk -F = '{print $2}'`
- SRCLIB=`grep -w srclib "$BUD_CFG"|awk -F = '{print $2}'`
- #========================build part========================#
- echo "cvs login"1 W. F; [5 O/ }+ Q
- cvs login
- echo "cd $HOME/build"8 m! p. ~: o. f' m- c4 q! _
- cd $HOME/build
- echo "cvs -q export -r "$CVSTAG" -d src "$SRCPATH""/ V; U* }! `: |
- cvs -q export -r "$CVSTAG" -d src "$SRCPATH"
- if [ $? -ne 0 ]/ t* I- E! u" m
- then
- echo "cvs export scode failed!"* B* T% l5 V# q, R
- exit 18 M. \. e! G6 r+ \0 p
- fi
- ant clean
- if [ $? -ne 0 ]
- then 9 K; n# |( D! V: ] y4 m! ~
- echo "ant clean target have error!"
- exit 1
- fi
- 2 |: _& _# e& f% R
- ant clnclass. I# L. B$ `0 L* Y1 {# Q
- ant copy
- if [ $? -ne 0 ]
- then
- echo "ant copy target have error!"
- exit 1. u4 I/ Z( j& E3 w: |& i
- fi* \; R* e7 q0 v3 L7 J4 ?9 _
- ant clnjava' |6 q) l4 B& K5 ]6 H" ]3 m9 l
- x' B* e7 F t- p
- if [ $FLAG = "cmpold" ]6 K- P% b: H8 q
- then4 G" Y3 F: c5 {$ T% k, X' i1 `4 G
- export srclib=$SRC_HOME/$SRCLIB
- TARNAME="$MODULE"-"$CVSTAG"-add.tar
- if [ -d $SRC_HOME/$JAVADIR ]
- then- W [( @2 ^0 Z2 r$ s$ b% e- S8 o
- ant compile
- if [ $? -ne 0 ]
- then# q, d7 f/ ~( n3 H# M D. U
- echo "ant compile target have error"( C* c3 J( c4 _ r1 i- u
- exit 1- U- ~* N e: M' c+ q
- fi: j, s* i+ I0 F* O C8 _( ^
- fi
- cd $DST_HOME
- $ y( u* y( I6 d# R' E
- for i in $CONFLST. {/ [+ J; n6 j7 L$ }
- do
- find . -type f -name "$i" -exec rm -f {} \;$ ?) Y/ r: } k T2 q8 s
- done @) l; A6 h( {" r: G9 p% x. I
- tar cf "$DEPFILE" * ( a( `9 {9 ^% j' f: L8 Y9 Y+ A
- mv "$DEPFILE" "$DEP_HOME"8 G) c& Q+ l" S# |
- #========================package part========================#
- cd $DEP_HOME
- rm -rf "$MODULE"-dep% H4 n6 o$ n5 v' t8 ^$ t, E1 c% i
- mkdir -p "$MODULE"-dep6 g5 A, O* L, i# ?
- cp "$DEPFILE" $DEP_HOME/"$MODULE"-dep
- cd "$MODULE"-dep* }" x9 a* ?$ n* l/ d
- tar xf "$DEPFILE"
- rm -f "$DEPFILE"
- cd $DEP_HOME
- , n9 L, s& H, K2 r' V8 H
- cmp_dir "$MODULE" "$MODULE"-dep7 [0 ]% Z0 r8 p8 ~( w
- if [ $? -ne 1 ]& `% I' a9 Y, M; j0 } w5 U
- then
- echo "#########################################"; K' v! y4 h5 s1 f/ M5 z5 ~
- echo "This version tag is the same to last tag!"" v$ m9 @6 p% i$ @6 @& ^, B: C
- echo "Please check whether this tag is the same to the last one!"4 X6 m( V7 B/ J. v7 h$ t4 `5 ]6 b
- exit 1# ^. Q6 p N0 v2 a& q
- fi
- cd "$MODULE"-dep
- tar cf "$TARNAME" `cat ../2.exist.err`) S" B9 F. {. n
- if [ -s $TARNAME ] 9 L# ~ W/ i4 e' E4 l$ P5 D$ f+ H! L
- then$ r" X# [! e9 ~
- tar uf "$TARNAME" `cat ../diff.err`
- else1 S# M9 d# V/ U+ p4 n
- tar cf "$TARNAME" `cat ../diff.err`
- if [ $? -ne 0 ]+ x% Z- u1 I. v0 ] k3 n
- then+ l1 x+ M/ f* C; I0 V2 y" ^
- echo "$TARNAME is not created !"
- exit 1
- fi
- fi$ S: j% I, [% T2 a$ C
- rm -rf $HOME/deploy/*
- mv "$TARNAME" $HOME/deploy
- cd $WWW_HOME4 x) K T% q+ e# y
- cp $HOME/deploy/"$TARNAME" $WWW_HOME
- tar xf "$TARNAME"
- rm -f "$TARNAME", `) k' W* o2 l9 m$ R
- echo "The add tar is created successfully!"
- ls -ltr $HOME/deploy/"$TARNAME"# L4 \: {) r8 Y" `1 D
- elif [ $FLAG = "complete" ]- c, u' e/ @+ ~0 T% g' x
- then
- export srclib=$SRC_HOME/$SRCLIB$ h2 U5 y! T" Q: N0 X5 R" B
- TARNAME="$MODULE"-"$CVSTAG".tar+ w* r. l' i0 W1 J8 B5 }; [
- if [ -d $SRC_HOME/$JAVADIR ]/ E: K' j( Q8 s3 v1 C3 ^
- then
- ant compile
- if [ $? -ne 0 ]
- then
- echo "ant compile target have error"
- exit 1
- fi
- fi
- / D5 ]& [! f4 O: t9 a
- cd $DST_HOME u b0 L9 b; ]% p
- tar cf "$TARNAME" *
- mv "$TARNAME" "$DEP_HOME"; x" {: u& t' K& v2 h
- rm -rf $HOME/deploy/*, @& {& g; ^: w7 S6 Q% p
- cp $DEP_HOME/"$TARNAME" $HOME/deploy
- cd $HOME/build/deploy U. v3 f4 M0 M2 P9 g$ s
- rm -rf $MODULE3 P& _1 L. g, O2 t1 Z& `) F
- mkdir -p $MODULE- S2 U# C4 P6 i/ `) n- k
- mv "$TARNAME" $MODULE
- cd $MODULE- p, p1 z/ b% Z
- tar xf "$TARNAME"
- rm -f "$TARNAME", m' q$ ]9 ]% K4 Y: F7 O" g& p: v6 f
- echo "The whole tar is created successfully!"
- ls -ltr $HOME/deploy/"$TARNAME"2 t7 G7 M9 d0 z9 r+ h4 G w
- elif [ $FLAG = "add" ]2 u! [) s' S7 S: [
- then) }& c8 O& b C4 m
- export srclib=$WWW_HOME/$SRCLIB
- TARNAME="$MODULE"-"$CVSTAG"-add.tar
- if [ -d $SRC_HOME/$JAVADIR ] ( M5 C$ W7 F) p l$ ^
- then7 _: M% q! j8 y" A
- ant compile) X. R7 ~5 x X+ x }' E
- if [ $? -ne 0 ]* p/ x$ t4 y+ H2 O1 k+ Q; A
- then- k/ S7 Q. U8 T# Y
- echo "ant compile target have error"& A/ r& i4 a# l3 ?7 a
- exit 14 k7 t2 }6 [* _4 Q W1 ~
- fi
- fi( k; M( Y! Y) g/ a0 X
- cd $DST_HOME
- tar cf "$TARNAME" *
- mv "$TARNAME" "$DEP_HOME"
- cp "$DEP_HOME"/"$TARNAME" "$DEP_HOME"/"$MODULE"" ?7 c; Y4 f5 w) R6 C6 X; I
- rm -rf $HOME/deploy/*
- cp "$DEP_HOME"/"$TARNAME" $HOME/deploy
- cd "$DEP_HOME"/"$MODULE"
- tar xf "$TARNAME"
- rm -f "$DEP_HOME"/"$MODULE"/"$TARNAME"
- echo "The add tar is created successfully!"* l. E2 K8 S1 R* d7 {4 T0 I" h7 F
- ls -ltr $HOME/deploy/"$TARNAME"
- else
- usage;exit 1;
- fi
其 实这个脚本的核心还是那个build.xml,如果抛却这些shell语句,就是一个java编译的build.xml而已,只是修改一下这个 build.xml掉用的properties配置文件,修改其中的参数就可以实现对不同的java项目的编译,因为java项目的核心就是对java代 码的编译,只要不脱离这个核心其他的都是辅助的,比如你的项目是基于web的项目,他就会把你相应的jsp、xsl、xml以及jpg等文件,按照定义好 的目录结构拷贝到同一目录下打包,毕竟基于java的web项目大都逃离不了WEB-ROOT WEB-INF/classes WEB-INF/lib等这样的目录结构嘛,如果是java应用程序,就会把编译好的class直接复制到例如bin lib这样的目录结构,统一打包,这是我根据我所接触的项目不断总结的,也许还有很多模式我没有接触到没有考虑到。
这个脚本还有一个可以单独独立出来的功能就是cmp_dir函数,这个函数的功能是实现了对两个目录进行比较的功能,最后的输出是3个文件列表,第一个文 件列表是在执行cmp_dir dir1 dir2时,dir1目录比dir2目录多出的文件列表,这个文件里列出的文件名只存在于dir1目录,第二个文件列表是dir2目录比dir1目录多出 的文件列表,这个文件里列出的文件名只存在于dir2目录,第三个文件列表是dir1和dir2目录里都存在但是文件内容不同的文件列表。
这个shell的主要流程是:
1.根据代码版本标签(基线标签)取出代码
2.对取出的代码进行编译和其他处理(其他处理主要是指拷贝、删除源代码、按要求建立目录结构等)
3.对构建结果进行打包封装( Z/ N5 J1 O& g# c6 x+ ? z- `9 S r% c
其中的细节设计到了公司的流程(特殊要求),比如进行版本3和版本2(或者版本1)比较的功能,主要是给出最新版本和上一版本的变更文件清单,部署的时候 可以采取全量部署和增量部署两种选择,因为可以根据需要生成全量包或者增量包,增量包里面的文件就是这两个版本变更的文件,顺便可以做一下变更确认达到减 少出错几率的目的,即可以确定我部署上去的文件会整个系统会有什么影响,这个流程并不是适合每个公司每个项目,所以最核心最能共用的部分还是那个 build.xml,把它从脚本里剥离出来,只要稍加更改就可以实现对大多数的java项目进行构建。
|