1+ #! /bin/bash
2+ # info: Install RoundCube for Nginx/Apache2
3+ # options: [MODE]
4+ # labels: hestia
5+ #
6+ # The function installs Round Cube
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+ RC_FILE=" roundcubemail-$rc_v -complete.tar.gz"
21+ RC_EXTRACT=" roundcubemail-$rc_v "
22+ # Downloading full version
23+ RC_URL=" https://github.com/roundcube/roundcubemail/releases/download/$rc_v /roundcubemail-$rc_v -complete.tar.gz"
24+
25+ # Folder paths
26+ RC_INSTALL_DIR=" /var/lib/roundcube"
27+ RC_CONFIG_DIR=" /etc/roundcube"
28+ RC_LOG=" /var/log/roundcube"
29+
30+ # ----------------------------------------------------------#
31+ # Verifications #
32+ # ----------------------------------------------------------#
33+
34+ # Checking root permissions
35+ if [ " x$( id -u) " != ' x0' ]; then
36+ echo " ERROR: v-add-sys-roundcube can be run executed only by root user"
37+ exit 10
38+ fi
39+
40+ # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
41+ if [ -z " $HESTIA " ]; then
42+ HESTIA=" /usr/local/hestia"
43+ fi
44+
45+ if [ -z " $HOMEDIR " ] || [ -z " $HESTIA_INSTALL_DIR " ]; then
46+ echo " ERROR: Environment variables not present, installation aborted."
47+ exit 2
48+ fi
49+
50+ if [ -z " $( echo " $DB_SYSTEM " | grep -w ' mysql' ) " ]; then
51+ echo " ERROR: Mysql not available. Instalation aborted"
52+ exit 2
53+ fi
54+
55+ if [ -d " /usr/share/roundcube" ]; then
56+ echo " ERROR: Install done from atp source unable to continue"
57+ exit 2;
58+ fi
59+
60+ # Get current version
61+ if [ -f " /var/lib/roundcube/index.php" ]; then
62+ version=$( cat $RC_INSTALL_DIR /index.php | grep -o -E ' [0-9].[0-9].[0-9]+' | head -1) ;
63+ if [ " $version " == " $rc_v " ]; then
64+ echo " Error: Installed version ($version ) is equal as the availble version ($rc_v )"
65+ exit 2;
66+ else
67+ UPDATE=" yes"
68+ fi
69+ fi
70+
71+ # Perform verification if read-only mode is enabled
72+ check_hestia_demo_mode
73+
74+ # ----------------------------------------------------------#
75+ # Action #
76+ # ----------------------------------------------------------#
77+
78+ if [ " $UPDATE " == " no" ]; then
79+ rm -f -r $RC_INSTALL_DIR
80+ rm -f -r $RC_CONFIG_DIR
81+
82+ mkdir -p $RC_INSTALL_DIR /
83+ mkdir -p $RC_CONFIG_DIR /
84+
85+ cd " $RC_INSTALL_DIR "
86+ [ ! -f " ${RC_INSTALL_DIR} /${RC_FILE} " ] && wget " $RC_URL " --quiet -O " ${RC_INSTALL_DIR} /${RC_FILE} "
87+
88+ tar xzf $RC_FILE
89+ cp -rf $RC_EXTRACT /* $RC_INSTALL_DIR
90+
91+ # Delete old config folder
92+ cp $RC_INSTALL_DIR /config/defaults.inc.php $RC_CONFIG_DIR /defaults.inc.php
93+ rm -f -r $RC_INSTALL_DIR /config/
94+ ln -s $RC_CONFIG_DIR / ./config
95+ # Replace with Hestia config
96+ cp -f $HESTIA_INSTALL_DIR /roundcube/main.inc.php $RC_CONFIG_DIR /config.inc.php
97+ cp -f $HESTIA_INSTALL_DIR /roundcube/mimetypes.php $RC_CONFIG_DIR /mimetypes.php
98+
99+ cp -f $HESTIA_INSTALL_DIR /roundcube/hestia.php $RC_INSTALL_DIR /plugins/password/drivers/
100+ mkdir -p $RC_CONFIG_DIR /plugins/password
101+ mkdir -p $RC_CONFIG_DIR /plugins/newmail_notifier
102+ mkdir -p $RC_CONFIG_DIR /plugins/zipdownload
103+
104+ # Allow changes to the respective config / Create symlinks to /etc/roundcube/
105+ cp -f $HESTIA_INSTALL_DIR /roundcube/config.inc.php $RC_CONFIG_DIR /plugins/password/config.inc.php
106+ ln -s $RC_CONFIG_DIR /plugins/password/config.inc.php ./plugins/password/config.inc.php
107+ cp -f $HESTIA_INSTALL_DIR /roundcube/plugins/config_newmail_notifier.inc.php $RC_CONFIG_DIR /plugins/newmail_notifier/config.inc.php
108+ ln -s $RC_CONFIG_DIR /plugins/newmail_notifier/config.inc.php ./plugins/newmail_notifier/config.inc.php
109+ cp -f $HESTIA_INSTALL_DIR /roundcube/plugins/config_zipdownload.inc.php $RC_CONFIG_DIR /plugins/zipdownload/config.inc.php
110+ ln -s $RC_CONFIG_DIR /plugins/zipdownload/config.inc.php ./plugins/zipdownload/config.inc.php
111+
112+
113+ chmod 640 $RC_CONFIG_DIR /config.inc.php
114+ chown root:www-data $RC_CONFIG_DIR /config.inc.php
115+
116+ # Log file
117+ if [ ! -d $RC_LOG ]; then
118+ mkdir $RC_LOG
119+ fi
120+ chown www-data:root $RC_LOG
121+ chmod 751 $RC_LOG
122+
123+ if [ ! -z " $( echo " $DB_SYSTEM " | grep -w ' mysql' ) " ]; then
124+ # Remove the following 2 lines when going live
125+ mysql -e " DROP DATABASE roundcube"
126+ mysql -e " DROP USER roundcube@localhost"
127+ mysql -e " CREATE DATABASE roundcube"
128+ # Mysql available on system
129+ r=$( generate_password)
130+ mysql -e " GRANT ALL ON roundcube.*
131+ TO roundcube@localhost IDENTIFIED BY '$r '"
132+ sed -i " s/%password%/$r /g" $RC_CONFIG_DIR /config.inc.php
133+ mysql roundcube < /var/lib/roundcube/SQL/mysql.initial.sql
134+ fi
135+ # To do in future add support for Postgresql only setup
136+
137+ rcDesKey=" $( openssl rand -base64 30 | tr -d " /" | cut -c1-24) "
138+ sed -i " s/%des_key%/$rcDesKey /g" $RC_CONFIG_DIR /config.inc.php
139+ # Change hostname for password change
140+ sed -i " s/localhost/$( hostname) /g" $RC_CONFIG_DIR /plugins/password/config.inc.php
141+
142+ # Clean up
143+ rm -f -r $RC_INSTALL_DIR /installer;
144+ rm -f -r $RC_INSTALL_DIR /$RC_FILE ;
145+ rm -f -r $RC_INSTALL_DIR /$RC_EXTRACT ;
146+
147+ # Add robots.txt
148+ echo " User-agent: *" > /var/lib/roundcube/robots.txt
149+ echo " Disallow: /" >> /var/lib/roundcube/robots.txt
150+
151+ # Updating hestia.conf
152+ if [ -z " $( grep WEBMAIL_SYSTEM $HESTIA /conf/hestia.conf) " ]; then
153+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' ' roundcube'
154+ else
155+ if [ -z " $( echo " $WEBMAIL_SYSTEM " | grep -w ' roundcube' ) " ]; then
156+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' " roundcube"
157+ else
158+ $BIN /v-change-sys-config-value ' WEBMAIL_SYSTEM' " roundcube,$WEBMAIL_SYSTEM "
159+ fi
160+ fi
161+
162+ phpenmod mcrypt > /dev/null 2>&1
163+ else
164+ rm -f -r $RC_INSTALL_DIR
165+ mkdir $RC_INSTALL_DIR
166+ cd " $RC_INSTALL_DIR "
167+ [ ! -f " ${RC_INSTALL_DIR} /${RC_FILE} " ] && wget " $RC_URL " --quiet -O " ${RC_INSTALL_DIR} /${RC_FILE} "
168+
169+ tar xzf $RC_FILE
170+ cp -rf $RC_EXTRACT /* $RC_INSTALL_DIR
171+
172+ cp -f $RC_INSTALL_DIR /config/defaults.inc.php $RC_CONFIG_DIR /defaults.inc.php
173+ rm -f -r $RC_INSTALL_DIR /config/
174+ ln -s $RC_CONFIG_DIR / ./config
175+
176+ ln -s $RC_CONFIG_DIR /plugins/password/config.inc.php ./plugins/password/config.inc.php
177+ ln -s $RC_CONFIG_DIR /plugins/newmail_notifier/config.inc.php ./plugins/newmail_notifier/config.inc.php
178+ ln -s $RC_CONFIG_DIR /plugins/zipdownload/config.inc.php ./plugins/zipdownload/config.inc.php
179+
180+ $RC_INSTALL_DIR /bin/update.sh --version " $version "
181+
182+ rm -f -r $RC_INSTALL_DIR /installer;
183+ rm -f -r $RC_INSTALL_DIR /$RC_FILE ;
184+ rm -f -r $RC_INSTALL_DIR /$RC_EXTRACT ;
185+ fi
186+ # ----------------------------------------------------------#
187+ # Logging #
188+ # ----------------------------------------------------------#
189+
190+
191+
192+ log_history " Rouncube successfuly installed" ' ' ' admin'
193+ log_event " $OK " " $ARGUMENTS "
0 commit comments