Repository navigation
Expand file tree
/
Copy pathpostinstall.sh
More file actions
99 lines (89 loc) · 3.66 KB
/
Copy pathpostinstall.sh
File metadata and controls
99 lines (89 loc) · 3.66 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
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
#!/bin/bash
# Function to run a command and check its return code
function do_and_check_cmd() {
output=$("$@" 2>&1)
ret="$?"
if [ $ret -ne 0 ] ; then
echo "❌ Error from command : $*"
echo "$output"
exit $ret
else
echo "✔️ Success: $*"
echo "$output"
fi
return 0
}
# Give all the permissions to the nginx user
echo "Setting ownership for all necessary directories to nginx user and group..."
do_and_check_cmd chown -R nginx:nginx /usr/share/bunkerweb /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb /var/run/bunkerweb /var/log/bunkerweb
# Copy old line from environment file to new one
# Check if old environment file exists
if [ -f /var/tmp/variables.env ]; then
echo "Old environment file found!"
echo "Copying old line from environment file to new one..."
while read -r line; do
echo "$line" >> /etc/bunkerweb/variables.env
done < /var/tmp/variables.env
# Remove old environment files
echo "Removing old environment files..."
do_and_check_cmd rm -f /var/tmp/variables.env
do_and_check_cmd chown root:nginx /etc/bunkerweb/variables.env
do_and_check_cmd chmod 740 /etc/bunkerweb/variables.env
else
echo "Old environment file not found. Skipping copy..."
fi
# Copy old line from ui environment file to new one
# Check if old environment file exists
if [ -f /var/tmp/ui.env ]; then
echo "Old ui environment file found!"
echo "Copying old line from ui environment file to new one..."
while read -r line; do
echo "$line" >> /etc/bunkerweb/ui.env
done < /var/tmp/ui.env
# Remove old environment files
echo "Removing old environment files..."
do_and_check_cmd rm -f /var/tmp/ui.env
do_and_check_cmd chown root:nginx /etc/bunkerweb/ui.env
do_and_check_cmd chmod 740 /etc/bunkerweb/ui.env
else
echo "Old ui environment file not found. Skipping copy..."
fi
# Check if old db.sqlite3 file exists
if [ -f /var/tmp/bunkerweb/db.sqlite3 ]; then
echo "Old db.sqlite3 file found!"
do_and_check_cmd cp /var/tmp/bunkerweb/db.sqlite3 /var/lib/bunkerweb/db.sqlite3
do_and_check_cmd rm -f /var/lib/bunkerweb/db.sqlite3
do_and_check_cmd chown root:nginx /var/lib/bunkerweb/db.sqlite3
do_and_check_cmd chmod 760 /var/lib/bunkerweb/db.sqlite3
else
echo "Old database file not found. Skipping copy..."
fi
# Create wizard config
if [ "$UI_WIZARD" != "" ] ; then
echo -ne 'DNS_RESOLVERS=9.9.9.9 8.8.8.8 8.8.4.4\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nMULTISITE=yes\nUI_HOST=http://127.0.0.1:7000\nSERVER_NAME=\n' > /etc/bunkerweb/variables.env
do_and_check_cmd chown nginx:nginx /etc/bunkerweb/variables.env
do_and_check_cmd chmod 660 /etc/bunkerweb/variables.env
touch /etc/bunkerweb/ui.env
do_and_check_cmd chown nginx:nginx /etc/bunkerweb/ui.env
do_and_check_cmd chmod 660 /etc/bunkerweb/ui.env
do_and_check_cmd systemctl enable bunkerweb-ui
do_and_check_cmd systemctl start bunkerweb-ui
fi
# Create /var/www/html if needed
if [ ! -d /var/www/html ] ; then
echo "Creating /var/www/html directory ..."
do_and_check_cmd mkdir -p /var/www/html
do_and_check_cmd chmod 750 /var/www/html
do_and_check_cmd chown root:nginx /var/www/html
else
echo "/var/www/html directory already exists, skipping copy..."
fi
# Stop and disable nginx on boot
echo "Stop and disable nginx on boot..."
do_and_check_cmd systemctl stop nginx
do_and_check_cmd systemctl disable nginx
# Auto start BW service on boot and start it now
echo "Enabling and starting bunkerweb service..."
do_and_check_cmd systemctl enable bunkerweb
do_and_check_cmd systemctl start bunkerweb
echo "Postinstall successful !"