install_update_dovecot.sh: in case of fresh install, create MySQL tables only if they not exists.

This commit is contained in:
Christoph 2018-05-16 21:00:33 +02:00
parent 6e9b526c00
commit bfac1c384f

View File

@ -128,9 +128,63 @@ do
echo -e "\n\t\033[33m\033[1mA version number is required!\033[m\n"
fi
done
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Is this a fresh new installation or an update?"
echo ""
echo ""
if [[ -n "$_update" ]]; then
if $_update || [[ "${_update,,}" = 'yes' ]] ; then
echo -e "\033[37m\033[1m[1] Update\033[m"
echo "[2] New Installation"
else
echo -e "[1] Update"
echo -e "\033[37m\033[1m[2] New Installation\033[m"
fi
echo ""
echononl "Choose a number or press <RETURN> for highlighted value: "
else
echo -e "[1] Update"
echo "[2] New Installation"
echo ""
echononl "Choose a Number: "
fi
update=""
while [[ "$update" != "true" && "$update" != "false" ]] ; do
read OPTION
case $OPTION in
1) update=true
;;
2) update=false
;;
'') if [[ -n "$_update" ]] ; then
if $_update || [[ "${_update,,}" = 'yes' ]] ; then
update=true
else
update=false
fi
else
echo ""
echo -e "\tWrong entry! [ 1 = Update ; 2 = New Installation ]"
echo ""
echononl "Reentry: "
fi
;;
*) update=""
echo ""
if [[ -n "$_IS_RELAY_HOST" ]]; then
echo -e "\tWrong entry! [ 1 = Update ; 2 = New Installation ] or type <RETURN>"
else
echo -e "\tWrong entry! [ 1 = Update ; 2 = New Installation ]"
fi
echo ""
echononl "Reentry: "
;;
esac
done
@ -143,8 +197,8 @@ echo ""
clear;
echo ""
if $_update ;then
echo -e "\tUpdate Dovecot................: $_update"
if $update ;then
echo -e "\tUpdate Dovecot................: $update"
else
echo -e "\tInstall Dovecot first time....: Yes"
fi
@ -198,8 +252,10 @@ if $xmpp_listener ; then
fi
echo ""
if ! $_update ;then
warn "Take care, your PostgreSQL configuration (pg_hba.conf) contains the following line:\n\n\t pg_hba.conf:\n\t \033[1mlocal all postfix trust\033[m"
if ! $update ;then
if [[ "$database" = "psql" ]]; then
warn "Take care, your PostgreSQL configuration (pg_hba.conf) contains the following line:\n\n\t pg_hba.conf:\n\t \033[1mlocal all postfix trust\033[m"
fi
fi
echononl "Sind die Angaben richtig [ja/nein]: "
@ -221,7 +277,7 @@ done
echo ""
if $_update ;then
if $update ;then
_new=false;
else
_new=true;
@ -712,7 +768,7 @@ if $_new ; then
echononl "\tCreate table expires in database ${dbname}.."
cat << EOF | psql -U$dbuser $dbname > /dev/null 2>&1
create table expires (
CREATE TABLE IF NOT EXISTS expires (
username varchar(100) not null,
mailbox varchar(255) not null,
expire_stamp integer not null,
@ -724,7 +780,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal Creating table expires failed
error "Creating table expires failed"
fi
echononl "\tCreate function merge_expires() / trigger mergeexpires.."
@ -800,7 +856,7 @@ EOF
echononl "\tCreate table expires in database ${dbname}.."
cat << EOF | mysql -u$dbuser -p$dbpassword $dbname > /dev/null 2>&1
create table expires (
CREATE TABLE IF NOT EXISTS expires (
username varchar(100) not null,
mailbox varchar(255) not null,
expire_stamp integer not null,
@ -811,7 +867,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal Creating table expires failed
error "Creating table expires failed"
fi
fi
fi
@ -2276,7 +2332,7 @@ if $_new ; then
echononl "\tCreate table quota2 in database \"$dbname\".."
cat << EOF | psql -U$dbuser $dbname > /dev/null 2>&1
CREATE TABLE quota2 (
CREATE TABLE IF NOT EXISTS quota2 (
username varchar(100) not null,
bytes bigint not null default 0,
messages integer not null default 0,
@ -2287,7 +2343,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table quota2 in database \"$dbname\" failed"
error "Creating table quota2 in database \"$dbname\" failed"
fi
echononl "\tCreate Trigger mergequota2.."
@ -2344,7 +2400,7 @@ EOF
elif [ "$db_driver" = "mysql" ]; then
echononl "\tCreate table quota2 in database \"$dbname\".."
cat << EOF | mysql -u$dbuser -p$dbpassword $dbname > /dev/null 2>&1
CREATE TABLE quota2 (
CREATE TABLE IF NOT EXISTS quota2 (
username varchar(100) not null,
bytes bigint not null default 0,
messages integer not null default 0,
@ -2355,7 +2411,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table quota2 in database \"$dbname\" failed"
error "Creating table quota2 in database \"$dbname\" failed"
fi
fi
@ -2909,7 +2965,7 @@ if $_new ; then
## -
echononl "\tCreate table user_share"
cat << EOF | psql -U$dbuser $dbname > /dev/null 2>&1
CREATE TABLE user_shares (
CREATE TABLE IF NOT EXISTS user_shares (
from_user varchar(100) not null,
to_user varchar(100) not null,
dummy char(1) DEFAULT '1', -- always '1' currently
@ -2921,12 +2977,12 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table user_shares failed"
error "Creating table user_shares failed"
fi
echononl "\tCreate table anyone_shares"
cat << EOF | psql -U$dbuser $dbname > /dev/null 2>&1
CREATE TABLE anyone_shares (
CREATE TABLE IF NOT EXISTS anyone_shares (
from_user varchar(100) not null,
dummy char(1) DEFAULT '1', -- always '1' currently
primary key (from_user)
@ -2937,7 +2993,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table anyone_shares failed"
error "Creating table anyone_shares failed"
fi
elif [ "$db_driver" = "mysql" ]; then
@ -2946,7 +3002,7 @@ EOF
## -
echononl "\tCreate table user_share"
cat << EOF | mysql -u$dbuser -p$dbpassword $dbname > /dev/null 2>&1
CREATE TABLE user_shares (
CREATE TABLE IF NOT EXISTS user_shares (
from_user varchar(100) not null,
to_user varchar(100) not null,
dummy char(1) DEFAULT '1', -- always '1' currently
@ -2957,12 +3013,12 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table user_shares failed"
error "Creating table user_shares failed"
fi
echononl "\tCreate table anyone_shares"
cat << EOF | mysql -u$dbuser -p$dbpassword $dbname > /dev/null 2>&1
CREATE TABLE anyone_shares (
CREATE TABLE IF NOT EXISTS anyone_shares (
from_user varchar(100) not null,
dummy char(1) DEFAULT '1', -- always '1' currently
primary key (from_user)
@ -2972,7 +3028,7 @@ EOF
echo -e "$rc_done"
else
echo -e "$rc_failed"
fatal "Creating table anyone_shares failed"
error "Creating table anyone_shares failed"
fi
fi
fi