-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_wsb.sh
92 lines (80 loc) · 1.82 KB
/
run_wsb.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
#!/bin/bash
#
# Boot script for WSB daemon.
#
# @verions 1.0
# @fecha 14/09/2019
# @author Javier Pastor
# @license GPL 3.0
#
FILE_CFG=config.ini
PATH_DATA=/data
PATH_WSB=$PATH_DATA/.wsb
PATH_STORE=$PATH_DATA/store
PATH_CFG=$PATH_WSB/$FILE_CFG
PATH_CFG_DEFAULT=/$FILE_CFG
EXEC_WSB=/usr/local/bin/wsb
EXEC_EXTERNAL=$PATH_DATA/run_wsb.sh
WSB_VERSION=$(${EXEC_WSB} --version | awk '{print $2;}')
WSB_PORT=${HTTP_PORT:-8080}
fun_check_path_data() {
if [[ ! -d $PATH_DATA ]]; then
mkdir -p $PATH_DATA
[[ $? -gt 0 ]] && return 1 || return 0
fi
}
fun_check_path_wsb() {
if [[ ! -d $PATH_WSB ]]; then
mkdir -p $PATH_WSB
[[ $? -gt 0 ]] && return 1 || return 0
fi
}
fun_check_path_store() {
if [[ ! -d $PATH_STORE ]]; then
mkdir -p $PATH_STORE
[[ $? -gt 0 ]] && return 1 || return 0
fi
}
fun_remove_config() {
if [[ -f $PATH_CFG ]]; then
rm -f $PATH_CFG
[[ $? -gt 0 ]] && return 1 || return 0
fi
}
fun_gen_config() {
fun_check_path_wsb
$EXEC_WSB --root $PATH_DATA config -ba
}
fun_fix_config() {
sed -i '/^\[app]/,/^\[/ s/^; root = ./root = .\/store\//' $PATH_CFG
sed -i "/^\[server]/,/^\[/ s/^; port = 8080/port = ${WSB_PORT}/" $PATH_CFG
sed -i '/^\[server]/,/^\[/ s/^; host = localhost/host = 0.0.0.0/' $PATH_CFG
sed -i '/^\[server]/,/^\[/ s/^; browse = true/browse = false/' $PATH_CFG
}
fun_check_chown() {
if [[ ! -d $PATH_DATA ]]; then
chown root:root $PATH_DATA -R
fi
if [[ ! -d $PATH_WSB ]]; then
chown root:root $PATH_WSB -R
fi
if [[ ! -d $PATH_STORE ]]; then
chown root:root $PATH_STORE -R
fi
}
if [[ -f $EXEC_EXTERNAL ]]; then
echo "*** RUN EXTERNAL ***"
sh $EXEC_EXTERNAL
else
echo "Starting webscrapbook $WSB_VERSION..."
fun_check_path_data
fun_check_path_store
if [ -f $PATH_CFG ]; then
fun_check_chown
else
fun_gen_config
fun_fix_config
fun_check_chown
fi
$EXEC_WSB --root $PATH_DATA serve
fi