1+ #! /bin/bash
2+ # info: Install Rainloop in HestiaCP
3+ # options: [MODE]
4+ # labels: hestia
5+ #
6+ # The function installs Rainloop
7+
8+ # ----------------------------------------------------------#
9+ # Variable&Function #
10+ # ----------------------------------------------------------#
11+
12+ # Includes
13+ source $HESTIA /func/main.sh
14+ source $HESTIA /conf/hestia.conf
15+ source $HESTIA /install/upgrade/upgrade.conf
16+
17+ MODE=$2
18+ UPDATE=" no"
19+ # Version and Download paths
20+ # Version to be moved to upgrade script
21+ RL_FILE=" rainloop-community-latest.zip"
22+ # For removal of folder
23+ RL_EXTRACT_MAIN=" rainloop"
24+
25+ # Downloading full version
26+ RL_URL=" https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip"
27+
28+ # Folder paths
29+ RL_INSTALL_DIR=" /var/lib/rainloop"
30+ RL_CONFIG_DIR=" /etc/rainloop"
31+ RL_LOG=" /var/log/rainloop"
32+
33+ # ----------------------------------------------------------#
34+ # Verifications #
35+ # ----------------------------------------------------------#
36+
37+ # Checking root permissions
38+ if [ " x$( id -u) " != ' x0' ]; then
39+ echo " ERROR: v-add-sys-rainloop can be run executed only by root user"
40+ exit 10
41+ fi
42+
43+ # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
44+ if [ -z " $HESTIA " ]; then
45+ HESTIA=" /usr/local/hestia"
46+ fi
47+
48+ if [ -z " $HOMEDIR " ] || [ -z " $HESTIA_INSTALL_DIR " ]; then
49+ echo " ERROR: Environment variables not present, installation aborted."
50+ exit 2
51+ fi
52+
53+ # Get current version
54+ if [ -f " /var/lib/rainloop/data/VERSION" ]; then
55+ version=$( cat $RL_INSTALL_DIR /data/VERSION) ;
56+ if [ " $version " == " $rl_v " ]; then
57+ echo " Error: Installed version ($version ) is equal as the availble version ($rc_v )"
58+ exit 2;
59+ else
60+ UPDATE=" yes"
61+ fi
62+ fi
63+
64+ # Perform verification if read-only mode is enabled
65+ check_hestia_demo_mode
66+
67+ # ----------------------------------------------------------#
68+ # Action #
69+ # ----------------------------------------------------------#
70+
71+ if [ " $UPDATE " == " no" ]; then
72+ rm -f -r $RL_INSTALL_DIR
73+ rm -f -r $RL_CONFIG_DIR
74+
75+ mkdir $RL_INSTALL_DIR
76+ mkdir $RL_CONFIG_DIR
77+
78+ cd " $RL_INSTALL_DIR "
79+ [ ! -f " ${RC_INSTALL_DIR} /${RC_FILE} " ] && wget " $RL_URL " --quiet -O " ${RL_INSTALL_DIR} /${RL_FILE} "
80+
81+ key=$( openssl rand -hex 4) ;
82+
83+ admin_account=" admin_$key "
84+ admin_password=$( generate_password)
85+ r=$( generate_password)
86+
87+ echo " Username: admin_$key " > ~ /.rainloop
88+ echo " Password: $admin_password " >> ~ /.rainloop
89+ echo " Secret key: admin_$key " >> ~ /.rainloop
90+
91+ unzip -q $RL_FILE
92+
93+ mv ./data $RL_CONFIG_DIR /
94+ ln -s $RL_CONFIG_DIR /data/ ./data
95+
96+ SALT=$( openssl rand -base64 64)
97+ cp ./data/VERSION ./data/INSTALLED
98+ echo " <?php //$SALT " > ./data/SALT.php
99+ echo " Forbidden" > ./data/index.php
100+ echo " Forbidden" > ./data/index.html
101+
102+ # Create database
103+ mysql -e " DROP DATABASE rainloop"
104+ mysql -e " DROP USER rainloop@localhost"
105+ mysql -e " CREATE DATABASE rainloop"
106+ # Mysql available on system
107+ r=$( generate_password)
108+ mysql -e " GRANT ALL ON rainloop.*
109+ TO rainloop@localhost IDENTIFIED BY '$r '"
110+
111+ mkdir -p $RL_CONFIG_DIR /data/_data_/_default_/configs
112+ php -f $HESTIA_INSTALL_DIR /rainloop/change_password.php " admin_$key " " $admin_password " " $r "
113+ mkdir -p $RL_CONFIG_DIR /data/_data_/_default_/domains
114+ cp -f $HESTIA_INSTALL_DIR /rainloop/default.ini $RL_CONFIG_DIR /data/_data_/_default_/domains
115+ mkdir -p $RL_CONFIG_DIR /data/_data_/_default_/plugins
116+ cp -f -r $HESTIA_INSTALL_DIR /rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR /data/_data_/_default_/plugins
117+ mkdir -p $RL_CONFIG_DIR /data/_data_/_default_/plugins/add-x-originating-ip-header
118+ # Download add-x-originating-ip-header from rainloop github
119+ 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
120+ 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
121+ 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
122+ 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
123+
124+ 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
125+ cp -f $HESTIA_INSTALL_DIR /rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR /data/_data_/_default_/configs/plugin-hestia-change-password.ini
126+
127+ sed -i " s/%hostname%/$( hostname) /g" $RL_CONFIG_DIR /data/_data_/_default_/configs/plugin-hestia-change-password.ini
128+ sed -i " s/%port%/$BACKEND_PORT /g" $RL_CONFIG_DIR /data/_data_/_default_/configs/plugin-hestia-change-password.ini
129+
130+
131+ chown -R www-data:www-data ./data
132+ chown -R www-data:www-data $RL_CONFIG_DIR /
133+
134+ rm ${RL_INSTALL_DIR} /${RL_FILE}
135+ # Add robots.txt
136+ echo " User-agent: *" > $RL_INSTALL_DIR /robots.txt
137+ echo " Disallow: /" >> $RL_INSTALL_DIR /robots.txt
138+
139+ # Updating hestia.conf
140+ if [ -z " $( grep WEBMAIL_SYSTEM $HESTIA /conf/hestia.conf) " ]; then
141+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' ' rainloop'
142+ else
143+ if [ -z " $( echo " $WEBMAIL_SYSTEM " | grep -w ' rainloop' ) " ]; then
144+ if [ ! -z " $WEBMAIL_SYSTEM " ]; then
145+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' " rainloop,$WEBMAIL_SYSTEM "
146+ else
147+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' " rainloop"
148+ fi
149+ fi
150+ fi
151+
152+ else
153+ [ ! -f " ${RC_INSTALL_DIR} /${RC_FILE} " ] && wget " $RL_URL " --quiet -O " ${RL_INSTALL_DIR} /${RL_FILE} "
154+ unzip -q -o $RL_FILE
155+ rm $RL_INSTALL_DIR /$RL_FILE
156+ fi
157+
158+ # ----------------------------------------------------------#
159+ # Logging #
160+ # ----------------------------------------------------------#
161+
162+
163+
164+ log_history " Rouncube successfuly installed" ' ' ' admin'
165+ log_event " $OK " " $ARGUMENTS "
0 commit comments