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