[email_account] Fix typos in comments and echo
Some typos and English mistakes in comments and in printed messages. Prefix error messages with "Error!".
This commit is contained in:
parent
d11ba705fe
commit
16960f727c
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Display usage
|
# Display usage.
|
||||||
usage ()
|
usage ()
|
||||||
{
|
{
|
||||||
local - progname
|
local - progname
|
||||||
|
@ -12,30 +12,32 @@ usage ()
|
||||||
echo "$progname emailaccount [emailalias]"
|
echo "$progname emailaccount [emailalias]"
|
||||||
echo "$progname -h | --help"
|
echo "$progname -h | --help"
|
||||||
echo
|
echo
|
||||||
echo "Fist form add an email account named emailaccount if it doesn't already exist"
|
echo "Fist form adds an email account named emailaccount if it doesn't already exist"
|
||||||
echo "and create an alias named emailalias for this email account if specified"
|
echo "and creates an alias named emailalias for this email account if specified."
|
||||||
echo
|
echo
|
||||||
echo "Second and third form print this help"
|
echo "Second form prints this help."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test an email is valid and exit if it isn't
|
# Test an email is valid and exit if it isn't.
|
||||||
test_email ()
|
test_email ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
user=$(echo "$1" | cut -d '@' -f 1)
|
user=$(echo "$1" | cut -d '@' -f 1)
|
||||||
if [ -z "$user" ]
|
if [ -z "$user" ]
|
||||||
then
|
then
|
||||||
echo "Missing user in email account"
|
echo "Error! Missing user in email account."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
domain=$(echo "$1" | cut -d '@' -f 2)
|
domain=$(echo "$1" | cut -d '@' -f 2)
|
||||||
if echo "$domain" | grep -E -v "^([[:alnum:]]+\.)+[[:alnum:]]+$" > /dev/null
|
if echo "$domain" | grep -E -v "^([[:alnum:]]+\.)+[[:alnum:]]+$" > /dev/null
|
||||||
then
|
then
|
||||||
echo "Invalid domain for email account"
|
echo "Error! Invalid domain for email account."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Ask a question to the user. Return 1 if the answer is negative,
|
||||||
|
# or 0 if it is positive.
|
||||||
ask_user_default_no ()
|
ask_user_default_no ()
|
||||||
{
|
{
|
||||||
local - answer
|
local - answer
|
||||||
|
@ -57,13 +59,13 @@ ask_user_default_no ()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test number of argument is correct and their value are correct also
|
# Test number of argument is correct and their value are correct also.
|
||||||
test_args ()
|
test_args ()
|
||||||
{
|
{
|
||||||
local - user domain first_ask next_ask
|
local - user domain first_ask next_ask
|
||||||
if [ \( $# -ge 1 -a "$1" = "-h" -a $# -gt 1 \) -o $# -gt 2 ]
|
if [ \( $# -ge 1 -a "$1" = "-h" -a $# -gt 1 \) -o $# -gt 2 ]
|
||||||
then
|
then
|
||||||
echo "Too many arguments"
|
echo "Error! Too many arguments."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ $# -eq 0 -o "$1" = "-h" -o "$1" = "-help" ]
|
if [ $# -eq 0 -o "$1" = "-h" -o "$1" = "-help" ]
|
||||||
|
@ -82,22 +84,22 @@ test_args ()
|
||||||
aliasdomain="$domain"
|
aliasdomain="$domain"
|
||||||
if [ "$emaildomain" != "$aliasdomain" ]
|
if [ "$emaildomain" != "$aliasdomain" ]
|
||||||
then
|
then
|
||||||
echo "Domain of the alias must be identical to the domain of the email account"
|
echo "Error! Domain of the alias must be identical to the domain of the email account."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
first_ask="Be aware that you'll need to restart cyrus twice and postfix once. Are you ready ?"
|
first_ask="Be aware that you'll need to restart cyrus twice and postfix once. Are you ready?"
|
||||||
next_ask="Incorrect answer. Are you ready to restart cyrus and postfix ?"
|
next_ask="Incorrect answer. Are you ready to restart cyrus and postfix?"
|
||||||
ask_user_default_no "$first_ask" "$next_ask"
|
ask_user_default_no "$first_ask" "$next_ask"
|
||||||
if [ $? -eq 1 ]
|
if [ $? -eq 1 ]
|
||||||
then
|
then
|
||||||
echo "Ok, exiting_"
|
echo "Ok, exiting…"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Are we root ?
|
# Are we root?
|
||||||
must_sudo ()
|
must_sudo ()
|
||||||
{
|
{
|
||||||
uid="$(id -u)"
|
uid="$(id -u)"
|
||||||
|
@ -105,28 +107,28 @@ must_sudo ()
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function try to become root with sudo and execute this script
|
# This function tries to become root with sudo and execute this script.
|
||||||
# NB: This function doesn't return
|
# NB: This function doesn't return.
|
||||||
try_sudo ()
|
try_sudo ()
|
||||||
{
|
{
|
||||||
local - ret
|
local - ret
|
||||||
echo "You aren't root. Trying to use sudo to become root…"
|
echo "You aren't root. Trying to use sudo to become root…"
|
||||||
sudo $0 "$@"
|
sudo $0 "$@" # Try to execute the script with sudo
|
||||||
ret=$?
|
ret=$?
|
||||||
if [ ! $ret -eq 0 ]
|
if [ ! $ret -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "You must be root or being able to become root by sudo without password to create an email account or add an email alias"
|
echo "Error! You must be root or being able to become root by sudo without password to create an email account or add an email alias."
|
||||||
fi
|
fi
|
||||||
exit $ret
|
exit $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test cyrus password is ok
|
# Test cyrus password is OK.
|
||||||
test_cyrus_admin ()
|
test_cyrus_admin ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
cyruser=$(grep -E "^[[:space:]]*admins:" /etc/imapd.conf | cut -d ':' -f 2- | sed -r "s/[[:alnum:]]+@[[:alnum:].]+//g" | tr -d ' ')
|
cyruser=$(grep -E "^[[:space:]]*admins:" /etc/imapd.conf | cut -d ':' -f 2- | sed -r "s/[[:alnum:]]+@[[:alnum:].]+//g" | tr -d ' ')
|
||||||
cyrpwd=$(cat /root/cyrus_main_admin_password)
|
cyrpwd=$(cat /root/cyrus_main_admin_password)
|
||||||
testsaslauthd -u $cyruser -p $cyrpwd > /dev/null || { echo "Password for main cyrus admin has changed but has not been modified in /root/" && exit 1 ; }
|
testsaslauthd -u $cyruser -p $cyrpwd > /dev/null || { echo "Error! Password for main cyrus admin has changed but has not been modified in /root/" && exit 1 ; }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Save cyrus state and make it cyradm ready, that is save and change
|
# Save cyrus state and make it cyradm ready, that is save and change
|
||||||
|
@ -141,14 +143,14 @@ save_cyrus_state_and_become_cyradm_ready ()
|
||||||
invoke-rc.d cyrus2.2 restart
|
invoke-rc.d cyrus2.2 restart
|
||||||
if [ ! $? -eq 0 ]
|
if [ ! $? -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "Restarting cyrus failed. The requested action coudn't be performed."
|
echo "Error! Restarting cyrus failed. The requested action coudn't be performed."
|
||||||
echo "Look at the logs and restart Cyrus manually."
|
echo "Look at the logs and restart Cyrus manually."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ask a password to the user and create the entry in sasldb database
|
# Ask a password to the user and create the entry in sasldb database.
|
||||||
ask_and_create_password ()
|
ask_and_create_password ()
|
||||||
{
|
{
|
||||||
local - newemailpassword
|
local - newemailpassword
|
||||||
|
@ -157,38 +159,38 @@ ask_and_create_password ()
|
||||||
while [ "$emailpassword" != "$newemailpassword" ]
|
while [ "$emailpassword" != "$newemailpassword" ]
|
||||||
do
|
do
|
||||||
emailpassword=""
|
emailpassword=""
|
||||||
echo "What password do you want for your email account ?"
|
echo "What password do you want for your email account?"
|
||||||
while [ -z "$emailpassword" ]
|
while [ -z "$emailpassword" ]
|
||||||
do
|
do
|
||||||
echo -n "Password : "
|
echo -n "Password: "
|
||||||
read emailpassword
|
read emailpassword
|
||||||
done
|
done
|
||||||
newemailpassword=""
|
newemailpassword=""
|
||||||
echo "Re-enter your password to ensure you type it in correctly"
|
echo "Please re-enter your password to ensure you typed it correctly."
|
||||||
while [ -z "$newemailpassword" ]
|
while [ -z "$newemailpassword" ]
|
||||||
do
|
do
|
||||||
echo -n "Password (bis) : "
|
echo -n "Password (bis): "
|
||||||
read newemailpassword
|
read newemailpassword
|
||||||
done
|
done
|
||||||
if [ "$emailpassword" != "$newemailpassword" ]
|
if [ "$emailpassword" != "$newemailpassword" ]
|
||||||
then
|
then
|
||||||
echo "Password don't match"
|
echo "Passwords don't match!"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "$emailpassword" | saslpasswd2 -p -u "$emaildomain" "$emailuser"
|
echo "$emailpassword" | saslpasswd2 -p -u "$emaildomain" "$emailuser"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if a password already exist in the sasldb database.
|
# Check if a password already exists in the sasldb database.
|
||||||
# Then ask a password to the user and create the entry in sasldb
|
# Then ask a password to the user and create the entry in sasldb
|
||||||
# database if password doesn't exist are user want to change it
|
# database if password doesn't exist are user want to change it.
|
||||||
create_sasldb_password ()
|
create_sasldb_password ()
|
||||||
{
|
{
|
||||||
local - first_ask next_ask
|
local - first_ask next_ask
|
||||||
sasldblistusers2 | grep "$emailuser@$emaildomain" > /dev/null
|
sasldblistusers2 | grep "$emailuser@$emaildomain" > /dev/null
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
then
|
then
|
||||||
first_ask="There is already a password for this user, do you want to change it ?"
|
first_ask="There is already a password for this user, do you want to change it?"
|
||||||
next_ask="Do you want to change the existing password for your email account ?"
|
next_ask="Do you want to change the existing password for your email account?"
|
||||||
ask_user_default_no "$first_ask" "$next_ask"
|
ask_user_default_no "$first_ask" "$next_ask"
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
then
|
then
|
||||||
|
@ -202,7 +204,7 @@ create_sasldb_password ()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the domain of the email account to the list of virtual domain
|
# Add the domain of the email account to the list of virtual domain
|
||||||
# in cyrus and postfix if necessary
|
# in cyrus and postfix if necessary.
|
||||||
update_virtual_domains ()
|
update_virtual_domains ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
|
@ -227,7 +229,7 @@ update_virtual_domains ()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print the first parameter and then the second parameter at a distance
|
# Print the first parameter and then the second parameter at a distance
|
||||||
# of $3 tabs
|
# of $3 tabs.
|
||||||
echo_with_tabs ()
|
echo_with_tabs ()
|
||||||
{
|
{
|
||||||
local - nbchars nbtabs
|
local - nbchars nbtabs
|
||||||
|
@ -242,7 +244,7 @@ echo_with_tabs ()
|
||||||
echo "$2"
|
echo "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add requested email to postfix virtual_mailbox_maps
|
# Add requested email to postfix virtual_mailbox_maps.
|
||||||
update_postfix_email_account ()
|
update_postfix_email_account ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
|
@ -262,7 +264,7 @@ update_postfix_email_account ()
|
||||||
postmap /etc/postfix/vmailbox
|
postmap /etc/postfix/vmailbox
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add requested alias to postfix virtual_alias_maps
|
# Add requested alias to postfix virtual_alias_maps.
|
||||||
update_email_aliases ()
|
update_email_aliases ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
|
@ -285,7 +287,7 @@ display_infos ()
|
||||||
else
|
else
|
||||||
echo "Your email login is $emailuser@$emaildomain and your password $emailpassword"
|
echo "Your email login is $emailuser@$emaildomain and your password $emailpassword"
|
||||||
fi
|
fi
|
||||||
echo -n "supported mechanism for imap authentification are : "
|
echo -n "Supported mechanism for imap authentification are: "
|
||||||
sed -r -n "{s/sasl_mech_list: *(.*)$/\1/;t success;T;: success;p}" /etc/imapd.conf
|
sed -r -n "{s/sasl_mech_list: *(.*)$/\1/;t success;T;: success;p}" /etc/imapd.conf
|
||||||
echo -n "The imap server listen on port "
|
echo -n "The imap server listen on port "
|
||||||
imap=$(grep -E "^[^#]+cmd=\"imapd[^#]+listen=\"imap\"" /etc/cyrus.conf)
|
imap=$(grep -E "^[^#]+cmd=\"imapd[^#]+listen=\"imap\"" /etc/cyrus.conf)
|
||||||
|
@ -314,7 +316,7 @@ display_infos ()
|
||||||
fi
|
fi
|
||||||
echo -n "993 ($security)"
|
echo -n "993 ($security)"
|
||||||
fi
|
fi
|
||||||
echo
|
echo "."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Restore cyrus state as it was before making it cyradm ready, that is
|
# Restore cyrus state as it was before making it cyradm ready, that is
|
||||||
|
@ -324,9 +326,9 @@ restore_cyrus_state ()
|
||||||
{
|
{
|
||||||
local -
|
local -
|
||||||
sed -r -i "s/^(.*cmd=\"imapd.* listen=\")localhost:(imap\".*)$/\1\2/" /etc/cyrus.conf
|
sed -r -i "s/^(.*cmd=\"imapd.* listen=\")localhost:(imap\".*)$/\1\2/" /etc/cyrus.conf
|
||||||
# Ok let's explain that sed line
|
# OK, let's explain the following sed line.
|
||||||
# First you must understand that for each line all the commands inside
|
# First you must understand that for each line, all the commands inside
|
||||||
# the {} block and separated by ; are executed
|
# the {} block and separated by ; are executed.
|
||||||
# When the allowplaintext commented line is found, the # is removed by
|
# When the allowplaintext commented line is found, the # is removed by
|
||||||
# a s/pattern/replacement/ command. Then, as this substitution is
|
# a s/pattern/replacement/ command. Then, as this substitution is
|
||||||
# successful, we jump at success which copy the substituted line in
|
# successful, we jump at success which copy the substituted line in
|
||||||
|
@ -334,20 +336,20 @@ restore_cyrus_state ()
|
||||||
# it by the substituted line. We've just deleted the next line. Then,
|
# it by the substituted line. We've just deleted the next line. Then,
|
||||||
# we print the line in the pattern space. If from the beginning we
|
# we print the line in the pattern space. If from the beginning we
|
||||||
# have a non allowplaintext line, then T makes us jump to fail and
|
# have a non allowplaintext line, then T makes us jump to fail and
|
||||||
# print the line in the pattern space (that is the current line)
|
# print the line in the pattern space (that is the current line).
|
||||||
sed -r -n -i "{s/^#([[:space:]]*allowplaintext:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
|
sed -r -n -i "{s/^#([[:space:]]*allowplaintext:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
|
||||||
# Same as for allowplaintext above
|
# Same as above for virtdomains
|
||||||
sed -r -n -i "{s/^#([[:space:]]*virtdomains:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
|
sed -r -n -i "{s/^#([[:space:]]*virtdomains:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
|
||||||
invoke-rc.d --quiet cyrus2.2 restart
|
invoke-rc.d --quiet cyrus2.2 restart
|
||||||
if [ ! $? -eq 0 ]
|
if [ ! $? -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "Restarting cyrus failed"
|
echo "Error! Restarting cyrus failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
invoke-rc.d --quiet postfix reload
|
invoke-rc.d --quiet postfix reload
|
||||||
if [ ! $? -eq 0 ]
|
if [ ! $? -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "Reloading postfix failed"
|
echo "Error! Reloading postfix failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue