forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-sys-rainloop
More file actions
executable file
·174 lines (138 loc) · 6.67 KB
/
v-add-sys-rainloop
File metadata and controls
executable file
·174 lines (138 loc) · 6.67 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
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
#!/bin/bash
# info: Install Rainloop in HestiaCP
# options: [MODE]
# labels: hestia
#
# The function installs Rainloop
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf
source $HESTIA/install/upgrade/upgrade.conf
MODE=$1
UPDATE="no"
# Version and Download paths
# Version to be moved to upgrade script
RL_FILE="rainloop-community-latest.zip"
# For removal of folder
RL_EXTRACT_MAIN="rainloop"
# Downloading full version
RL_URL="https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip"
# Folder paths
RL_INSTALL_DIR="/var/lib/rainloop"
RL_CONFIG_DIR="/etc/rainloop"
RL_LOG="/var/log/rainloop"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking root permissions
if [ "x$(id -u)" != 'x0' ]; then
echo "ERROR: v-add-sys-rainloop can be run executed only by root user"
exit 10
fi
# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
if [ -z "$HESTIA" ]; then
HESTIA="/usr/local/hestia"
fi
if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
echo "ERROR: Environment variables not present, installation aborted."
exit 2
fi
# Get current version
if [ -f "/var/lib/rainloop/data/VERSION" ]; then
version=$(cat $RL_INSTALL_DIR/data/VERSION);
if [ "$version" == "$rl_v" ]; then
echo "Error: Installed version ($version) is equal as the availble version ($rl_v)"
exit 2;
else
UPDATE="yes"
fi
fi
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ "$UPDATE" == "no" ]; then
rm -f -r $RL_INSTALL_DIR
rm -f -r $RL_CONFIG_DIR
mkdir $RL_INSTALL_DIR
mkdir $RL_CONFIG_DIR
cd "$RL_INSTALL_DIR"
[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
key=$(openssl rand -hex 4);
admin_account="admin_$key"
admin_password=$(generate_password)
r=$(generate_password)
echo "Username: admin_$key" > ~/.rainloop
echo "Password: $admin_password" >> ~/.rainloop
echo "Secret key: admin_$key" >> ~/.rainloop
unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
mv ./data $RL_CONFIG_DIR/
ln -s $RL_CONFIG_DIR/data/ ./data
SALT=$(openssl rand -base64 64)
cp ./data/VERSION ./data/INSTALLED
echo "<?php //$SALT" > ./data/SALT.php
echo "Forbidden" > ./data/index.php
echo "Forbidden" > ./data/index.html
# Create database
mysql -e "DROP DATABASE rainloop"
mysql -e "DROP USER rainloop@localhost"
mysql -e "CREATE DATABASE rainloop"
# Mysql available on system
r=$(generate_password)
mysql -e "GRANT ALL ON rainloop.*
TO rainloop@localhost IDENTIFIED BY '$r'"
mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/configs
php -f $HESTIA_INSTALL_DIR/rainloop/change_password.php "admin_$key" "$admin_password" "$r"
mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/domains
cp -f $HESTIA_INSTALL_DIR/rainloop/default.ini $RL_CONFIG_DIR/data/_data_/_default_/domains
mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins
cp -f -r $HESTIA_INSTALL_DIR/rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR/data/_data_/_default_/plugins
mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
# Download add-x-originating-ip-header from rainloop github
wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/index.php https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/index.php
wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/VERSION https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/VERSION
wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/README https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/README
wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/LICENSE https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/LICENSE
cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-add-x-originating-ip-header.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-add-x-originating-ip-header.ini
cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
sed -i "s/%hostname%/$(hostname)/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
sed -i "s/%port%/$BACKEND_PORT/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
chown -R www-data:www-data ./data
chown -R www-data:www-data $RL_CONFIG_DIR/
rm ${RL_INSTALL_DIR}/${RL_FILE}
# Add robots.txt
echo "User-agent: *" > $RL_INSTALL_DIR/robots.txt
echo "Disallow: /" >> $RL_INSTALL_DIR/robots.txt
# Updating hestia.conf
if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'rainloop'
else
if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
if [ ! -z "$WEBMAIL_SYSTEM" ]; then
$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop,$WEBMAIL_SYSTEM"
else
$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop"
fi
fi
fi
else
[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
version=$(cat $RL_INSTALL_DIR/data/VERSION);
unzip -q -j rainloop-community-latest.zip "data/VERSION" -d $RL_INSTALL_DIR/
version_source=$(cat $RL_INSTALL_DIR/VERSION);
# Check version inside .zip file in case hestia didn't update yet
if [ "$version" != "$version_source" ]; then
unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
rm $RL_INSTALL_DIR/$RL_FILE
fi
rm ${RL_INSTALL_DIR}/VERSION
fi
#----------------------------------------------------------#
# Logging #
#----------------------------------------------------------#
log_history "Rouncube successfuly installed" '' 'admin'
log_event "$OK" "$ARGUMENTS"