-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
59 lines (45 loc) · 1.8 KB
/
start.sh
File metadata and controls
59 lines (45 loc) · 1.8 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
#!/bin/bash
# start.sh
# 2025.08.05
#set -x
# Check if /etc/nut files exist, and copy them from /opt/apcupsd if they don't
files=( hosts.conf upsset.conf )
for file in "${files[@]}"; do
if [ ! -f /etc/nut/$file ] || [[ $UPDATE_CONFIGS == "true" ]]; then
cp /opt/nut/$file /etc/nut/$file \
&& sed -i 's/\b\(example\|Example\|sample\)\s\?//' /etc/nut/$file \
&& echo "No existing $file found or UPDATE_CONFIGS set to true"
else
echo "Existing $file found, and will be used"
fi
done
htmls=( upsstats-single.html upsstats.html )
for html in "${htmls[@]}"; do
if [ ! -f /etc/nut/$html ] || [[ $UPDATE_HTMLS == "true" ]]; then
cp /opt/nut/$html /etc/nut/$html \
&& sed -i 's/\b\(example\|Example\|sample\)\s\?//' /etc/nut/$html \
&& echo "No existing $html found or UPDATE_HTMLS set to true"
else
echo "Existing $html found, and will be used"
fi
done
echo -e "\n----------------------------------------\n"
# Configure upsset.conf
sed -i "s|^### I_HAVE_SECURED_MY_CGI_DIRECTORY|I_HAVE_SECURED_MY_CGI_DIRECTORY|" /etc/nut/upsset.conf
# populate two arrays with host and UPS names
HOSTS=( $UPSHOSTS )
NAMES=( $UPSNAMES )
# add monitors to hosts.conf for each host and UPS name combo
for ((monitor=0;monitor<${#HOSTS[@]};monitor++)); do
echo "MONITOR ${NAMES[$monitor]}@${HOSTS[$monitor]} \"${NAMES[$monitor]}\"" >> /etc/nut/hosts.conf
echo "MONITOR ${NAMES[$monitor]}@${HOSTS[$monitor]} \"${NAMES[$monitor]}\""
done
# Set default ServerName
echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf
a2enconf servername
# Redirect root to upsstats.cgi
echo "RedirectMatch ^/\$ /cgi-bin/nut/upsstats.cgi" >> /etc/apache2/sites-available/000-default.conf
# Initiate nut-upsd packages
a2enmod cgi
echo -e "\n----------------------------------------\n"
exec apache2ctl -D FOREGROUND