Alternc  latest
Alternc logiel libre pour l'hébergement
alternc-slave.postinst
Go to the documentation of this file.
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  if [ ! -z "$RET" ]; then
17  grep -Eq "^ *$var=" $CONFIGFILE || echo "$var=" >> $CONFIGFILE
18  SED_SCRIPT="$SED_SCRIPT;s\\^ *$var=.*\\$var=\"$RET\"\\"
19  fi
20 }
21 
22 # summary of how this script can be called:
23 # * <postinst> `configure' <most-recently-configured-version>
24 # * <old-postinst> `abort-upgrade' <new version>
25 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
26 # <new-version>
27 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
28 # <failed-install-package> <version> `removing'
29 # <conflicting-package> <version>
30 # for details, see http://www.debian.org/doc/debian-policy/ or
31 # the debian-policy package
32 #
33 # quoting from the policy:
34 # Any necessary prompting should almost always be confined to the
35 # post-installation script, and should be protected with a conditional
36 # so that unnecessary prompting doesn't happen if a package's
37 # installation fails and the `postinst' is called with `abort-upgrade',
38 # `abort-remove' or `abort-deconfigure'.
39 
40 case "$1" in
41  configure)
42 
43  # Create AlternC Panel user for web server
44  if ! getent group alterncpanel; then
45  addgroup --system --gid 1999 alterncpanel
46  fi
47  if ! getent passwd alterncpanel; then
48  adduser --system --home "/etc/alternc/.alterncpanel" \
49  --disabled-password --uid 1999 --ingroup alterncpanel alterncpanel
50  fi
51 
52  # ajoute l'user postfix au groupe sasl
53  adduser --quiet postfix sasl
54 
55  # corriger les permissions du chroot
56  mkdir -p /var/spool/postfix/var/run/saslauthd || true
57  dpkg-statoverride --quiet --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd || true
58 
59  # build local.sh if it does not exist
60  if [ ! -f $CONFIGFILE ]; then
61  cat > $CONFIGFILE <<EOF
62 #!/bin/sh
63 #
64 # AlternC - Web Hosting System - Configuration
65 # This file will be modified on package configuration
66 # (e.g. upgrade or dpkg-reconfigure alternc)
67 
68 # Hosting service name
69 HOSTING=""
70 
71 # Primary hostname for this box (will be used to access the management panel)
72 FQDN=""
73 
74 # Public IP
75 PUBLIC_IP=""
76 
77 # Internal IP
78 # (most of the time, should be equal to PUBLIC_IP, unless you are behind
79 # firewall doing address translation)
80 INTERNAL_IP=""
81 
82 # Monitoring IP or network (will be allowed to access Apache status)
83 MONITOR_IP=""
84 
85 # Primary DNS hostname
86 NS1_HOSTNAME=""
87 
88 # Secondary DNS hostname
89 NS2_HOSTNAME=""
90 
91 # Mail server hostname
92 DEFAULT_MX=""
93 
94 # Note: MySQL username/password configuration now stored in /etc/alternc/my.cnf
95 
96 # quels clients mysql sont permis (%, localhost, etc)
97 MYSQL_CLIENT=""
98 
99 # Folder holding data (used for quota management)
100 ALTERNC_LOC=""
101 
102 # the type of backup created by the sql backup script
103 # valid options are "rotate" (newsyslog-style) or "date" (suffix is the date)
104 SQLBACKUP_TYPE=""
105 
106 # overwrite existing files when backing up
107 SQLBACKUP_OVERWRITE=""
108 EOF
109 
110  chown root:www-data $CONFIGFILE
111  chmod 640 $CONFIGFILE
112  fi
113 
114  # Update local.sh
115  # 1. use cp to keep permissions
116  # 2. add missing variable to local.sh
117  # 3. use sed to set variables with current values
118  echo "Updating $CONFIGFILE"
119  cp -a -f $CONFIGFILE $CONFIGFILE.tmp
120  # SED_SCRIPT will be modified by update_var
121  SED_SCRIPT=""
122  update_var alternc-slave/hostingname HOSTING
123  update_var alternc-slave/desktopname FQDN
124  update_var alternc-slave/public_ip PUBLIC_IP
125  update_var alternc-slave/internal_ip INTERNAL_IP
126  update_var alternc-slave/monitor_ip MONITOR_IP
127  update_var alternc-slave/ns1 NS1_HOSTNAME
128  update_var alternc-slave/ns2 NS2_HOSTNAME
129  update_var alternc-slave/default_mx DEFAULT_MX
130  update_var alternc-slave/mysql/client MYSQL_CLIENT
131  update_var alternc-slave/sql/backup_type SQLBACKUP_TYPE
132  update_var alternc-slave/sql/backup_overwrite SQLBACKUP_OVERWRITE
133  update_var alternc-slave/alternc_location ALTERNC_LOC
134  sed -e "$SED_SCRIPT" < $CONFIGFILE > $CONFIGFILE.tmp
135  mv -f $CONFIGFILE.tmp $CONFIGFILE
136 
137  if [ -e $CONFIGFILE ]; then
138  # source local.sh variables
139  . $CONFIGFILE
140  fi
141 
142  if grep -q alternc-mergelog /etc/passwd ; then
143  echo "Reusing the alternc-mergelog account as a generic alternc account"
144  # the uid is ugly. we should request allocation from
145  # base-passwd instead
146  usermod --uid 342 --shell /bin/rbash --login alternc alternc-mergelog
147  # this is a separate step otherwise usermod will look for
148  # files to chown in /var/alternc, which takes a long time
149  usermod --home $ALTERNC_LOC alternc
150  fi
151  if [ -d /var/run/alternc-mergelog/.ssh ]; then
152  echo "Cleaning up old alternc-mergelog home"
153  mv /var/run/alternc-mergelog/.ssh $ALTERNC_LOC/.ssh && rmdir /var/run/alternc-mergelog
154  fi
155  if ! grep -q alternc /etc/passwd ; then
156  echo "Creating alternc account"
157  # this uid is ugly. we should request allocation from
158  # base-password instead
159  adduser --quiet --system --uid 342 --home $ALTERNC_LOC --shell /bin/rbash --ingroup adm alternc
160  fi
161 
162  echo "config phpmyadmin"
163  include_str='include("/etc/alternc/phpmyadmin.inc.php")'
164  pma_config=/etc/phpmyadmin/config.inc.php
165  if ! grep -e "$include_str" $pma_config > /dev/null 2>&1; then
166  echo "<?php $include_str ?>" >> $pma_config
167  fi
168 
169  if ! grep -q '## ALTERNC START' /etc/sudoers; then
170  # XXX: this is not proper locking
171  if [ -e /etc/sudoers.tmp ]; then
172  echo "sudoers file being edited, aborting"
173  exit 1
174  else
175  cp /etc/sudoers /etc/sudoers.tmp
176  cat >> /etc/sudoers.tmp <<EOF
177 ## ALTERNC START
178 ## do not change anything between those lines
179 alternc ALL=NOPASSWD: /usr/sbin/invoke-rc.d apache reload
180 alternc ALL=NOPASSWD: /usr/sbin/invoke-rc.d apache2 reload
181 alternc ALL=NOPASSWD: /usr/sbin/rndc reload *
182 alternc ALL=NOPASSWD: /usr/sbin/rndc reload
183 ## ALTERNC END
184 EOF
185  mv /etc/sudoers.tmp /etc/sudoers
186  fi
187  fi
188 
189  # important: postinst gele sans ca
190  db_stop
191 
192  echo "running alternc.install"
193  alternc.install -s
194  ;;
195 
196  abort-upgrade|abort-remove|abort-deconfigure)
197 
198  ;;
199 
200  *)
201  echo "postinst called with unknown argument \`$1'" >&2
202  exit 1
203  ;;
204 
205 esac
206 
207 # dh_installdeb will replace this with shell code automatically
208 # generated by other debhelper scripts.
209 
210 #DEBHELPER#
211 
212 exit 0
213 
214 # vim: et sw=4