This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.sh
95 lines (85 loc) · 2.7 KB
/
start.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
#!/bin/bash
function prepare_config {
#override the defaults, check if set - if not, keep default
if [ -z "$WEB_PORT" ]
then
echo "\$WEB_PORT not set - keeping default value ..."
else
WEB_PORT_NEW="$WEB_PORT"
echo "\$WEB_PORT set - overriding default with new value $WEB_PORT"
sed -i "s/http: port = ${WEB_PORT}/http: port = ${WEB_PORT_NEW}/g" /etc/owfs.conf
fi
#######
if [ -z "$OWFS_PORT" ]
then
echo "\$OWFS_PORT not set - keeping default value ..."
else
OWFS_PORT_NEW="$OWFS_PORT"
echo "\$OWFS_PORT set - overriding default with new value $OWFS_PORT"
sed -i "s/server: port = localhost:${OWFS_PORT}/server: port = localhost:${OWFS_PORT_NEW}/g" /etc/owfs.conf
sed -i "s/\! server: server = localhost:${OWFS_PORT}/\! server: server = localhost:${OWFS_PORT_NEW}/g" /etc/owfs.conf
fi
#######
if [ -z "$FTP_PORT" ]
then
echo "\$FTP_PORT not set - keeping default value ..."
else
FTP_PORT_NEW="$FTP_PORT"
echo "\$FTP_PORT set - overriding default with new value $FTP_PORT"
sed -i "s/ftp: port = ${FTP_PORT}/ftp: port = ${FTP_PORT_NEW}/g" /etc/owfs.conf
fi
#######
if [ -z "$OW_DEVICE" ]
then
echo "\$OW_DEVICE not set - keeping default value ..."
else
OW_DEVICE_NEW="$OW_DEVICE"
echo "\$OW_DEVICE set - overriding default with new value $OW_DEVICE"
sed -i "s/${OW_DEVICE}/${OW_DEVICE_NEW}/g" /etc/owfs.conf
fi
#######
if [ -z "$OW_SERVER" ]
then
echo "\$OW_SERVER not set - keeping default value ..."
else
OW_SERVER_NEW="$OW_SERVER"
echo "\$OW_SERVER set - overriding default with new value $OW_SERVER"
sed -i "s/${OW_SERVER}/${OW_SERVER_NEW}/g" /etc/owfs.conf
fi
}
if [ "$CUSTOM_CONFIG_ENABLED" = "1" ]
then
echo "starting services with custom config from $CUSTOM_CONFIG_FILE"
mv /etc/owfs.conf /etc/owfs.conf.old
cp "$CUSTOM_CONFIG_FILE" /etc/owfs.conf
else
prepare_config
echo "starting services with prepared standard config from /etc/owfs.conf"
fi
SERVICES=(owserver owhttpd owftpd)
#SERVICES_LVL=3
if [ -z "$SERVICES_LVL" ]
then
echo "no Service Level set, apply default 3"
SERVICES_LVL=3
else
if (( $SERVICES_LVL >= 1 )) && (( $SERVICES_LVL <= 3 ))
then
echo "valid Service Level set to $SERVICES_LVL"
else
echo "no valid Service Level set, applying default 3"
SERVICES_LVL=3
fi
fi
echo "looping array items: ${#SERVICES[*]}"
for index in ${!SERVICES[*]}
do
if (($index +1 <= $SERVICES_LVL))
then
service "${SERVICES[$index]}" start
fi
done
# Spin until we receive a SIGTERM (e.g. from `docker stop`)
echo "all work done, go sleeping..."
trap 'exit 143' SIGTERM # exit = 128 + 15 (SIGTERM)
tail -f /dev/null & wait ${!}