3 SSH_AGENT_FILE
="$HOME/ssh_agent_file"
6 LOG_INFO
="$RYZOM_PATH/log/${BASENAME}_info.log"
7 LOG_ERROR
="$RYZOM_PATH/log/${BASENAME}_error.log"
9 # first param is the subject line
10 # others params are email
15 echo Send
mail to $
* with log
$LOG_ERROR in body and subject
$SUBJECT
16 cat $LOG_ERROR |
mail -s "$SUBJECT on `hostname`" $
*
21 echo "*********************** $* SUCCESS !"
27 echo "***************************************************"
28 echo "***************************************************"
29 echo "*********************** $* FAILED"
30 echo "***************************************************"
31 echo "***************************************************"
35 # failed fill the log and send email if necessary
36 # argument are the error message
40 if [ "X$LOG_INFO" != "X" ]
42 print_failure $
* >> $LOG_INFO
44 if [ "X$LOG_ERROR" != "X" ]
46 print_failure $
* >> $LOG_ERROR
49 if [ "X$MAIL_ERROR" != "X" ]
51 send_mail
"$* FAILED" $MAIL_ERROR
53 echo "No email to send the error mail" >> $LOG_ERROR
60 # useful function to avoid continuing if something goes wrong
61 # first param is $? and second is the string that will display
68 if [ "X$LOG_INFO" != "X" ]
70 print_success $
* >> $LOG_INFO
72 if [ "X$LOG_ERROR" != "X" ]
74 print_success $
* >> $LOG_ERROR
82 # step_failed() fills the log and increments $STEPS_FAILURES
86 if [ "X$LOG_INFO" != "X" ]
88 print_failure $
* >> $LOG_INFO
90 if [ "X$LOG_ERROR" != "X" ]
92 print_failure $
* >> $LOG_ERROR
95 if [ "X$STEPS_FAILURES" = "X" ]
99 STEPS_FAILURES
=`expr $STEPS_FAILURES + 1`
103 # call init_steps() before you use step()
104 # it takes a label for following steps as parameter
111 # like verify() but will continue even if step failed until verify_steps() is called
112 # first param is $? and second is the string that will display
119 if [ "X$LOG_INFO" != "X" ]
121 print_success $
* >> $LOG_INFO
123 if [ "X$LOG_ERROR" != "X" ]
125 print_success $
* >> $LOG_ERROR
133 # call verify_steps() when you want to stop if error(s) occurred in previous steps
136 if [ $STEPS_FAILURES -eq 0 ]
138 print_success
$STEPS_LABEL
139 if [ "X$LOG_INFO" != "X" ]
141 print_success
$STEPS_LABEL >> $LOG_INFO
143 if [ "X$LOG_ERROR" != "X" ]
145 print_success
$STEPS_LABEL >> $LOG_ERROR
148 if [ $STEPS_FAILURES -eq 1 ]
150 failed
"1 step failed: $STEPS_LABEL"
152 failed
"$STEPS_FAILURES steps failed: $STEPS_LABEL"
159 echo "Using this script will destroy the current version, type 'yes' if you really want to do that"
161 if [ "X$CONF" != "Xyes" ]; then
162 failed
"You didn't answer 'yes', I stop the script!"
169 if [ "X$HOST" != "X$1" ]; then
170 failed
"You can execute this script only on '$1' and not on '$HOST'"
174 # useful function to initialize the default log for all scripts
177 if [ "X$LOG_INFO" != "X" ]
179 test -d `dirname $LOG_INFO` || mkdir
-p `dirname $LOG_INFO`
180 test ! -f $LOG_INFO ||
rm $LOG_INFO
182 # display all ulimit in the log
183 ulimit -a >>$LOG_INFO
186 if [ "X$LOG_ERROR" != "X" ]
188 test -d `dirname $LOG_ERROR` || mkdir
-p `dirname $LOG_ERROR`
189 test ! -f $LOG_ERROR ||
rm $LOG_ERROR
196 if [ ! -f $SSH_AGENT_FILE ]
198 failed
"the file $SSH_AGENT_FILE not exist, you must call create_ssh_agent_file first"
201 eval `cat $SSH_AGENT_FILE`