| 1 | #!/bin/bash |
| 2 | |
| 3 | # ============================================================================ |
| 4 | # Copyright (C) THALES. All rights reserved |
| 5 | # Author: Laurent Mazet |
| 6 | # Date : 02/05/2014 |
| 7 | # * 05/12/2014 ajout tarbal acq et rec |
| 8 | # ============================================================================ |
| 9 | |
| 10 | # TODO |
| 11 | # * |
| 12 | |
| 13 | PROGNAME=$(basename $0) |
| 14 | BLADES="acq slave rec" |
| 15 | CLUSTER=/opt/cluster |
| 16 | EXCLUDE=/tmp/$PROGNAME-exclude-$$ |
| 17 | TFTP=/opt/tftp |
| 18 | TMPLOG=/tmp/$PROGNAME-$$.log |
| 19 | VER=1.0 |
| 20 | |
| 21 | # help function |
| 22 | |
| 23 | function 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 | |
| 32 | function title () { echo -e "\033[0;1m$*\033[0;0m"; } |
| 33 | function pass () { echo -e "\033[1;32m$*\033[0;0m"; } |
| 34 | function warn () { echo -e "\033[1;33m$*\033[0;0m"; } |
| 35 | function fail () { echo -e "\033[1;31m$*\033[0;0m"; } |
| 36 | # check command |
| 37 | |
| 38 | function 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 | |
| 47 | while [ $# -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 |
| 54 | done |
| 55 | |
| 56 | # create exclude list |
| 57 | cat - <<EOF > $EXCLUDE |
| 58 | *~ |
| 59 | *.bak |
| 60 | .*.swp |
| 61 | .#* |
| 62 | EOF |
| 63 | |
| 64 | # create tarballs |
| 65 | _OLDPWD=$(pwd) |
| 66 | for 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 . |
| 73 | done |
| 74 | cd $_OLDPWD |
| 75 | |
| 76 | # clean exclude list |
| 77 | check rm -f $EXCLUDE |
| 78 | exit 0 |