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