3 # Source debconf library.
4 . /usr/share/debconf/confmodule
8 # Validate an IPv4 address.
14 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
19 [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
20 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
27 # Checking mysql connectivity and updating local.sh environment variables accordingly
31 while [ "$STATE" -eq 0 ]; do
32 db_input high alternc/mysql/host || true
34 db_get alternc/mysql/host || true
36 db_input high alternc/mysql/remote_user || true
38 db_get alternc/mysql/remote_user || true
40 db_input high alternc/mysql/remote_password || true
42 db_get alternc/mysql/remote_password || true
44 db_input high alternc/mysql/client || true
46 db_get alternc/mysql/client || true
48 if [ "`mysql -u"$MYSQL_USER" -p"$MYSQL_PASS" -h"$MYSQL_HOST" -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then
49 STATE=`expr $STATE + 1`
51 db_input high alternc/retry_remote_mysql || true
52 if [ $? -eq 30 ]; then
53 db_input high alternc/remote_mysql_error || true
58 db_get alternc/retry_remote_mysql || true
59 if [ "$RET" = "false" ]; then
60 db_input high alternc/remote_mysql_error || true
68 # Return the deepest existing directory in a path
69 function get_first_existing_dir()
72 if [ -z "$dir" ] ; then
75 if ! test -d "$dir" ; then
76 get_first_existing_dir "$(dirname "$dir")"
83 # Compute default values for local.sh
85 MYSQL_DATABASE=alternc
87 MYSQL_PASS="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)' `"
88 MYSQL_MAIL_USER=alternc_user
89 MYSQL_MAIL_PASS="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)' `"
90 MYSQL_CLIENT=localhost
91 FQDN="`(cat /etc/mailname 2>/dev/null || hostname -f)|tr '[:upper:]' '[:lower:]'`"
92 INTERNAL_IP="`env LANG=C ip addr show|grep 'inet ' | grep -v 127.0.0.1| head -1 | sed -e 's/^.*inet \([0-9\.]*\).*$/\1/' 2>/dev/null || hostname -f`"
93 PUBLIC_IP="$INTERNAL_IP"
94 DEFAULT_MX="`cat /etc/mailname 2>/dev/null || hostname -f`"
95 ALTERNC_HTML="/var/www/alternc/"
96 ALTERNC_MAIL="/var/mail/alternc"
97 ALTERNC_LOGS="/var/log/alternc/sites/"
101 SQLBACKUP_TYPE="rotate"
102 SQLBACKUP_OVERWRITE="no"
105 while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 14 ]; do
106 case "$QUEST_STATE" in
108 if [ -r /etc/alternc/my.cnf ]; then
109 MYSQL_USER=$(cat /etc/alternc/my.cnf |grep "^user"|sed -r 's/user="(.*)"/\1/');
110 MYSQL_PASS=$(cat /etc/alternc/my.cnf |grep "^password"|sed -r 's/password="(.*)"/\1/');
111 MYSQL_DATABASE=$(cat /etc/alternc/my.cnf |grep "^database"|sed -r 's/database="(.*)"/\1/');
112 MYSQL_HOST=$(cat /etc/alternc/my.cnf |grep "^host"|sed -r 's/host="(.*)"/\1/');
113 db_set alternc/mysql/host "$MYSQL_HOST"
114 db_set alternc/mysql/db "$MYSQL_DATABASE"
115 db_set alternc/mysql/user "$MYSQL_USER"
116 db_set alternc/mysql/password "$MYSQL_PASS"
119 if [ -r /etc/alternc/local.sh ]; then
120 # source the current config
121 . /etc/alternc/local.sh
122 # and push it into debconf (its values have priority over anything!)
123 db_set alternc/hostingname "$HOSTING"
124 db_set alternc/desktopname "`echo $FQDN | tr '[:upper:]' '[:lower:]'`"
125 db_set alternc/public_ip "$PUBLIC_IP"
126 db_set alternc/internal_ip "$INTERNAL_IP"
127 db_set alternc/ns1 "$NS1_HOSTNAME"
128 db_set alternc/ns2 "$NS2_HOSTNAME"
129 db_set alternc/default_mx "$DEFAULT_MX"
130 db_set alternc/alternc_html "$ALTERNC_HTML"
131 db_set alternc/alternc_mail "$ALTERNC_MAIL"
132 db_set alternc/alternc_logs "$ALTERNC_LOGS"
133 db_set alternc/monitor_ip "$MONITOR_IP"
134 db_set alternc/default_mx2 "$DEFAULT_SECONDARY_MX"
135 db_set alternc/mysql/client "$MYSQL_CLIENT"
136 db_set alternc/sql/backup_type "$SQLBACKUP_TYPE"
137 db_set alternc/sql/backup_overwrite "$SQLBACKUP_OVERWRITE"
138 db_set alternc/mysql/alternc_mail_user "$MYSQL_MAIL_USER"
139 db_set alternc/mysql/alternc_mail_password "$MYSQL_MAIL_PASS"
141 # upgrade <= 3.0 to >= 3.1
142 if [ "x$ALTERNC_LOC" != "x" ]; then
143 ALTERNC_HTML="$ALTERNC_LOC/html"
144 ALTERNC_MAIL="$ALTERNC_LOC/mail"
145 db_set alternc/alternc_html "$ALTERNC_HTML"
146 db_set alternc/alternc_mail "$ALTERNC_MAIL"
149 # We ask for the hosting name and the FQDN
150 db_get alternc/hostingname
151 if [ -z "$RET" ]; then
152 db_set alternc/hostingname "$HOSTING"
153 db_input high alternc/hostingname || true
158 db_get alternc/desktopname
159 if [ -z "$RET" ]; then
160 db_set alternc/desktopname "$FQDN"
161 db_input high alternc/desktopname || true
163 # Ensure that the FQDN is lowercase (Fixes #1405)
164 db_get alternc/desktopname
165 db_set alternc/desktopname "`echo $RET | tr '[:upper:]' '[:lower:]'`"
168 # Ask for the public and private ip
169 db_get alternc/public_ip
170 if [ -z "$RET" ]; then
171 db_set alternc/public_ip "$PUBLIC_IP"
174 while [ $STATE -eq 0 ]; do
175 db_input high alternc/public_ip || true
177 db_get alternc/public_ip
179 if valid_ip $ip ; then
180 if [ $(echo $ip |egrep '(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1)$') ]; then
181 db_input high alternc/use_private_ip || true
183 db_get alternc/use_private_ip
184 if [ "$RET" = "true" ]; then
187 db_reset alternc/use_private_ip || true
188 db_fset alternc/use_private_ip "seen" "false" || true
200 db_get alternc/internal_ip
201 if [ -z "$RET" ]; then
202 db_set alternc/internal_ip "$INTERNAL_IP"
206 while [ $STATE -eq 0 ]; do
207 db_input high alternc/internal_ip || true
209 db_get alternc/internal_ip
211 if valid_ip $ip ; then
217 # Ask for the DNS servers
219 if [ -z "$RET" ]; then
220 db_set alternc/ns1 "$NS1_HOSTNAME"
221 db_input high alternc/ns1 || true
226 if [ -z "$RET" ]; then
227 db_set alternc/ns2 "$NS2_HOSTNAME"
228 db_input high alternc/ns2 || true
232 db_get alternc/default_mx
233 if [ -z "$RET" ]; then
234 db_set alternc/default_mx "$DEFAULT_MX"
235 db_input high alternc/default_mx || true
239 if [ "`mysql --defaults-file=/etc/mysql/debian.cnf -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then
240 db_input critical alternc/use_local_mysql || true
244 db_get alternc/use_local_mysql
245 if [ "$RET" != "true" ]; then
246 db_input critical alternc/use_remote_mysql || true
250 db_get alternc/use_remote_mysql
251 if [ "$RET" == "true" ]; then
252 # User want to use a remote server
257 # We need to set the alternc_location here because we have to test for quotas and acls
259 db_get alternc/alternc_html
260 if [ -z "$RET" ]; then
261 db_set alternc/alternc_html $ALTERNC_HTML
262 db_input high alternc/alternc_html || true
264 db_get alternc/alternc_html
267 # Checking acl and quota activation.
268 basedir=`get_first_existing_dir "$ALTERNC_HTML"`;
269 MOUNT_POINT=$(df -P ${basedir} | tail -n 1 | awk '{print $6}')
270 # Get the first existing dir
271 aclcheckfile="$basedir/test-acl"
272 touch "$aclcheckfile"
273 setfacl -m u:root:rwx "$aclcheckfile" || (
274 test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true
275 db_input high alternc/acluninstalled || true
279 test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true
281 quota -gA -f $MOUNT_POINT || (
282 db_get alternc/quotauninstalled
283 if [ -z "$RET" ]; then
284 db_input critical alternc/quotauninstalled || true
286 db_set alternc/quotauninstalled "false" || true
291 db_get alternc/alternc_mail
292 if [ -z "$RET" ]; then
293 db_set alternc/alternc_mail $ALTERNC_MAIL
294 db_input high alternc/alternc_mail || true
298 db_get alternc/alternc_logs
299 if [ -z "$RET" ];then
300 db_set alternc/alternc_logs $ALTERNC_LOGS
301 db_input high alternc/alternc_logs || true
306 QUEST_STATE=$(($QUEST_STATE + 1))
308 QUEST_STATE=$(($QUEST_STATE - 1))
312 if [ -r /etc/alternc/my.cnf ]; then
313 # make mysql configuration available as shell variables
314 # to convert from .cnf to shell syntax, we:
315 # * match only lines with "equal" in them (/=/)
316 # * remove whitespace around the = and add a left quote operator ' (;s)
317 # * add a right quote operator at the end of line (;s)
318 # * convert mysql variables into our MYSQL_ naming convention (;s)
319 # * print the result (;p)
320 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`
323 if [ -r /etc/alternc/my_mail.cnf ]; then
324 # make mysql configuration available as shell variables
325 # to convert from .cnf to shell syntax, we:
326 # * match only lines with "equal" in them (/=/)
327 # * remove whitespace around the = and add a left quote operator ' (;s)
328 # * add a right quote operator at the end of line (;s)
329 # * convert mysql variables into our MYSQL_ naming convention (;s)
330 # * print the result (;p)
331 eval `sed -n -e "/=/{s/ *= *\"\?/='/;s/\"\?\$/'/;s/host/MYSQL_HOST/;s/user/MYSQL_MAIL_USER/;s/password/MYSQL_MAIL_PASS/;s/database/MYSQL_DATABASE/;p}" /etc/alternc/my_mail.cnf`
334 db_get alternc/monitor_ip
335 if [ -z "$RET" ]; then
336 db_set alternc/monitor_ip "$MONITOR_IP"
339 db_get alternc/default_mx2
340 if [ -z "$RET" ]; then
341 db_set alternc/default_mx2 "$DEFAULT_SECONDARY_MX"
344 db_get alternc/mysql/host
345 if [ -z "$RET" ]; then
346 db_set alternc/mysql/host "$MYSQL_HOST"
349 # Even if we asked the question concerning the database earlier in the process
350 # Those calls are needed to pass the variable of remote sql server to AlternC
351 db_get alternc/mysql/db
352 if [ -z "$RET" ]; then
353 db_set alternc/mysql/db "$MYSQL_DATABASE"
356 db_get alternc/mysql/user
357 if [ -z "$RET" ]; then
358 db_get alternc/mysql/remote_user
359 if [ -z "$RET" ]; then
360 db_set alternc/mysql/user "$MYSQL_USER"
362 db_set alternc/mysql/user "$RET"
366 db_get alternc/mysql/password
367 if [ -z "$RET" ]; then
368 db_get alternc/mysql/remote_password
369 if [ -z "$RET" ]; then
370 db_set alternc/mysql/password "$MYSQL_PASS"
372 db_set alternc/mysql/password "$RET"
376 db_get alternc/mysql/client
377 if [ -z "$RET" ]; then
378 db_set alternc/mysql/client "$MYSQL_CLIENT"
381 db_get alternc/sql/backup_type
382 if [ -z "$RET" ]; then
383 db_set alternc/sql/backup_type "$SQLBACKUP_TYPE"
386 db_get alternc/sql/backup_overwrite
387 if [ -z "$RET" ]; then
388 db_set alternc/sql/backup_overwrite "$SQLBACKUP_OVERWRITE"
391 db_get alternc/mysql/alternc_mail_user
392 if [ -z "$RET" ]; then
393 db_set alternc/mysql/alternc_mail_user "$MYSQL_MAIL_USER"
396 db_get alternc/mysql/alternc_mail_password
397 if [ -z "$RET" ]; then
398 db_set alternc/mysql/alternc_mail_password "$MYSQL_MAIL_PASS"
401 db_input low alternc/default_mx2 || true
402 db_input low alternc/mysql/host || true
403 db_input low alternc/mysql/db || true
404 db_input low alternc/mysql/user || true
405 db_input low alternc/mysql/password || true
406 db_input low alternc/mysql/alternc_mail_password || true
407 db_input low alternc/mysql/alternc_mail_user || true
408 db_input low alternc/mysql/client || true
409 db_input low alternc/sql/backup_type || true
410 db_input low alternc/sql/overwrite || true
411 db_input low alternc/monitor_ip || true
412 db_input low alternc/slaves || true