Alternc  latest
Alternc logiel libre pour l'hébergement
roundcube-install
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # ----------------------------------------------------------------------
4 # AlternC - Web Hosting System
5 # Copyright (C) 2000-2012 by the AlternC Development Team.
6 # https://alternc.org/
7 # ----------------------------------------------------------------------
8 # LICENSE
9 #
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.
14 #
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.
19 #
20 # To read the license please visit http://www.gnu.org/copyleft/gpl.html
21 # ----------------------------------------------------------------------
22 # Purpose of file: Install roundcube conf files.
23 # ----------------------------------------------------------------------
24 
25 if [ "$1" = "templates" ]
26 then
27  echo "Installing Roundcube Templates ..."
28 
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)'`"
32  # "
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"
41 
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\\;
49 EOF
50  for file in $CONFIG_FILES; do
51  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
52  echo -n " $file"
53  if [ -f "$TEMPLATE" ]; then
54  sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
55  fi
56  done
57 
58  rm -f $SED_SCRIPT
59 
60  echo " Done"
61 
62  . /usr/lib/alternc/functions.sh
63 
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}';"
69  echo " Done"
70 
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');"
73  echo " Done"
74 
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';"
79  echo " Done"
80 
81 fi
82 
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
88 fi