3 # ----------------------------------------------------------------------
4 # AlternC - Web Hosting System
5 # Copyright (C) 2000-2012 by the AlternC Development Team.
7 # ----------------------------------------------------------------------
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License (GPL)
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # To read the license please visit http://www.gnu.org/copyleft/gpl.html
21 # ----------------------------------------------------------------------
22 # Purpose of file: Install roundcube conf files.
23 # ----------------------------------------------------------------------
25 if [ "$1" = "templates" ]
27 echo "Installing Roundcube Templates ..."
29 LOGIN="0000_roundcube"
30 PASSWORD="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)'`"
31 DESKEY="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..24)'`"
33 # Add new variables to the sed script ...
34 SED_SCRIPT="/tmp/alternc-roundcube.sedscript"
35 # cf alternc.install for more explanations on this horror :
36 eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_USER/;s/password/MYSQL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my.cnf`
37 . /etc/alternc/local.sh
38 # Configuration template location
39 TEMPLATE_DIR="/etc/alternc/templates"
40 CONFIG_FILES="etc/roundcube/config.inc.php etc/roundcube/plugins/password/config.inc.php"
42 cat > $SED_SCRIPT <<EOF
43 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
44 s\\%%dbhost%%\\$MYSQL_HOST\\;
45 s\\%%dbname%%\\$MYSQL_DATABASE\\;
46 s\\%%roundcube-login%%\\$LOGIN\\;
47 s\\%%roundcube-password%%\\$PASSWORD\\;
48 s\\%%deskey%%\\$DESKEY\\;
50 for file in $CONFIG_FILES; do
51 TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
53 if [ -f "$TEMPLATE" ]; then
54 sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
62 . /usr/lib/alternc/functions.sh
64 echo "giving write access to roundcube to the email password ..."
65 # now database host user and password are mysql root account values ;)
66 mysql_query "GRANT UPDATE (password) ON ${database}.address TO '${LOGIN}'@'${MYSQL_CLIENT}' IDENTIFIED BY '${PASSWORD}';"
67 mysql_query "GRANT SELECT ON ${database}.address TO '${LOGIN}'@'${MYSQL_CLIENT}';"
68 mysql_query "GRANT SELECT ON ${database}.domaines TO '${LOGIN}'@'${MYSQL_CLIENT}';"
71 echo "Setting roundcube domaintype"
72 mysql_query "INSERT IGNORE INTO domaines_type (name ,description ,target ,entry ,compatibility ,enable ,only_dns ,need_dns ,advanced )VALUES ('roundcube','Roundcube Webmail access', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'txt', 'ALL', '0', '0', '0');"
75 echo "Migrating old webmail domaine type to roundcube one:"
76 # migration of the "webmail" hosts to "roundcube" hosts:
77 mysql_query "INSERT IGNORE INTO sub_domaines (compte, domaine, sub, valeur, type, web_action, web_result, enable) SELECT compte, domaine, sub, valeur,'roundcube', 'UPDATE',0, enable FROM sub_domaines WHERE type='WEBMAIL';"
78 mysql_query "UPDATE sub_domaines SET web_action='DELETE' WHERE type='WEBMAIL';"
83 if [ "$1" = "end" ]; then
84 # Roundcube vhosts run as www-data instead of alternc-roundcube now.
85 # Ensure the configuration is owned by the appropriate user.
86 chown www-data:root /etc/roundcube/config.inc.php
87 chown www-data:nogroup /var/lib/roundcube/temp