Import from Clearcase LIV_TRC6500_V2.2.3
[debian6500.git] / install / cluster / bin / create_slave_tarball.sh
1 #!/bin/bash
2
3 # ============================================================================
4 # Copyright (C) THALES. All rights reserved
5 # Author: Laurent Mazet
6 # Date : 02/05/2014
7 # ============================================================================
8
9 # TODO
10 # *
11
12 PROGNAME=$(basename $0)
13 BLADES="slave"
14 CLUSTER=/opt/cluster
15 EXCLUDE=/tmp/$PROGNAME-exclude-$$
16 TFTP=/opt/tftp
17 TMPLOG=/tmp/$PROGNAME-$$.log
18 VER=1.0
19
20 # help function
21
22 function usage () {
23 echo "usage: $PROGNAME [-h] [-v]"
24 echo " -h: help message"
25 echo " -v: version message"
26 exit $@
27 }
28
29 # formating functions
30
31 function title () { echo -e "\033[0;1m$*\033[0;0m"; }
32 function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
33 function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
34 function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
35 # check command
36
37 function check () {
38 echo -n "$@: "
39 { eval $@; } >&$TMPLOG && pass OK || { fail KO; cat $TMPLOG; ERR=yes; }
40 rm -f $TMPLOG
41 test ! "$TEST" = yes
42 }
43
44 # argument processing
45
46 while [ $# -gt 0 ]; do
47 case "$1" in
48 -h) usage 0;;
49 -v) echo "$PROGNAME: version $VER"; exit;;
50 *) echo "unknown argument ($1)"; exit 1;;
51 esac
52 shift
53 done
54
55 # create exclude list
56 cat - <<EOF > $EXCLUDE
57 *~
58 *.bak
59 .*.swp
60 .#*
61 EOF
62
63 # create tarballs
64 _OLDPWD=$(pwd)
65 for target in $BLADES; do
66 tarball=$TFTP/$target.tgz
67 repository=$CLUSTER/$target
68 [ -d "$repository" ] || { warn "directory '$repository' does not exist"; continue; }
69 [ -f $tarball ] && check rm -f $tarball
70 cd $repository
71 check tar czf $tarball --exclude-from $EXCLUDE .
72 done
73 cd $_OLDPWD
74
75 # clean exclude list
76 check rm -f $EXCLUDE
77 exit 0