-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·202 lines (174 loc) · 3.05 KB
/
install.sh
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
# ==============================================================================
# Do installtion
# ==============================================================================
# Create by Arondight (shell_way@foxmail.com)
# ==============================================================================
WORKDIR=$(dirname $(readlink -f $0))
function showHelp ()
{
cat <<'END_OF_HELP' >&2
Usage:
./install.sh [Option]...
Options:
-h, --help Show this help
-c, --check Check if everything is ready
-i, --install Install these profiles
-a, --init Init these profiles after installtion
Example:
./install.sh -a
END_OF_HELP
return $?
}
function doCheck ()
{
local path=''
local ret=0
local UTILS=(git ln install mkdir rm mv tail grep awk uniq md5sum readlink date)
echo 'Checking your system first ...'
for util in ${UTILS[@]}
do
echo -ne "Checking ${util} ...\t"
if ! type $util >/dev/null 2>&1
then
echo 'failed'
return 1
else
echo 'ok'
fi
done
for path in ${WORKDIR}/*
do
if [[ -d $path ]]
then
path=$(readlink -f $path)
if [[ -x "${path}/check.sh" ]]
then
if ! command "${path}/check.sh"
then
ret=1
fi
fi
unset path
fi
done
echo 'Checking your system done...'
return $ret
}
function doInstall ()
{
local path=''
echo 'Install profiles begin...'
for path in ${WORKDIR}/*
do
if [[ -d $path ]]
then
path=$(readlink -f $path)
if [[ -x "$path/install.sh" ]]
then
if ! command "${path}/install.sh"
then
return 1
fi
fi
unset path
fi
done
echo 'Install profiles done...'
return 0
}
function doInit ()
{
local path=''
echo 'Init profiles begin...'
for path in ${WORKDIR}/*
do
if [[ -d $path ]]
then
path=$(readlink -f $path)
if [[ -x "$path/init.sh" ]]
then
if ! command "${path}/init.sh"
then
return 1
fi
fi
unset path
fi
done
echo 'Init profiles done...'
return 0
}
# MAIN:
{
optCheck=0
optInstall=0
optInit=0
optHelp=0
if [[ 0 -eq $# ]]
then
set -- '--help'
fi
while true
do
case $1 in
-c|--check)
shift
optCheck=1
;;
-i|--install)
shift
optInstall=1
set -- '--check' $@
continue
;;
-a|--init)
shift
optInit=1
set -- '--install' $@
continue
;;
-h|--help)
shift
optHelp=1
;;
*)
break
;;
esac
done
# show help {
if [[ 1 -eq $optHelp ]]
then
showHelp
exit 1
fi
# }
# do check {
if [[ 1 -eq $optCheck ]]
then
if ! doCheck
then
exit $?
fi
fi
# }
# do install {
if [[ 1 -eq $optInstall ]]
then
if ! doInstall
then
exit $?
fi
fi
# }
# do init {
if [[ 1 -eq $optInit ]]
then
if ! doInit
then
exit $?
fi
fi
exit 0
}