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 # cp -f /etc/alternc/templates/roundcube/avelsieve-config.php /etc/alternc/templates/roundcube/apache.conf /etc/roundcube/
29 # cp -f /etc/alternc/templates/javascript-common/javascript-common.conf /etc/javascript-common/
30 
31  LOGIN="0000_roundcube"
32  PASSWORD="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)'`"
33  DESKEY="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..24)'`"
34 
35  # Add new variables to the sed script ...
36  SED_SCRIPT="/tmp/alternc-roundcube.sedscript"
37  # cf alternc.install for more explanations on this horror :
38  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`
39  . /etc/alternc/local.sh
40  # Configuration template location
41  TEMPLATE_DIR="/etc/alternc/templates"
42  CONFIG_FILES="etc/roundcube/config.inc.php etc/roundcube/plugins/password/config.inc.php"
43 
44  cat > $SED_SCRIPT <<EOF
45 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
46 s\\%%dbhost%%\\$MYSQL_HOST\\;
47 s\\%%dbname%%\\$MYSQL_DATABASE\\;
48 s\\%%roundcube-login%%\\$LOGIN\\;
49 s\\%%roundcube-password%%\\$PASSWORD\\;
50 s\\%%deskey%%\\$DESKEY\\;
51 EOF
52  for file in $CONFIG_FILES; do
53  TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
54  echo -n " $file"
55  if [ -f "$TEMPLATE" ]; then
56  sed -f "$SED_SCRIPT" < $TEMPLATE > /$file
57  fi
58  done
59 
60  rm -f $SED_SCRIPT
61 
62  echo " Done"
63 
64  . /usr/lib/alternc/functions.sh
65 
66  echo "giving write access to roundcube to the email password ..."
67  # now database host user and password are mysql root account values ;)
68  mysql_query "GRANT UPDATE (password) ON ${database}.address TO '${LOGIN}'@'${MYSQL_CLIENT}' IDENTIFIED BY '${PASSWORD}';"
69  mysql_query "GRANT SELECT ON ${database}.address TO '${LOGIN}'@'${MYSQL_CLIENT}';"
70  mysql_query "GRANT SELECT ON ${database}.domaines TO '${LOGIN}'@'${MYSQL_CLIENT}';"
71  echo " Done"
72 
73  echo "Setting roundcube domaintype"
74  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 " Done"
76 
77  echo "Migrating old webmail domaine type to roundcube one:"
78  # migration of the "webmail" hosts to "roundcube" hosts:
79  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';"
80  mysql_query "UPDATE sub_domaines SET web_action='DELETE' WHERE type='WEBMAIL';"
81  echo " Done"
82 
83  echo "Deconfiguring javascript-common alias"
84  if [ -f /etc/apache2/conf.d/javascript-common.conf ]; then
85  rm -f /etc/apache2/conf.d/javascript-common.conf
86  fi
87  if [ -f /etc/apache2/conf-available/javascript-common.conf ] ; then
88  a2disconf javascript-common.conf
89  service apache2 reload
90  fi
91  # just in case
92  if [ -f /etc/javascript-common/javascript-common.conf ]; then
93  sed -i -e "s/^Alias \/javascript/# Do not uncomment, commented by AlternC to prevent a global alias\n#Alias \/javascript/" /etc/javascript-common/javascript-common.conf
94  fi
95  echo " Done"
96 
97 fi
98