Blame view

tools/scripts/Tools.sh 1.98 KB
e6be5137b   Jean-François Rey   reinitialized pro...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #!/bin/bash
  
  #################################################
  # File :    Tools.sh                            #
  # Brief :   Tool functions                      #
  # Author :  Jean-François Rey                   #
  # Version : 1.0                                 #
  # Date :    13/06/13                            #
  #################################################
  
  # Type
  ERROR=2
  WARN=1
  INFO=0
  
  # Global Verbose variable (have to be define in scripts)
  # 0 : mute
  # 1 : basic info (start,config,end)
  # 2 : add process
  # 3 : all
  VERBOSE=0
  
  # print_message( verbose_level, message)
  # - message_type : ERROR, WARN, INFO
  # - verbose_level : level to print message
  # - message : the message to print
  function print_message()
  {
      if [ $# -eq 3 ]
      then
          # print error
135404bcf   Jean-François Rey   Modify verbose an...
32
33
          if [ $1 -eq $ERROR ]; then echo -ne "###ERROR : $3
  " > /dev/stderr; exit 0; fi
e6be5137b   Jean-François Rey   reinitialized pro...
34
35
36
          # check verbose level
          if [ $2 -le $VERBOSE ]
          then
f37e72eaf   Jean-François Rey   up
37
              #for (( dec=1 ; $dec<$2 ; dec++ )); do echo -ne "\t"; done
e6be5137b   Jean-François Rey   reinitialized pro...
38
              # print warn
135404bcf   Jean-François Rey   Modify verbose an...
39
40
              if [ $1 = $WARN ]; then echo -ne "##WARNING : $3
  "; exit 0; fi 
e6be5137b   Jean-François Rey   reinitialized pro...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
              # default info
              echo -ne "#INFO : $3
  " 
          fi
      fi
  }
  
  # print_error(message)
  # - message : error message to print
  function print_error()
  {
      print_message $ERROR 3 "$1"
  }
  
  # print_warn(message,[level])
  # - message : message to print
  # - level : optional option - verbose level to print
  function print_warn()
  {
      if [ $# -eq 2 ]
      then
         print_message $WARN $2 "$1"
      else
          print_message $WARN $VERBOSE "$1"
      fi
  }
  
  # print_info(message,[level])
  # - message : message to print
  # - level : optional option - verbose level to print
  function print_info()
  {
      if [ $# -eq 2 ]
      then
          print_message $INFO $2 "$1"
      else
          print_message $INFO $VERBOSE "$1"
      fi
  }
135404bcf   Jean-François Rey   Modify verbose an...
80
81
82
83
84
85
86
  # print_log_file(filename,message)
  # - filename : full path to log file
  # - message : message to log
  print_log_file()
  {
      if [ $# -eq 2 ]
      then
7e99f0793   Jean-François Rey   up
87
          echo -e "$2" >> $1
135404bcf   Jean-François Rey   Modify verbose an...
88
89
      fi
  }