forked from ldcsaa/HP-Socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
310 lines (258 loc) · 6.26 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
PACKAGE_PATH=$(cd "$(dirname "$0")"; pwd)
SH_NAME=$(basename "$0")
SCRIPT_DIR=script
DEM_DIR=demo/Release
CER_DIR=demo/ssl-cert
DEM_FILE="hp-*.exe"
LIB_FILE_PREFIX="lib${HPSOCKET_LIB_NAME}"
DEFAULT_PREFIX="/usr/local"
PREFIX_PATH=
DEST_LIB_DIR=
DEST_BIN_DIR=bin
DEST_CER_DIR=hp-ssl-cert
DEST_INC_DIR=include
INSTALL_DEMO=0
IS_UNINSTALL=0
ACTION_NAME=
source $PACKAGE_PATH/$SCRIPT_DIR/env.sh
print_usage()
{
printf "Usage: %s [...O.P.T.I.O.N.S...]\n" "$SH_NAME"
echo "-----------------+-------------------------------------------------------"
printf " %-14s : %s\n" "-p|--prefix" "install/uninstall path (default: /usr/local)"
printf " %-14s : %s\n" "-l|--libdir" "lib dir (x86/ARM default: 'lib', x64 default: 'lib64')"
printf " %-14s : %s\n" "-d|--with-demo" "install demos or not (default: false)"
printf " %-14s : %s\n" "-u|--uninstall" "execute uninstall operation from install path"
printf " %-14s : %s\n" "-v|--version" "print hp-socket version"
printf " %-14s : %s\n" "-h|--help" "print this usage message"
echo "-----------------+-------------------------------------------------------"
}
print_config()
{
printf "Action: %s\n" "$ACTION_NAME"
echo "---------------+-------------------"
printf "%14s : v%d.%d.%d [BN:%02d]\n" "HP-Socket" $VER_MAJOR $VER_MINOR $VER_REVISE $VER_BUILD
printf "%14s : %s\n" "$ACTION_NAME path" "$PREFIX_PATH"
printf "%14s : %s\n" "lib path" "$PREFIX_PATH/$DEST_LIB_DIR"
printf "%14s : %s\n" "arch platform" "$PLATFORM"
if [ $IS_UNINSTALL -eq 0 ]; then
printf "%14s : %s\n" "install demos" $(int_to_bool "$INSTALL_DEMO")
fi
echo "---------------+-------------------"
read_confirm
}
parse_args()
{
ARGS=$(getopt -o hvup:l:d: -l help,version,uninstall,prefix:,libdir:,with-demo: -n "$SH_NAME" -- "$@")
RS=$?
if [ $RS -ne 0 ]; then
print_usage
exit 2
fi
eval set -- "${ARGS}"
while true; do
case "$1" in
-h|--help)
print_usage
exit 0
;;
-v|--version)
print_version
exit 0
;;
-u|--uninstall)
IS_UNINSTALL=1
shift
;;
-p|--prefix)
PREFIX_PATH="$2"
shift 2
;;
-l|--libdir)
DEST_LIB_DIR="$2"
shift 2
;;
-d|--with-demo)
INSTALL_DEMO=$(bool_to_int $2)
if [ -z $INSTALL_DEMO ]; then
printf "Invalid arg value: %s %s\n" "$1" "$2"
print_usage
exit 2
fi
shift 2
;;
--)
shift
break
;;
*)
printf "Parse args fail\n"
print_usage
exit 2
;;
esac
done
if [[ ${PREFIX_PATH:0-1:1} == '/' ]]; then
PREFIX_PATH=${PREFIX_PATH%?}
fi
if [ -z "$PREFIX_PATH" ]; then
PREFIX_PATH=$DEFAULT_PREFIX
fi
if [ -z "$DEST_LIB_DIR" ]; then
if [ $PLATFORM == "x64" ]; then
DEST_LIB_DIR="lib64"
else
DEST_LIB_DIR="lib"
fi
fi
if [ $IS_UNINSTALL -eq 0 ]; then
ACTION_NAME="install"
else
ACTION_NAME="uninstall"
fi
}
_INSTALL_FILE_=
set_install_file()
{
_INSTALL_FILE_="$1"
if [ $IS_UNINSTALL -eq 0 ]; then
ACT="create"
else
ACT="remove"
fi
printf " > %s %s\n" "$ACT" "$_INSTALL_FILE_"
}
cp_lib_a()
{
for FILE in $1/${LIB_FILE_PREFIX}*.a; do
if [ -f "$FILE" ]; then
set_install_file $PREFIX_PATH/$DEST_LIB_DIR/$(basename $FILE)
cp -f $FILE $_INSTALL_FILE_
chmod -f +x $_INSTALL_FILE_
fi
done
}
cp_lib_so()
{
local DEST_LIB_PATH=$PREFIX_PATH/$DEST_LIB_DIR
for FILE in $1/${LIB_FILE_PREFIX}*.so; do
if [ -f "$FILE" ]; then
FILE_NAME=$(basename $FILE)
set_install_file $DEST_LIB_PATH/$FILE_NAME.$VER_MAJOR.$VER_MINOR.$VER_REVISE
cp -f $FILE $_INSTALL_FILE_
chmod -f +x $_INSTALL_FILE_
set_install_file $DEST_LIB_PATH/$FILE_NAME.$VER_MAJOR
ln -snf $FILE_NAME.$VER_MAJOR.$VER_MINOR.$VER_REVISE $_INSTALL_FILE_
set_install_file $DEST_LIB_PATH/$FILE_NAME
ln -snf $FILE_NAME.$VER_MAJOR $_INSTALL_FILE_
fi
done
}
cp_inc()
{
local SRC=$1
local DEST=$2
for FILE in $SRC/*; do
FILE_NAME=$(basename $FILE)
if [ -d "$FILE" ]; then
mkdir -p $DEST/$FILE_NAME
cp_inc $SRC/$FILE_NAME $DEST/$FILE_NAME
elif [ -f "$FILE" ]; then
set_install_file $DEST/$FILE_NAME
cp -f $FILE $_INSTALL_FILE_
fi
done
}
cp_bin_exe()
{
for FILE in $DEM_DIR/$PLATFORM/$DEM_FILE; do
if [ -f "$FILE" ]; then
set_install_file $PREFIX_PATH/$DEST_BIN_DIR/$(basename $FILE)
cp -f $FILE $_INSTALL_FILE_
chmod -f +x $_INSTALL_FILE_
fi
done
}
cp_bin_cert()
{
for FILE in $CER_DIR/*; do
if [ -f "$FILE" ]; then
set_install_file $PREFIX_PATH/$DEST_BIN_DIR/$DEST_CER_DIR/$(basename $FILE)
cp -f $FILE $_INSTALL_FILE_
fi
done
}
rm_empty_dir()
{
if [[ -d "$1" && -z $(ls -A "$1") ]]; then
set_install_file "$1"
rm -rf $_INSTALL_FILE_
fi
}
do_install()
{
mkdir -p $PREFIX_PATH/$DEST_LIB_DIR
# copy *.a
cp_lib_a $HPSOCKET_LIB_TARGET_DIR
cp_lib_a $HPSOCKET4C_LIB_TARGET_DIR
# copy *.so
cp_lib_so $HPSOCKET_LIB_TARGET_DIR
cp_lib_so $HPSOCKET4C_LIB_TARGET_DIR
mkdir -p $PREFIX_PATH/$DEST_INC_DIR
# copy include dir
cp_inc $INC_DIR $PREFIX_PATH/$DEST_INC_DIR
if [[ $INSTALL_DEMO -eq 1 && -d $DEM_DIR/$PLATFORM && "$(ls -A $DEM_DIR/$PLATFORM)" != "" ]]; then
# copy demo .exe files
mkdir -p $PREFIX_PATH/$DEST_BIN_DIR
cp_bin_exe
# copy demo ssl cert files
mkdir -p $PREFIX_PATH/$DEST_BIN_DIR/$DEST_CER_DIR
cp_bin_cert
fi
}
do_uninstall()
{
local FILE_PATH=$PREFIX_PATH/$DEST_LIB_DIR
if [ -d "$FILE_PATH" ]; then
# rm *.a
set_install_file "$FILE_PATH/${LIB_FILE_PREFIX}*.a"
rm -rf $_INSTALL_FILE_
# rm *.so
set_install_file "$FILE_PATH/${LIB_FILE_PREFIX}*.so"
rm -rf $_INSTALL_FILE_
set_install_file "$FILE_PATH/${LIB_FILE_PREFIX}*.so.*"
rm -rf $_INSTALL_FILE_
rm_empty_dir $FILE_PATH
fi
FILE_PATH=$PREFIX_PATH/$DEST_INC_DIR
if [ -d "$FILE_PATH" ]; then
# rm include
set_install_file "$FILE_PATH/$HPSOCKET_LIB_NAME"
rm -rf $_INSTALL_FILE_
rm_empty_dir $FILE_PATH
fi
FILE_PATH=$PREFIX_PATH/$DEST_BIN_DIR
if [ -d "$FILE_PATH" ]; then
# rm demo cert
set_install_file "$FILE_PATH/$DEST_CER_DIR"
rm -rf $_INSTALL_FILE_
# rm demo
set_install_file "$FILE_PATH/$DEM_FILE"
rm -rf $_INSTALL_FILE_
set_install_file "$FILE_PATH/$DEM_FILE.*"
rm -rf $_INSTALL_FILE_
rm_empty_dir $PREFIX_PATH/$DEST_BIN_DIR
fi
rm_empty_dir $PREFIX_PATH
}
parse_args "$@"
print_config
if [ $IS_UNINSTALL -eq 0 ]; then
do_install
else
do_uninstall
fi
ldconfig > /dev/null 2>&1
echo "Done!"
exit 0