-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachinefunc.sh
More file actions
101 lines (89 loc) · 2.92 KB
/
machinefunc.sh
File metadata and controls
101 lines (89 loc) · 2.92 KB
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
32
33
34
35
36
37
38
39
40
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
source config.sh
RED="\\E[5;33;41m"
GREEN="\\E[1;32m"
YELLOW="\\E[1;33m"
RESET="\\E[0m"
success() { [ $# -ge 1 ] && echo -e $GREEN"$@" $RESET; }
error() { [ $# -ge 1 ] && echo -e $RED"[ERROR] ""$@" $RESET; }
warning() { [ $# -ge 1 ] && echo -e $YELLOW"[WARNING] ""$@" $RESET; }
normalp() { [ $# -ge 1 ] && echo -e $RESET"$@"; }
function listAllParts
{
normalp "Parts in config:"
for part in ${allparts[@]};do
normalp $part
done
normalp ""
}
function installParts
{
local PART=all
if [[ $# -ge 1 ]];then
PART=$1
fi
local installparts=""
if [[ "$PART" == "all" ]];then
normalp "Install all part"
installparts=("${allparts[@]}")
else
normalp "Install part:" $PART
installparts=($PART)
fi
local total_start_time=`date +%s`
normalp "Begin install ... Now: `date '+%Y-%m-%d %H:%M:%S'`"
for onepart in ${installparts[@]};do
local controlscript=parts/${onepart}/part.sh
if [ -f ${controlscript} ];then
local start_time=`date +%s`
normalp "Begin install ${onepart}, begin at: `date '+%Y-%m-%d %H:%M:%S'`"
chmod +x ${controlscript}
bash ${controlscript} install
local ret=$?
if [[ $ret -eq 0 ]];then
local end_time=`date +%s`
success "Installation of ${onepart} completed, end at: `date '+%Y-%m-%d %H:%M:%S'`, running time: $((${end_time}-${start_time}))"
elif [[ $ret -ne 100 ]];then
error "Install ${onepart} failed !!!"
fi
else
error "The action control for ${onepart} could not be found, please check file ${controlscript}"
fi
done
local total_end_time=`date +%s`
normalp "End install ... Now: `date '+%Y-%m-%d %H:%M:%S'`, total running time: $((${total_end_time}-${total_start_time}))"
}
function cleanParts
{
local PART=all
if [[ $# -ge 1 ]];then
PART=$1
fi
local cleanparts=""
if [[ "$PART" == "all" ]];then
normalp "Clean all part"
cleanparts=("${allparts[@]}")
else
normalp "Clean part:" $PART
cleanparts=($PART)
fi
local total_start_time=`date +%s`
normalp "Begin clean ..."
for onepart in ${cleanparts[@]};do
local controlscript=parts/${onepart}/part.sh
if [ -f ${controlscript} ];then
chmod +x ${controlscript}
bash ${controlscript} clean
local ret=$?
if [[ $ret -eq 0 ]];then
success "Clean of ${onepart} completed"
elif [[ $ret -ne 100 ]];then
error "Clean ${onepart} failed !!!"
fi
else
error "The action control for ${onepart} could not be found, please check file ${controlscript}"
fi
done
local total_end_time=`date +%s`
normalp "End clean ... total running time: $((${total_end_time}-${total_start_time}))"
}