From 67d0f562c051f1e2caa262b541e99bdbf8e0749f Mon Sep 17 00:00:00 2001 From: Steven Mondji-Lerider Date: Tue, 29 Jan 2013 13:54:27 +0000 Subject: [PATCH] Updating debconf configuration script : - now we can it the back button to go back a question. - The questions are a little more clear ( still needs some work ) - adding a function valid_ip() to check IP addresses before using them. --- debian/alternc.config | 407 ++++++++++++++++++++++----------------- debian/alternc.templates | 16 ++ 2 files changed, 251 insertions(+), 172 deletions(-) diff --git a/debian/alternc.config b/debian/alternc.config index df929e4b..e811bf46 100644 --- a/debian/alternc.config +++ b/debian/alternc.config @@ -4,20 +4,63 @@ set -e # Source debconf library. . /usr/share/debconf/confmodule -db_title AlternC -db_input critical alternc/welcomeconfirm || true +db_capb backup -db_go -# Check the answer. -db_get alternc/welcomeconfirm || true -if [ "$RET" = "false" ]; then - # reset the welcomeconfirm flag if user refuses so it gets asked again next time - db_reset alternc/welcomeconfirm || true - db_fset alternc/welcomeconfirm "seen" "false" || true - exit 3 -fi +#Return if everything is good, exit error number otherwise +function valid_ip() +{ + local ip=$1 + local stat=1 + + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ + && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + stat=$? + fi + return $stat +} + + +#checking mysql connectivity and updating local.sh variables accordingly +check_mysql(){ + + STATE=0 + while [ "$STATE" -eq 0 ]; do + db_input high alternc/mysql/host || true + db_go + db_get alternc/mysql/host || true + MYSQL_HOST="$RET" + db_input high alternc/mysql/remote_user || true + db_go + db_get alternc/mysql/remote_user || true + MYSQL_USER="$RET" + db_input high alternc/mysql/remote_password || true + db_go + db_get alternc/mysql/remote_password || true + MYSQL_PASSWORD="$RET" + db_input high alternc/mysql/client || true + db_go + db_get alternc/mysql/client || true + MYSQL_CLIENT="$RET" + if [ "`mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_HOST" -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then + STATE=`expr $STATE + 1` + else + db_input high alternc/remote_mysql_error || true + db_go + db_get alternc/remote_mysql_error || true + if [ "$RET" = "false" ]; then + exit 4 + fi + fi + done + +} # default values for local.sh MYSQL_HOST=127.0.0.1 @@ -37,66 +80,160 @@ NS2_HOSTNAME="$FQDN" HOSTING="AlternC" SQLBACKUP_TYPE="rotate" SQLBACKUP_OVERWRITE="no" +QUEST_STATE=1 -if [ -r /etc/alternc/local.sh ]; then - # source the current config - . /etc/alternc/local.sh -fi +while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 14 ]; do + case "$QUEST_STATE" in + 1) + db_title AlternC + db_input critical alternc/welcomeconfirm || true + #db_go + ;; + 2) + # Check the answer. + db_get alternc/welcomeconfirm || true -#We ask for the hosting name and the FQDN -db_set alternc/hostingname "$HOSTING" -db_set alternc/desktopname "$FQDN" -db_input high alternc/hostingname || true + if [ "$RET" = "false" ]; then + # reset the welcomeconfirm flag if user refuses so it gets asked again next time + db_reset alternc/welcomeconfirm || true + db_fset alternc/welcomeconfirm "seen" "false" || true + exit 3 + fi + ;; + 3) + if [ -r /etc/alternc/local.sh ]; then + # source the current config + . /etc/alternc/local.sh + fi -# Get the FQDN -db_input high alternc/desktopname || true -# Be sure that the FQDN is lowercase (Bug #1405) -db_get alternc/desktopname -db_set alternc/desktopname "`echo $RET | tr '[:upper:]' '[:lower:]'`" -# End bug #1405 - -db_go || true -#we ask for the public and private ip -db_set alternc/public_ip "$PUBLIC_IP" -STATE=0 -while [ $STATE -eq 0 ]; do - db_input high alternc/public_ip || true - db_go - db_get alternc/public_ip - ip="$RET" - if [ $(echo $ip |egrep '(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1)$') ]; then - db_input high alternc/use_private_ip || true - db_go - db_get alternc/use_private_ip - if [ "$RET" = "true" ]; then + #We ask for the hosting name and the FQDN + db_set alternc/hostingname "$HOSTING" + db_set alternc/desktopname "$FQDN" + db_input high alternc/hostingname || true + ;; + 4) + # Get the FQDN + db_input high alternc/desktopname || true + # Be sure that the FQDN is lowercase (Bug #1405) + db_get alternc/desktopname + db_set alternc/desktopname "`echo $RET | tr '[:upper:]' '[:lower:]'`" + # End bug #1405 + ;; + 5) + #we ask for the public and private ip + db_set alternc/public_ip "$PUBLIC_IP" + STATE=0 + while [ $STATE -eq 0 ]; do + db_input high alternc/public_ip || true + db_go + db_get alternc/public_ip + ip="$RET" + if valid_ip $ip ; then + if [ $(echo $ip |egrep '(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1)$') ]; then + db_input high alternc/use_private_ip || true + db_go + db_get alternc/use_private_ip + if [ "$RET" = "true" ]; then + STATE=1 + fi + else + STATE=1 + fi + else STATE=1 fi - else - STATE=1 + done + ;; + 6) + #private IP + + db_set alternc/internal_ip "$INTERNAL_IP" + + STATE=0 + while [ $STATE -eq 0 ]; do + db_input high alternc/internal_ip || true + db_go + db_get alternc/internal_ip + ip="$RET" + if valid_ip $ip ; then + STATE=1 + fi + done + ;; + 7) + #We ask for the DNS server for the ip + # + db_set alternc/ns1 "$NS1_HOSTNAME" + + db_input high alternc/ns1 || true + ;; + 8) + db_set alternc/ns1 "$NS2_HOSTNAME" + db_input high alternc/ns2 || true + ;; + 9) + db_set alternc/default_mx "$DEFAULT_MX" + db_input high alternc/default_mx || true + ;; + 10) + if [ "`mysql --defaults-file=/etc/mysql/debian.cnf -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then + db_input critical alternc/use_local_mysql || true + else + db_input critical alternc/use_remote_mysql || true + fi + ;; + 11) + db_get alternc/use_local_mysql || true + if [ "$RET" = "false" ]; then + #user want to use a remote server + check_mysql + fi + ;; + 12) + db_input low alternc/alternc_location || true + ;; + 13) + # We need to check the alternc_location here because we have to test for quotas and acls + db_get alternc/alternc_location + if [ -z "$RET" ] + then + db_set alternc/alternc_location "$ALTERNC_LOC" + fi + + db_get alternc/alternc_location + LOCATION="$RET" + #checking acl and quota activation, does't work with NFS yet. should now work with lxc + MOUNT_POINT=$(df -P ${LOCATION%/*} | tail -n 1 | awk '{print $6}') + + # Get the mount options for the path: (warning, / may have multiple declarations, take the last one only : + MOUNT_OPTS=$(awk '$2=="'$MOUNT_POINT'" { print $4 }' /proc/mounts | tail -1) + + # Check to see if acl is one of the mount points: + ACL="$(echo "$MOUNT_OPTS" | tr "," "\\n" | egrep '^acl|attr2|user_xattr$')" || true + if [ -z "$ACL" ]; then + db_input critical alternc/acluninstalled || true + db_title AlternC + db_reset alternc/acluninstalled || true + db_fset alternc/acluninstalled "seen" "false" || true + exit 2 + fi + quota_activation=$(quotaon -pa 2>/dev/null |grep '^group.*on$' | /usr/bin/awk '$4 ~ /^\'$MOUNT_POINT'$/ {print $4}') + + if [ -z "$quota_activation" -o "$quota_activation" != "$MOUNT_POINT" ]; then + db_input critical alternc/quotauninstalled || true + db_go + db_reset alternc/quotauninstalled || true + db_fset alternc/quotauninstalled "seen" "false" || true + fi + ;; + esac + if db_go; then + QUEST_STATE=$(($QUEST_STATE + 1)) + else + QUEST_STATE=$(($QUEST_STATE - 1)) fi done -#private IP -db_set alternc/internal_ip "$INTERNAL_IP" -db_input high alternc/internal_ip || true -db_go - -#We ask for the DNS server for the ip -# -db_set alternc/ns1 "$NS1_HOSTNAME" - -db_input high alternc/ns1 || true -db_go - -db_set alternc/ns1 "$NS2_HOSTNAME" -db_input high alternc/ns2 || true -db_go - -#default mail server -db_set alternc/default_mx "$DEFAULT_MX" -db_input high alternc/default_mx || true -db_go - if [ -r /etc/alternc/my.cnf ]; then # make mysql configuration available as shell variables # to convert from .cnf to shell syntax, we: @@ -119,97 +256,44 @@ if [ -r /etc/alternc/my_mail.cnf ]; then 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` fi -#checking mysql connectivity and updating local.sh variables accordingly -check_mysql(){ - STATE=0 - while [ "$STATE" -eq 0 ]; do - db_input high alternc/mysql/host || true - db_go - db_get alternc/mysql/host || true - MYSQL_HOST="$RET" - db_input high alternc/mysql/user || true - db_go - db_get alternc/mysql/user || true - MYSQL_USER="$RET" - db_input high alternc/mysql/password || true - db_go - db_get alternc/mysql/password || true - MYSQL_PASSWORD="$RET" - db_input high alternc/mysql/client || true - db_go - db_get alternc/mysql/client || true - MYSQL_CLIENT="$RET" - if [ "`mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_HOST" -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then - STATE=`expr $STATE + 1` - else - db_input high alternc/remote_mysql_error || true - db_go - db_get alternc/remote_mysql_error || true - if [ "$RET" = "false" ]; then - exit 4 - fi - fi - done - -} - -if [ "`mysql --defaults-file=/etc/mysql/debian.cnf -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then - db_input critical alternc/use_local_mysql || true - db_go - db_get alternc/use_local_mysql || true - if [ "$RET" = "false" ]; then - #user want to use a remote server - check_mysql - fi -else -db_input critical alternc/use_remote_mysql || true -db_go -db_get alternc/use_remote_mysql || true - if [ "$RET" = "true" ]; then - #user want to use a remote server - check_mysql - fi -fi +#if [ "`mysql --defaults-file=/etc/mysql/debian.cnf -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then +# db_input critical alternc/use_local_mysql || true +# db_go +# db_get alternc/use_local_mysql || true +# if [ "$RET" = "false" ]; then +# #user want to use a remote server +# check_mysql +# fi +#else +#db_input critical alternc/use_remote_mysql || true +#db_go +#db_get alternc/use_remote_mysql || true +# if [ "$RET" = "true" ]; then +# #user want to use a remote server +# check_mysql +# fi +#fi -# We need to check the alternc_location here because we have to test for quotas and acls -db_input low alternc/alternc_location || true -db_go -db_get alternc/alternc_location -if [ -z "$RET" ] - then -db_set alternc/alternc_location "$ALTERNC_LOC" -fi -db_get alternc/alternc_location -LOCATION="$RET" -#checking acl and quota activation, does't work with NFS yet. should now work with lxc -MOUNT_POINT=$(df -P ${LOCATION%/*} | tail -n 1 | awk '{print $6}') - -# Get the mount options for the path: (warning, / may have multiple declarations, take the last one only : -MOUNT_OPTS=$(awk '$2=="'$MOUNT_POINT'" { print $4 }' /proc/mounts | tail -1) - -# Check to see if acl is one of the mount points: -ACL="$(echo "$MOUNT_OPTS" | tr "," "\\n" | egrep '^acl|attr2|user_xattr$')" || true - -if [ -z "$ACL" ]; then - db_input critical alternc/acluninstalled || true - db_go - db_title AlternC - db_reset alternc/acluninstalled || true - db_fset alternc/acluninstalled "seen" "false" || true - exit 2 -fi -quota_activation=$(quotaon -pa 2>/dev/null |grep '^group.*on$' | /usr/bin/awk '$4 ~ /^\'$MOUNT_POINT'$/ {print $4}') - -if [ -z "$quota_activation" -o "$quota_activation" != "$MOUNT_POINT" ]; then - db_input critical alternc/quotauninstalled || true - db_go - db_reset alternc/quotauninstalled || true - db_fset alternc/quotauninstalled "seen" "false" || true -fi +#if [ -z "$ACL" ]; then +# db_input critical alternc/acluninstalled || true +# db_go +# db_title AlternC +# db_reset alternc/acluninstalled || true +# db_fset alternc/acluninstalled "seen" "false" || true +# exit 2 +#fi +#quota_activation=$(quotaon -pa 2>/dev/null |grep '^group.*on$' | /usr/bin/awk '$4 ~ /^\'$MOUNT_POINT'$/ {print $4}') +# +#if [ -z "$quota_activation" -o "$quota_activation" != "$MOUNT_POINT" ]; then +# db_input critical alternc/quotauninstalled || true +# db_go +# db_reset alternc/quotauninstalled || true +# db_fset alternc/quotauninstalled "seen" "false" || true +#fi db_get alternc/hostingname if [ -z "$RET" ] @@ -223,17 +307,6 @@ if [ -z "$RET" ] db_set alternc/desktopname "$FQDN" fi -db_get alternc/public_ip -if [ -z "$RET" ] - then -db_set alternc/public_ip "$PUBLIC_IP" -fi - -db_get alternc/internal_ip -if [ -z "$RET" ] - then -db_set alternc/internal_ip "$INTERNAL_IP" -fi db_get alternc/monitor_ip if [ -z "$RET" ] @@ -241,24 +314,12 @@ if [ -z "$RET" ] db_set alternc/monitor_ip "$MONITOR_IP" fi -db_get alternc/ns1 -if [ -z "$RET" ] - then -db_set alternc/ns1 "$NS1_HOSTNAME" -fi - db_get alternc/ns2 if [ -z "$RET" ] then db_set alternc/ns2 "$NS2_HOSTNAME" fi -db_get alternc/default_mx -if [ -z "$RET" ] - then -db_set alternc/default_mx "$DEFAULT_MX" -fi - db_get alternc/default_mx2 if [ -z "$RET" ] then @@ -271,6 +332,8 @@ if [ -z "$RET" ] db_set alternc/mysql/host "$MYSQL_HOST" fi +#Even if we asked the question concerning the database earlier in the process +#those calls are needed to pass the variable of remote sql server to AlternC db_get alternc/mysql/db if [ -z "$RET" ] then diff --git a/debian/alternc.templates b/debian/alternc.templates index 74b83bdb..237d724f 100644 --- a/debian/alternc.templates +++ b/debian/alternc.templates @@ -95,6 +95,15 @@ _Description: AlternC's mysql account: AlternC will create a mysql administrator account. Please choose it's username here. The default value should be good in most case. +Template: alternc/mysql/remote_user +Type: string +_Description: AlternC's mysql account: + Using a remote mysql installation requires the AlternC user to be configured in advance + with root access to the mysql installation. + . + The alternc sql user is responsible for granting access to user generated databases, + that is why it needs root access on the mysql installation. + Template: alternc/mysql/password Type: password _Description: Password of the AlternC's mysql account: @@ -105,6 +114,13 @@ _Description: Password of the AlternC's mysql account: Please choose a quite complex password since it will have full access to the system database !!! +Template: alternc/mysql/remote_password +Type: password +_Description: Password of the AlternC's mysql account: + Specify the remote mysql user password + . + Please choose a quite complex password since it will have full access to + the system database !!! Template: alternc/mysql/alternc_mail_user Type: string