| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -e |
|---|
| 4 | |
|---|
| 5 | # Source debconf library. |
|---|
| 6 | . /usr/share/debconf/confmodule |
|---|
| 7 | |
|---|
| 8 | CONFIGFILE="/etc/alternc/local.sh" |
|---|
| 9 | |
|---|
| 10 | update_var() { |
|---|
| 11 | local question |
|---|
| 12 | local var |
|---|
| 13 | question="$1" |
|---|
| 14 | var="$2" |
|---|
| 15 | db_get "$question" |
|---|
| 16 | |
|---|
| 17 | grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE |
|---|
| 18 | SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\" |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | # summary of how this script can be called: |
|---|
| 22 | # * <postinst> `configure' <most-recently-configured-version> |
|---|
| 23 | # * <old-postinst> `abort-upgrade' <new version> |
|---|
| 24 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
|---|
| 25 | # <new-version> |
|---|
| 26 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
|---|
| 27 | # <failed-install-package> <version> `removing' |
|---|
| 28 | # <conflicting-package> <version> |
|---|
| 29 | # for details, see http://www.debian.org/doc/debian-policy/ or |
|---|
| 30 | # the debian-policy package |
|---|
| 31 | # |
|---|
| 32 | # quoting from the policy: |
|---|
| 33 | # Any necessary prompting should almost always be confined to the |
|---|
| 34 | # post-installation script, and should be protected with a conditional |
|---|
| 35 | # so that unnecessary prompting doesn't happen if a package's |
|---|
| 36 | # installation fails and the `postinst' is called with `abort-upgrade', |
|---|
| 37 | # `abort-remove' or `abort-deconfigure'. |
|---|
| 38 | |
|---|
| 39 | case "$1" in |
|---|
| 40 | configure) |
|---|
| 41 | |
|---|
| 42 | # ajoute l'user postfix au groupe sasl |
|---|
| 43 | adduser --quiet postfix sasl |
|---|
| 44 | |
|---|
| 45 | # corriger les permissions du chroot |
|---|
| 46 | mkdir -p /var/spool/postfix/var/run/saslauthd || true |
|---|
| 47 | dpkg-statoverride --quiet --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd || true |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | #Create Dovecot user for mail handling FIXME change home with ALTERNC_LOC |
|---|
| 51 | if ! getent group vmail; then |
|---|
| 52 | addgroup --gid 1998 vmail |
|---|
| 53 | fi |
|---|
| 54 | if ! getent passwd vmail; then |
|---|
| 55 | useradd -g vmail -u 1998 vmail -d /var/alternc/mail -m |
|---|
| 56 | fi |
|---|
| 57 | chown -R vmail:vmail /var/alternc/mail |
|---|
| 58 | chmod u+w /var/alternc/mail |
|---|
| 59 | chmod -R g+w /var/alternc/mail |
|---|
| 60 | |
|---|
| 61 | # build local.sh if it does not exist |
|---|
| 62 | if [ ! -f $CONFIGFILE ]; then |
|---|
| 63 | cat > $CONFIGFILE <<EOF |
|---|
| 64 | #!/bin/sh |
|---|
| 65 | # |
|---|
| 66 | # AlternC - Web Hosting System - Configuration |
|---|
| 67 | # This file will be modified on package configuration |
|---|
| 68 | # (e.g. upgrade or dpkg-reconfigure alternc) |
|---|
| 69 | |
|---|
| 70 | # Hosting service name |
|---|
| 71 | HOSTING="" |
|---|
| 72 | |
|---|
| 73 | # Primary hostname for this box (will be used to access the management panel) |
|---|
| 74 | FQDN="" |
|---|
| 75 | |
|---|
| 76 | # Public IP |
|---|
| 77 | PUBLIC_IP="" |
|---|
| 78 | |
|---|
| 79 | # Internal IP |
|---|
| 80 | # (most of the time, should be equal to PUBLIC_IP, unless you are behind |
|---|
| 81 | # firewall doing address translation) |
|---|
| 82 | INTERNAL_IP="" |
|---|
| 83 | |
|---|
| 84 | # Monitoring IP or network (will be allowed to access Apache status) |
|---|
| 85 | MONITOR_IP="" |
|---|
| 86 | |
|---|
| 87 | # Primary DNS hostname |
|---|
| 88 | NS1_HOSTNAME="" |
|---|
| 89 | |
|---|
| 90 | # Secondary DNS hostname |
|---|
| 91 | NS2_HOSTNAME="" |
|---|
| 92 | |
|---|
| 93 | # Mail server hostname |
|---|
| 94 | DEFAULT_MX="" |
|---|
| 95 | |
|---|
| 96 | # Secondary mail server hostname |
|---|
| 97 | DEFAULT_SECONDARY_MX="" |
|---|
| 98 | |
|---|
| 99 | # Note: MySQL username/password configuration now stored in /etc/alternc/my.cnf |
|---|
| 100 | |
|---|
| 101 | # quels clients mysql sont permis (%, localhost, etc) |
|---|
| 102 | MYSQL_CLIENT="" |
|---|
| 103 | |
|---|
| 104 | # Folder holding data (used for quota management) |
|---|
| 105 | ALTERNC_LOC="" |
|---|
| 106 | |
|---|
| 107 | # the type of backup created by the sql backup script |
|---|
| 108 | # valid options are "rotate" (newsyslog-style) or "date" (suffix is the date) |
|---|
| 109 | SQLBACKUP_TYPE="" |
|---|
| 110 | |
|---|
| 111 | # overwrite existing files when backing up |
|---|
| 112 | SQLBACKUP_OVERWRITE="" |
|---|
| 113 | |
|---|
| 114 | # known slave servers, empty for none, localhost is special (no ssh) |
|---|
| 115 | ALTERNC_SLAVES="" |
|---|
| 116 | EOF |
|---|
| 117 | |
|---|
| 118 | chown root:alterncpanel $CONFIGFILE |
|---|
| 119 | chmod 640 $CONFIGFILE |
|---|
| 120 | fi |
|---|
| 121 | |
|---|
| 122 | # Update local.sh |
|---|
| 123 | # 1. use cp to keep permissions |
|---|
| 124 | # 2. add missing variable to local.sh |
|---|
| 125 | # 3. use sed to set variables with current values |
|---|
| 126 | echo "Updating $CONFIGFILE" |
|---|
| 127 | cp -a -f $CONFIGFILE $CONFIGFILE.tmp |
|---|
| 128 | # SED_SCRIPT will be modified by update_var |
|---|
| 129 | SED_SCRIPT="" |
|---|
| 130 | update_var alternc/hostingname HOSTING |
|---|
| 131 | update_var alternc/desktopname FQDN |
|---|
| 132 | update_var alternc/public_ip PUBLIC_IP |
|---|
| 133 | update_var alternc/internal_ip INTERNAL_IP |
|---|
| 134 | update_var alternc/monitor_ip MONITOR_IP |
|---|
| 135 | update_var alternc/ns1 NS1_HOSTNAME |
|---|
| 136 | update_var alternc/ns2 NS2_HOSTNAME |
|---|
| 137 | update_var alternc/default_mx DEFAULT_MX |
|---|
| 138 | update_var alternc/default_mx2 DEFAULT_SECONDARY_MX |
|---|
| 139 | update_var alternc/mysql/client MYSQL_CLIENT |
|---|
| 140 | update_var alternc/sql/backup_type SQLBACKUP_TYPE |
|---|
| 141 | update_var alternc/sql/backup_overwrite SQLBACKUP_OVERWRITE |
|---|
| 142 | update_var alternc/alternc_location ALTERNC_LOC |
|---|
| 143 | update_var alternc/slaves ALTERNC_SLAVES |
|---|
| 144 | sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp |
|---|
| 145 | mv -f $CONFIGFILE.tmp $CONFIGFILE |
|---|
| 146 | |
|---|
| 147 | # Setup grants |
|---|
| 148 | db_get "alternc/mysql/host" |
|---|
| 149 | MYSQL_HOST="$RET" |
|---|
| 150 | if [ "$MYSQL_HOST" != "localhost" -o -e /usr/sbin/mysqld ]; then |
|---|
| 151 | # compatibility shims with my.cnf |
|---|
| 152 | host="$RET" |
|---|
| 153 | db_get "alternc/mysql/db" |
|---|
| 154 | database="$RET" |
|---|
| 155 | db_get "alternc/mysql/user" |
|---|
| 156 | user="$RET" |
|---|
| 157 | db_get "alternc/mysql/password" |
|---|
| 158 | password="$RET" |
|---|
| 159 | db_get "alternc/mysql/alternc_mail_user" |
|---|
| 160 | alternc_mail_user="$RET" |
|---|
| 161 | db_get "alternc/mysql/alternc_mail_password" |
|---|
| 162 | alternc_mail_password="$RET" |
|---|
| 163 | |
|---|
| 164 | # we source (instead of forking) mysql.sh so that it gets the local environment above |
|---|
| 165 | . /usr/share/alternc/install/mysql.sh |
|---|
| 166 | fi |
|---|
| 167 | |
|---|
| 168 | if [ -e $CONFIGFILE ]; then |
|---|
| 169 | # source local.sh variables |
|---|
| 170 | . $CONFIGFILE |
|---|
| 171 | fi |
|---|
| 172 | |
|---|
| 173 | # multi-server configuration: we create an alternc account with |
|---|
| 174 | # authorized keys. since this is the master, we do not give him a |
|---|
| 175 | # valid shell, but we still need the user for proper perms |
|---|
| 176 | if [ ! -z "$ALTERNC_SLAVES" ] && [ "$ALTERNC_SLAVES" != "localhost" ] ; then |
|---|
| 177 | if ! grep -q alternc /etc/passwd ; then |
|---|
| 178 | echo "Creating alternc account" |
|---|
| 179 | adduser --quiet --system --uid 342 --home $ALTERNC_LOC --shell /bin/false --ingroup adm alternc |
|---|
| 180 | fi |
|---|
| 181 | chown alternc /var/alternc |
|---|
| 182 | if [ -r ~root/.ssh/id_dsa.pub ]; then |
|---|
| 183 | key=`cat ~root/.ssh/id_dsa.pub` |
|---|
| 184 | if ! grep -q "$key" $ALTERNC_LOC/.ssh/authorized_keys ; then |
|---|
| 185 | echo "Authorizing root ssh key to access the common alternc account" |
|---|
| 186 | mkdir -p $ALTERNC_LOC/.ssh |
|---|
| 187 | echo "$key" >> $ALTERNC_LOC/.ssh/authorized_keys |
|---|
| 188 | chown -R alternc:adm $ALTERNC_LOC/.ssh |
|---|
| 189 | chmod -R og-rwx $ALTERNC_LOC/.ssh |
|---|
| 190 | fi |
|---|
| 191 | else |
|---|
| 192 | echo "No SSH key in "~root/.ssh/id_dsa.pub |
|---|
| 193 | echo "create one and reconfigure alternc to propagate SSH keys" |
|---|
| 194 | fi |
|---|
| 195 | else |
|---|
| 196 | echo "AlternC slaves not configured ($ALTERNC_SLAVES)" |
|---|
| 197 | fi |
|---|
| 198 | |
|---|
| 199 | # /var/alternc/dns/d/www.example.com |
|---|
| 200 | FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`" |
|---|
| 201 | if [ "$FQDN_LETTER" = "$FQDN" ] |
|---|
| 202 | then |
|---|
| 203 | FQDN_LETTER="_" |
|---|
| 204 | fi |
|---|
| 205 | |
|---|
| 206 | # Erase all apacheconf file |
|---|
| 207 | # They will be regenerated without the bug by upgrade_check.sh below. |
|---|
| 208 | if dpkg --compare-versions "$2" le "0.9.3.9-globenet14"; then |
|---|
| 209 | rm -f /var/alternc/apacheconf/*/* |
|---|
| 210 | fi |
|---|
| 211 | |
|---|
| 212 | echo "checking for upgrades" |
|---|
| 213 | /usr/share/alternc/install/upgrade_check.sh $2 |
|---|
| 214 | |
|---|
| 215 | echo "config phpmyadmin" |
|---|
| 216 | # Mise à jour sur une configuration existante |
|---|
| 217 | # recherche la chaine include_str (avec les / echappées) et supprime les <?php ?> |
|---|
| 218 | # ${include_str//\//\\/}"'\) c'est uniquement BASH, on est en SH/DASH |
|---|
| 219 | include_str='include("/etc/alternc/phpmyadmin.inc.php")' |
|---|
| 220 | pma_config='/etc/phpmyadmin/config.inc.php' |
|---|
| 221 | bash -c "include_str='include(\"/etc/alternc/phpmyadmin.inc.php\")';pma_config='/etc/phpmyadmin/config.inc.php';sed 's/<?php \('\"\${include_str//\//\\/}\"'\) ?>/\1;/g' \$pma_config > \$pma_config'_2' && mv \$pma_config'_2' \$pma_config" |
|---|
| 222 | |
|---|
| 223 | # Sur une configuration vierge, inclure la configuration alternc |
|---|
| 224 | if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then |
|---|
| 225 | echo "$include_str;" >> $pma_config |
|---|
| 226 | fi |
|---|
| 227 | |
|---|
| 228 | #clean old access to the management panel |
|---|
| 229 | # We don't use this anymore : (FIXME : shall we remove /var/alternc/dns while upgrading ?) |
|---|
| 230 | #find /var/alternc/dns/ -type l -lname /var/alternc/bureau -exec rm {} \; |
|---|
| 231 | |
|---|
| 232 | # Bind stuff |
|---|
| 233 | touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 234 | chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 235 | chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 236 | touch /var/run/alternc/refresh_slave |
|---|
| 237 | /usr/lib/alternc/slave_dns |
|---|
| 238 | # Apache will not start without this file |
|---|
| 239 | touch /var/alternc/apache-vhost/vhosts_all.conf |
|---|
| 240 | |
|---|
| 241 | # Update l18n files |
|---|
| 242 | /usr/share/alternc/install/dopo.sh |
|---|
| 243 | |
|---|
| 244 | #squirrelmail fix |
|---|
| 245 | chown -R :alterncpanel /var/lib/squirrelmail/data |
|---|
| 246 | chmod -R g+w /var/lib/squirrelmail |
|---|
| 247 | #sudo stuff allowing alterncpanel to use quota |
|---|
| 248 | if [ -d /etc/sudoers.d ]; then |
|---|
| 249 | cp /etc/alternc/alternc-sudoers /etc/sudoers.d/alternc-sudoers |
|---|
| 250 | chmod 0440 /etc/sudoers.d/alternc-sudoers |
|---|
| 251 | else |
|---|
| 252 | echo "running an older version of sudo" |
|---|
| 253 | #FIXME |
|---|
| 254 | echo "copy content of /usr/share/doc/examples/example.sudoers into /etc/sudoers.d for to run properly" |
|---|
| 255 | fi |
|---|
| 256 | |
|---|
| 257 | # important: postinst gele sans ca |
|---|
| 258 | db_stop |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | echo "**********************************************" |
|---|
| 262 | echo "* *" |
|---|
| 263 | echo "* ALTERNC *" |
|---|
| 264 | echo "* ------------ *" |
|---|
| 265 | echo "* *" |
|---|
| 266 | echo "* *" |
|---|
| 267 | echo "* Please run alternc.install to fully deploy *" |
|---|
| 268 | echo "* *" |
|---|
| 269 | echo "**********************************************" |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | ;; |
|---|
| 274 | |
|---|
| 275 | abort-upgrade|abort-remove|abort-deconfigure) |
|---|
| 276 | |
|---|
| 277 | ;; |
|---|
| 278 | |
|---|
| 279 | *) |
|---|
| 280 | echo "postinst called with unknown argument \`$1'" >&2 |
|---|
| 281 | exit 1 |
|---|
| 282 | ;; |
|---|
| 283 | |
|---|
| 284 | esac |
|---|
| 285 | |
|---|
| 286 | # dh_installdeb will replace this with shell code automatically |
|---|
| 287 | # generated by other debhelper scripts. |
|---|
| 288 | |
|---|
| 289 | #DEBHELPER# |
|---|
| 290 | |
|---|
| 291 | exit 0 |
|---|
| 292 | |
|---|
| 293 | # vim: et sw=4 |
|---|