Subversion Repositories ALCASAR

Rev

Blame | Last modification | View Log

#!/bin/bash

##############################################################################################################################
##                                                                                                                          
##                                  ALCASAR SERVICE MAIL INSTALL                                                            
##                                                                                                                          
##      Script by joss_p                                                    
##      V 1.0 Dec 2021.                                                                                             
##  This script configure the mail conf file and execute the fonfiguration from the acc.                                                                                        
##                                                                                                                                                                                                                                              
##                                                                                                                                                                                                                                              
##############################################################################################################################

#. /usr/local/etc/alcasar-mail.conf

saslPath="/etc/postfix/sasl"
smtpIP="0.0.0.0/0"

if [[ ${#} -ne 0 ]]
then
        while getopts ":s:p:r:m:o:a:w:123" option
        do
                case $option in
                        1)
                                TYPE_MAIL=1
                        ;;
                        2)
                                TYPE_MAIL=2
                        ;;
                        3)
                                TYPE_MAIL=3
                        ;;
                        s)
                                smtp=$OPTARG
                        ;;
                        p)
                                port=$OPTARG
                        ;;
                        r)
                                smtpIP=$OPTARG
                        ;;
                        m)
                                mailAddr=$OPTARG
                        ;;
                        o)
                                mailMdp=$OPTARG
                        ;;
                        a)
                                adminMail=$OPTARG
                        ;;
                        w)
                                whiteDomain=$OPTARG
                        ;;
                        :)
                                echo "L'option $OPTARG requiert un argument"
                                exit 1
                        ;;
                        \?)
                                echo "$OPTARG : option invalide"
                                exit 1
                        ;;
                esac
        done
fi



if [[ $TYPE_MAIL -eq 2 ]]; then
        echo "relayhost = [${smtp}]:${port}" >> /etc/postfix/main.cf
elif [[ $TYPE_MAIL -eq 3 ]]; then
        echo "relayhost = [${smtp}]:${port}" >> /etc/postfix/main.cf
        [ -d ${saslPath} ] || mkdir ${saslPath}
        echo "[${smtp}]:${port} ${mailAddr}:${mailMdp}" > ${saslPath}/sasl_passwd
        postmap ${saslPath}/sasl_passwd
        chmod -R 777 ${saslPath}
        #chown root:root ${saslPath}/sasl_passwd*
        #chmod 0600 ${saslPath}/sasl_passwd*
else
        echo "Erreur ! Aucun type de messagerie sélectionné !"
        exit 0
fi

old_smtpIP=`grep "SMTP_IP=" /usr/local/etc/alcasar-iptables-local.sh  | cut -d "'" -f2`
old_port=`grep "SMTP_PORT=" /usr/local/etc/alcasar-iptables-local.sh  | cut -d "=" -f2 | cut -f1`
sed -ie "/SMTP_IP=/ s@${old_smtpIP}@${smtpIP}@" /usr/local/etc/alcasar-iptables-local.sh
sed -ie "/SMTP_PORT=/ s/${old_port}/${port}/" /usr/local/etc/alcasar-iptables-local.sh
sed -ie "/SMTP_IP=/ s/^#//" /usr/local/etc/alcasar-iptables-local.sh
sed -ie "/SMTP_PORT/ s/^#//g" /usr/local/etc/alcasar-iptables-local.sh
#chmod 740 /usr/local/etc/alcasar-iptables-local.sh
#chmod 700 /usr/local/bin/alcasar-iptables.sh
bash /usr/local/bin/alcasar-iptables.sh

exit 0