Blame view

tools/scripts/Tools.sh 2.02 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
d7e9e4b9d   Jean-François Rey   update bugfix stderr
32
33
          if [ $1 -eq $ERROR ]; then echo -ne " ###ERROR : $3
  " >&2 ; return 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
d7e9e4b9d   Jean-François Rey   update bugfix stderr
39
40
              if [ $1 = $WARN ]; then echo -ne " ##WARNING : $3
  "; return 0; fi 
e6be5137b   Jean-François Rey   reinitialized pro...
41
              # default info
d7e9e4b9d   Jean-François Rey   update bugfix stderr
42
43
              echo -ne " #INFO : $3
  " 
e6be5137b   Jean-François Rey   reinitialized pro...
44
45
46
47
48
49
50
51
          fi
      fi
  }
  
  # print_error(message)
  # - message : error message to print
  function print_error()
  {
d7e9e4b9d   Jean-François Rey   update bugfix stderr
52
53
54
55
      if [ $# -eq 1 ]
      then
          print_message $ERROR 3 "$1"
      fi
e6be5137b   Jean-François Rey   reinitialized pro...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  }
  
  # 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...
83
84
85
86
87
88
89
  # print_log_file(filename,message)
  # - filename : full path to log file
  # - message : message to log
  print_log_file()
  {
      if [ $# -eq 2 ]
      then
b427f103e   Jean-François Rey   update log info p...
90
          echo -e "$2" >> "$1"
135404bcf   Jean-François Rey   Modify verbose an...
91
92
      fi
  }