| 3 |
3 |
SSH_AGENT_FILE="$HOME/ssh_agent_file"
|
| 4 |
4 |
|
| 5 |
5 |
BASENAME=`basename $0`
|
| 6 |
|
LOG_INFO="$HOME/log/${BASENAME}_info.log"
|
| 7 |
|
LOG_ERROR="$HOME/log/${BASENAME}_error.log"
|
|
6 |
LOG_INFO="$RYZOM_PATH/log/${BASENAME}_info.log"
|
|
7 |
LOG_ERROR="$RYZOM_PATH/log/${BASENAME}_error.log"
|
| 8 |
8 |
|
| 9 |
9 |
# first param is the subject line
|
| 10 |
10 |
# others params are email
|
| 11 |
|
function send_mail()
|
|
11 |
send_mail()
|
| 12 |
12 |
{
|
| 13 |
13 |
SUBJECT=$1
|
| 14 |
14 |
shift
|
| ... | ... | |
| 16 |
16 |
cat $LOG_ERROR | mail -s "$SUBJECT on `hostname`" $*
|
| 17 |
17 |
}
|
| 18 |
18 |
|
| 19 |
|
function print_success()
|
|
19 |
print_success()
|
| 20 |
20 |
{
|
| 21 |
21 |
echo "*********************** $* SUCCESS !"
|
| 22 |
22 |
echo
|
| 23 |
23 |
}
|
| 24 |
24 |
|
| 25 |
|
function print_failure()
|
|
25 |
print_failure()
|
| 26 |
26 |
{
|
| 27 |
27 |
echo "***************************************************"
|
| 28 |
28 |
echo "***************************************************"
|
| ... | ... | |
| 34 |
34 |
|
| 35 |
35 |
# failed fill the log and send email if necessary
|
| 36 |
36 |
# argument are the error message
|
| 37 |
|
function failed()
|
|
37 |
failed()
|
| 38 |
38 |
{
|
| 39 |
39 |
print_failure $*
|
| 40 |
40 |
if [ "X$LOG_INFO" != "X" ]
|
| ... | ... | |
| 59 |
59 |
|
| 60 |
60 |
# useful function to avoid continuing if something goes wrong
|
| 61 |
61 |
# first param is $? and second is the string that will display
|
| 62 |
|
function verify()
|
|
62 |
verify()
|
| 63 |
63 |
{
|
| 64 |
64 |
if [ $1 -eq 0 ]
|
| 65 |
65 |
then
|
| ... | ... | |
| 80 |
80 |
}
|
| 81 |
81 |
|
| 82 |
82 |
# step_failed() fills the log and increments $STEPS_FAILURES
|
| 83 |
|
function step_failed()
|
|
83 |
step_failed()
|
| 84 |
84 |
{
|
| 85 |
85 |
print_failure $*
|
| 86 |
86 |
if [ "X$LOG_INFO" != "X" ]
|
| ... | ... | |
| 102 |
102 |
|
| 103 |
103 |
# call init_steps() before you use step()
|
| 104 |
104 |
# it takes a label for following steps as parameter
|
| 105 |
|
function init_steps()
|
|
105 |
init_steps()
|
| 106 |
106 |
{
|
| 107 |
107 |
STEPS_LABEL="$*"
|
| 108 |
108 |
STEPS_FAILURES=0
|
| ... | ... | |
| 110 |
110 |
|
| 111 |
111 |
# like verify() but will continue even if step failed until verify_steps() is called
|
| 112 |
112 |
# first param is $? and second is the string that will display
|
| 113 |
|
function step()
|
|
113 |
step()
|
| 114 |
114 |
{
|
| 115 |
115 |
if [ $1 -eq 0 ]
|
| 116 |
116 |
then
|
| ... | ... | |
| 131 |
131 |
}
|
| 132 |
132 |
|
| 133 |
133 |
# call verify_steps() when you want to stop if error(s) occured in previous steps
|
| 134 |
|
function verify_steps()
|
|
134 |
verify_steps()
|
| 135 |
135 |
{
|
| 136 |
136 |
if [ $STEPS_FAILURES -eq 0 ]
|
| 137 |
137 |
then
|
| ... | ... | |
| 154 |
154 |
fi
|
| 155 |
155 |
}
|
| 156 |
156 |
|
| 157 |
|
function ask_confirmation()
|
|
157 |
ask_confirmation()
|
| 158 |
158 |
{
|
| 159 |
159 |
echo "Using this script will destroy the current version, type 'yes' if you really want to do that"
|
| 160 |
160 |
read CONF
|
| ... | ... | |
| 163 |
163 |
fi
|
| 164 |
164 |
}
|
| 165 |
165 |
|
| 166 |
|
function check_host()
|
|
166 |
check_host()
|
| 167 |
167 |
{
|
| 168 |
168 |
HOST=`hostname -s`
|
| 169 |
169 |
if [ "X$HOST" != "X$1" ]; then
|
| ... | ... | |
| 172 |
172 |
}
|
| 173 |
173 |
|
| 174 |
174 |
# useful function to initialize the default log for all scripts
|
| 175 |
|
function init()
|
|
175 |
init()
|
| 176 |
176 |
{
|
| 177 |
177 |
if [ "X$LOG_INFO" != "X" ]
|
| 178 |
178 |
then
|
|
179 |
test -d `dirname $LOG_INFO` || mkdir -p `dirname $LOG_INFO`
|
| 179 |
180 |
test ! -f $LOG_INFO || rm $LOG_INFO
|
| 180 |
181 |
touch $LOG_INFO
|
| 181 |
182 |
# display all ulimit in the log
|
| ... | ... | |
| 184 |
185 |
|
| 185 |
186 |
if [ "X$LOG_ERROR" != "X" ]
|
| 186 |
187 |
then
|
|
188 |
test -d `dirname $LOG_ERROR` || mkdir -p `dirname $LOG_ERROR`
|
| 187 |
189 |
test ! -f $LOG_ERROR || rm $LOG_ERROR
|
| 188 |
190 |
touch $LOG_ERROR
|
| 189 |
191 |
fi
|
| 190 |
192 |
}
|
| 191 |
193 |
|
| 192 |
|
function init_ssh()
|
|
194 |
init_ssh()
|
| 193 |
195 |
{
|
| 194 |
196 |
if [ ! -f $SSH_AGENT_FILE ]
|
| 195 |
197 |
then
|