os-init/ubuntu-20.04/apps/zimbra-10/zimbra-10.sh
2023-11-19 20:25:10 +01:00

67 lines
2.1 KiB
Bash

#!/bin/bash
MTMZMBUILDER="http://10.80.70.167"
MTMZMBUILDER=$(whiptail --title "ZM Builder URL" --inputbox "" 0 30 "${MTMZMBUILDER}" 3>&1 1>&2 2>&3)
ZIMBRAVER=10.0.5
ZIMBRAVER=$(whiptail --title "Zimbra version" --inputbox "" 0 30 "${ZIMBRAVER}" 3>&1 1>&2 2>&3)
DNSIP=$(grep "nameserver " /etc/resolv.conf | awk -F ' ' '{print $2}')
FQDN=$(hostname -A)
apt -y remove postfix
apt -y autoremove
mkdir v"${ZIMBRAVER}"
cd v"${ZIMBRAVER}" || exit 1
wget "${MTMZMBUILDER}"/zcs-"${ZIMBRAVER}".tgz
tar xf zcs-*.tgz
cd "$(ls -d ./*/)" || exit 1
systemctl disable systemd-resolved.service
systemctl stop systemd-resolved.service
./install.sh
cd || exit 1
sed -i "s/127.0.0.1/${DNSIP}/" /etc/resolv.conf
sudo -u zimbra bash -c "/opt/zimbra/bin/zmprov mcf zimbraPublicServiceHostname ${FQDN}"
sudo -u zimbra bash -c "/opt/zimbra/bin/zmprov mcf zimbraPublicServicePort 443"
cat << 'EOF' > /usr/local/bin/mtm-zmupdate
#!/bin/bash
MTMZMBUILDER=${1}
ZIMBRAVER=${2}
show_help() {
echo "mtm-zmupdate zmbuilder zmversion"
echo ""
echo "Example :"
echo "mtm-zmupdate https://x.x.x.x 10.0.5"
}
if [ "${MTMZMBUILDER}" == "" ] || [ "${ZIMBRAVER}" == "" ]; then
show_help
exit 1
fi
cd || exit 1
mkdir v"${ZIMBRAVER}"
cd v"${ZIMBRAVER}" || exit 1
wget "${MTMZMBUILDER}"/zcs-"${ZIMBRAVER}".tgz
tar xf zcs-*.tgz
cd "$(ls -d ./*/)" || exit 1
./install.sh
cd || exit 1
EOF
chmod 755 /usr/local/bin/mtm-zmupdate
apt update
apt -y dist-upgrade
if [ -f "/etc/iptables/rules.v4" ]; then
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a -A INPUT -p tcp -m tcp --dport 8443 -m state --state NEW -j ACCEPT' /etc/iptables/rules.v4
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a -A INPUT -p tcp -m tcp --dport 7071 -m state --state NEW -j ACCEPT' /etc/iptables/rules.v4
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a -A INPUT -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT' /etc/iptables/rules.v4
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a -A INPUT -p tcp -m tcp --dport 25 -m state --state NEW -j ACCEPT' /etc/iptables/rules.v4
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a # ZIMBRA' /etc/iptables/rules.v4
iptables-restore /etc/iptables/rules.v4
fi