[enh] homogenize coding style

- use 2 spaces for indentations
- remove tabulations
- remove trailing spaces
- if/then statements
This commit is contained in:
Pierre-Louis Bonicoli 2014-03-25 18:34:34 +01:00
parent 6dd6094b71
commit a5f544b705
1 changed files with 117 additions and 132 deletions

249
debian/alternc.config vendored
View File

@ -1,4 +1,4 @@
#! /bin/bash #!/bin/bash
set -e set -e
@ -8,61 +8,61 @@ set -e
db_capb backup db_capb backup
#Return if everything is good, exit error number otherwise #Return if everything is good, exit error number otherwise
function valid_ip() function valid_ip()
{ {
local ip=$1 local ip=$1
local stat=1 local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS OIFS=$IFS
IFS='.' IFS='.'
ip=($ip) ip=($ip)
IFS=$OIFS IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$? stat=$?
fi fi
return $stat return $stat
} }
#checking mysql connectivity and updating local.sh variables accordingly #checking mysql connectivity and updating local.sh variables accordingly
check_mysql(){ check_mysql()
{
STATE=0 STATE=0
while [ "$STATE" -eq 0 ]; do while [ "$STATE" -eq 0 ]; do
db_input high alternc/mysql/host || true db_input high alternc/mysql/host || true
db_go db_go
db_get alternc/mysql/host || true db_get alternc/mysql/host || true
MYSQL_HOST="$RET" MYSQL_HOST="$RET"
db_input high alternc/mysql/remote_user || true db_input high alternc/mysql/remote_user || true
db_go db_go
db_get alternc/mysql/remote_user || true db_get alternc/mysql/remote_user || true
MYSQL_USER="$RET" MYSQL_USER="$RET"
db_input high alternc/mysql/remote_password || true db_input high alternc/mysql/remote_password || true
db_go db_go
db_get alternc/mysql/remote_password || true db_get alternc/mysql/remote_password || true
MYSQL_PASSWORD="$RET" MYSQL_PASSWORD="$RET"
db_input high alternc/mysql/client || true db_input high alternc/mysql/client || true
db_go db_go
db_get alternc/mysql/client || true db_get alternc/mysql/client || true
MYSQL_CLIENT="$RET" MYSQL_CLIENT="$RET"
if [ "`mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_HOST" -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then if [ "`mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_HOST" -Bse 'SELECT "OK";' 2>/dev/null`" = "OK" ]; then
STATE=`expr $STATE + 1` STATE=`expr $STATE + 1`
else else
db_input high alternc/remote_mysql_error || true db_input high alternc/remote_mysql_error || true
db_go db_go
db_get alternc/remote_mysql_error || true db_get alternc/remote_mysql_error || true
if [ "$RET" = "false" ]; then if [ "$RET" = "false" ]; then
exit 4 exit 4
fi fi
fi fi
done done
} }
function get_first_existing_dir() { function get_first_existing_dir()
{
# Prend en premier parametre un chemin # Prend en premier parametre un chemin
# Retourne le répertoire parent existant le plus "proche" # Retourne le répertoire parent existant le plus "proche"
# Exemple: on lui donne /var/www/alternc/gerard/dupont/ mais # Exemple: on lui donne /var/www/alternc/gerard/dupont/ mais
@ -79,7 +79,6 @@ function get_first_existing_dir() {
} }
# default values for local.sh # default values for local.sh
MYSQL_HOST=127.0.0.1 MYSQL_HOST=127.0.0.1
MYSQL_DATABASE=alternc MYSQL_DATABASE=alternc
@ -106,14 +105,13 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
case "$QUEST_STATE" in case "$QUEST_STATE" in
1) 1)
if [ -r /etc/alternc/local.sh ]; then if [ -r /etc/alternc/local.sh ]; then
# source the current config # source the current config
. /etc/alternc/local.sh . /etc/alternc/local.sh
fi fi
# upgrade <= 3.0 to >= 3.1 # upgrade <= 3.0 to >= 3.1
if [ "x$ALTERNC_LOC" != "x" ] if [ "x$ALTERNC_LOC" != "x" ]; then
then ALTERNC_HTML="$ALTERNC_LOC/html"
ALTERNC_HTML="$ALTERNC_LOC/html" ALTERNC_MAIL="$ALTERNC_LOC/mail"
ALTERNC_MAIL="$ALTERNC_LOC/mail"
fi fi
#We ask for the hosting name and the FQDN #We ask for the hosting name and the FQDN
@ -136,19 +134,19 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
while [ $STATE -eq 0 ]; do while [ $STATE -eq 0 ]; do
db_input high alternc/public_ip || true db_input high alternc/public_ip || true
db_go db_go
db_get alternc/public_ip db_get alternc/public_ip
ip="$RET" ip="$RET"
if valid_ip $ip ; then 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 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_input high alternc/use_private_ip || true
db_go db_go
db_get alternc/use_private_ip db_get alternc/use_private_ip
if [ "$RET" = "true" ]; then if [ "$RET" = "true" ]; then
STATE=1 STATE=1
else else
db_reset alternc/use_private_ip || true db_reset alternc/use_private_ip || true
db_fset alternc/use_private_ip "seen" "false" || true db_fset alternc/use_private_ip "seen" "false" || true
fi fi
else else
STATE=1 STATE=1
fi fi
@ -166,11 +164,11 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
while [ $STATE -eq 0 ]; do while [ $STATE -eq 0 ]; do
db_input high alternc/internal_ip || true db_input high alternc/internal_ip || true
db_go db_go
db_get alternc/internal_ip db_get alternc/internal_ip
ip="$RET" ip="$RET"
if valid_ip $ip ; then if valid_ip $ip ; then
STATE=1 STATE=1
fi fi
done done
;; ;;
5) 5)
@ -202,10 +200,10 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
fi fi
;; ;;
10) 10)
# We need to set the alternc_location here because we have to test for quotas and acls # We need to set the alternc_location here because we have to test for quotas and acls
db_get alternc/alternc_html db_get alternc/alternc_html
if [ -z "$RET" ];then if [ -z "$RET" ]; then
db_set alternc/alternc_html $ALTERNC_HTML db_set alternc/alternc_html $ALTERNC_HTML
db_input high alternc/alternc_html db_input high alternc/alternc_html
fi fi
@ -219,28 +217,28 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
aclcheckfile="$basedir/test-acl" aclcheckfile="$basedir/test-acl"
touch "$aclcheckfile" touch "$aclcheckfile"
setfacl -m u:root:rwx "$aclcheckfile" 2>/dev/null || ( setfacl -m u:root:rwx "$aclcheckfile" 2>/dev/null || (
test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true
db_input critical alternc/acluninstalled || true db_input critical alternc/acluninstalled || true
db_go db_go
db_reset alternc/acluninstalled || true db_reset alternc/acluninstalled || true
db_fset alternc/acluninstalled "seen" "false" || true db_fset alternc/acluninstalled "seen" "false" || true
exit 2 exit 2
) )
test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true test -e "$aclcheckfile" && rm -f "$aclcheckfile" || true
quota -gA -f $MOUNT_POINT 2>/dev/null || ( quota -gA -f $MOUNT_POINT 2>/dev/null || (
db_get alternc/quotauninstalled db_get alternc/quotauninstalled
if [ -z "$RET" ]; then if [ -z "$RET" ]; then
db_input critical alternc/quotauninstalled || true db_input critical alternc/quotauninstalled || true
db_go db_go
#db_reset alternc/quotauninstalled || true #db_reset alternc/quotauninstalled || true
db_set alternc/quotauninstalled "false" || true db_set alternc/quotauninstalled "false" || true
fi fi
) )
;; ;;
11) 11)
db_get alternc/alternc_mail db_get alternc/alternc_mail
if [ -z "$RET" ];then if [ -z "$RET" ]; then
db_set alternc/alternc_mail $ALTERNC_MAIL db_set alternc/alternc_mail $ALTERNC_MAIL
db_input high alternc/alternc_mail db_input high alternc/alternc_mail
fi fi
@ -255,31 +253,31 @@ while [ "$QUEST_STATE" != 0 -a "$QUEST_STATE" != 13 ]; do
esac esac
if db_go; then if db_go; then
QUEST_STATE=$(($QUEST_STATE + 1)) QUEST_STATE=$(($QUEST_STATE + 1))
else else
QUEST_STATE=$(($QUEST_STATE - 1)) QUEST_STATE=$(($QUEST_STATE - 1))
fi fi
done done
if [ -r /etc/alternc/my.cnf ]; then if [ -r /etc/alternc/my.cnf ]; then
# make mysql configuration available as shell variables # make mysql configuration available as shell variables
# to convert from .cnf to shell syntax, we: # to convert from .cnf to shell syntax, we:
# * match only lines with "equal" in them (/=/) # * match only lines with "equal" in them (/=/)
# * remove whitespace around the = and add a left quote operator ' (;s) # * remove whitespace around the = and add a left quote operator ' (;s)
# * add a right quote operator at the end of line (;s) # * add a right quote operator at the end of line (;s)
# * convert mysql variables into our MYSQL_ naming convention (;s) # * convert mysql variables into our MYSQL_ naming convention (;s)
# * print the result (;p) # * print the result (;p)
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` 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`
fi fi
if [ -r /etc/alternc/my_mail.cnf ]; then if [ -r /etc/alternc/my_mail.cnf ]; then
# make mysql configuration available as shell variables # make mysql configuration available as shell variables
# to convert from .cnf to shell syntax, we: # to convert from .cnf to shell syntax, we:
# * match only lines with "equal" in them (/=/) # * match only lines with "equal" in them (/=/)
# * remove whitespace around the = and add a left quote operator ' (;s) # * remove whitespace around the = and add a left quote operator ' (;s)
# * add a right quote operator at the end of line (;s) # * add a right quote operator at the end of line (;s)
# * convert mysql variables into our MYSQL_ naming convention (;s) # * convert mysql variables into our MYSQL_ naming convention (;s)
# * print the result (;p) # * print the result (;p)
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` 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 fi
@ -297,9 +295,8 @@ fi
db_get alternc/monitor_ip db_get alternc/monitor_ip
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/monitor_ip "$MONITOR_IP"
db_set alternc/monitor_ip "$MONITOR_IP"
fi fi
db_get alternc/ns2 db_get alternc/ns2
@ -309,31 +306,26 @@ db_set alternc/ns2 "$NS2_HOSTNAME"
fi fi
db_get alternc/default_mx2 db_get alternc/default_mx2
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/default_mx2 "$DEFAULT_SECONDARY_MX"
db_set alternc/default_mx2 "$DEFAULT_SECONDARY_MX"
fi fi
db_get alternc/mysql/host db_get alternc/mysql/host
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/mysql/host "$MYSQL_HOST"
db_set alternc/mysql/host "$MYSQL_HOST"
fi fi
#Even if we asked the question concerning the database earlier in the process #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 #those calls are needed to pass the variable of remote sql server to AlternC
db_get alternc/mysql/db db_get alternc/mysql/db
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/mysql/db "$MYSQL_DATABASE"
db_set alternc/mysql/db "$MYSQL_DATABASE"
fi fi
db_get alternc/mysql/user db_get alternc/mysql/user
if [ -z "$RET" ] if [ -z "$RET" ]; then
then
db_get alternc/mysql/remote_user db_get alternc/mysql/remote_user
if [ -z "$RET" ] if [ -z "$RET" ]; then
then
db_set alternc/mysql/user "$MYSQL_USER" db_set alternc/mysql/user "$MYSQL_USER"
else else
db_set alternc/mysql/user "$RET" db_set alternc/mysql/user "$RET"
@ -341,11 +333,9 @@ if [ -z "$RET" ]
fi fi
db_get alternc/mysql/password db_get alternc/mysql/password
if [ -z "$RET" ] if [ -z "$RET" ]; then
then
db_get alternc/mysql/remote_password db_get alternc/mysql/remote_password
if [ -z "$RET" ] if [ -z "$RET" ]; then
then
db_set alternc/mysql/password "$MYSQL_PASS" db_set alternc/mysql/password "$MYSQL_PASS"
else else
db_set alternc/mysql/password "$RET" db_set alternc/mysql/password "$RET"
@ -353,33 +343,28 @@ if [ -z "$RET" ]
fi fi
db_get alternc/mysql/client db_get alternc/mysql/client
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/mysql/client "$MYSQL_CLIENT"
db_set alternc/mysql/client "$MYSQL_CLIENT"
fi fi
db_get alternc/sql/backup_type db_get alternc/sql/backup_type
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/sql/backup_type "$SQLBACKUP_TYPE"
db_set alternc/sql/backup_type "$SQLBACKUP_TYPE"
fi fi
db_get alternc/sql/backup_overwrite db_get alternc/sql/backup_overwrite
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/sql/backup_overwrite "$SQLBACKUP_OVERWRITE"
db_set alternc/sql/backup_overwrite "$SQLBACKUP_OVERWRITE"
fi fi
db_get alternc/mysql/alternc_mail_user db_get alternc/mysql/alternc_mail_user
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/mysql/alternc_mail_user "$MYSQL_MAIL_USER"
db_set alternc/mysql/alternc_mail_user "$MYSQL_MAIL_USER"
fi fi
db_get alternc/mysql/alternc_mail_password db_get alternc/mysql/alternc_mail_password
if [ -z "$RET" ] if [ -z "$RET" ]; then
then db_set alternc/mysql/alternc_mail_password "$MYSQL_MAIL_PASS"
db_set alternc/mysql/alternc_mail_password "$MYSQL_MAIL_PASS"
fi fi
db_input low alternc/default_mx2 || true db_input low alternc/default_mx2 || true