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

198 lines
5.7 KiB
Bash

#!/bin/bash
ZPUSHVER="2.7.1"
ZPUSHVER=$(whiptail --title "Z-Push version" --inputbox "" 0 30 "${ZPUSHVER}" 3>&1 1>&2 2>&3)
TIMEZONE="Europe\/Zurich"
TIMEZONE=$(whiptail --title "Default timezone" --inputbox "" 0 30 "${TIMEZONE}" 3>&1 1>&2 2>&3)
BACKENDVER=71
BACKENDVER=$(whiptail --title "Backend version" --inputbox "" 0 30 "${BACKENDVER}" 3>&1 1>&2 2>&3)
ZIMBRAURL="https://test.mbx.netm.ch"
ZIMBRAURL=$(whiptail --title "Zimbra URL" --inputbox "" 0 30 "${ZIMBRAURL}" 3>&1 1>&2 2>&3)
APACHE2PORT=4433
APACHE2PORT=$(whiptail --title "Apache SSL Port" --inputbox "" 0 30 "${APACHE2PORT}" 3>&1 1>&2 2>&3)
main() {
inst_dep
inst_z-push "${ZPUSHVER}" "${TIMEZONE}"
inst_z-push-update
inst_z-push-backend "${BACKENDVER}" "${ZIMBRAURL}"
inst_z-push-backend-update
conf_apache2
conf_logrotate
}
inst_dep() {
apt -y install php php-cli php-soap php-mbstring php-curl php-intl php-fpm
mkdir /var/lib/z-push
mkdir /var/log/z-push
mkdir /var/www/z-push
}
inst_z-push() { # $1=version $2=timezone
cd || exit 1
wget -O z-push.tar.gz https://github.com/Z-Hub/Z-Push/archive/refs/tags/"${1}".tar.gz
tar xzvf z-push.tar.gz
cp -r Z-Push-"${1}"/src/* /var/www/z-push
rm z-push.tar.gz
rm -r Z-Push-"${1}"
# Config
sed -i "s/'TIMEZONE', ''/'TIMEZONE', '${2}'/" /var/www/z-push/config.php
sed -i "s/'BACKEND_PROVIDER', ''/'BACKEND_PROVIDER', 'BackendZimbra'/" /var/www/z-push/config.php
}
inst_z-push-update() {
cat << 'EOF' > /usr/local/bin/mtm-zpushupdate
show_help() {
echo "mtm-zpushupdate version"
echo ""
echo "Example :"
echo "mtm-zpushupdate 2.7.1"
echo "Look at :"
echo "https://github.com/Z-Hub/Z-Push/releases"
}
if [ "${1}" == "" ]; then
show_help
exit 1
fi
cd || exit 1
wget -O z-push.tar.gz https://github.com/Z-Hub/Z-Push/archive/refs/tags/"${1}".tar.gz
tar xzvf z-push.tar.gz
mv /var/www/z-push /var/www/z-push.upd
mkdir /var/www/z-push
cp -r Z-Push-"${1}"/src/* /var/www/z-push
mv /var/www/z-push/config.php /var/www/z-push/config.php.new
mv /var/www/z-push.upd/config.php /var/www/z-push/
mv /var/www/z-push.upd/backend/zimbra /var/www/z-push/backend/
# chown -R www-data:www-data /var/www/z-push
systemctl restart apache2.service
rm -r /var/www/z-push.upd
rm z-push.tar.gz
rm -r Z-Push-"${1}"
diff /var/www/z-push/config.php /var/www/z-push/config.php.new
EOF
chmod 755 /usr/local/bin/mtm-zpushupdate
}
inst_z-push-backend() { # $1=version $2=zimbraurl
cd || exit 1
wget https://sourceforge.net/projects/zimbrabackend/files/Release"${1}"/zimbra"${1}".tgz/download
tar -xf download
cp -r zimbra"${1}" /var/www/z-push/backend/zimbra
rm download
rm -r zimbra"${1}"
# Config
sed -i "/define('ZIMBRA_URL', 'https:\/\/127.0.0.1');/a \ define('ZIMBRA_URL', '${2}');" /var/www/z-push/backend/zimbra/config.php
}
inst_z-push-backend-update() {
cat << 'EOF' > /usr/local/bin/mtm-zpushbackendupdate
show_help() {
echo "mtm-zpushbackendupdate version"
echo ""
echo "Example :"
echo "mtm-zpushbackendupdate 71"
echo "Look at :"
echo "https://sourceforge.net/projects/zimbrabackend/files"
}
if [ "${1}" == "" ]; then
show_help
exit 1
fi
cd || exit 1
wget https://sourceforge.net/projects/zimbrabackend/files/Release"${1}"/zimbra"${1}".tgz/download
tar -xf download
mv /var/www/z-push/backend/zimbra /var/www/z-push/backend/zimbra.upd
cp -r zimbra"${1}" /var/www/z-push/backend/zimbra
mv /var/www/z-push/backend/zimbra/config.php /var/www/z-push/backend/zimbra/config.php.new
mv /var/www/z-push/backend/zimbra.upd/config.php /var/www/z-push/backend/zimbra/config.php
# chown -R www-data:www-data /var/www/z-push/backend/zimbra
systemctl restart apache2.service
rm -r /var/www/z-push/backend/zimbra.upd
rm download
rm -r zimbra"${1}"
diff /var/www/z-push/backend/zimbra/config.php /var/www/z-push/backend/zimbra/config.php.new
EOF
chmod 755 /usr/local/bin/mtm-zpushbackendupdate
}
conf_apache2() {
chown -R www-data:www-data /var/lib/z-push
chown -R www-data:www-data /var/log/z-push
# chown -R www-data:www-data /var/www/z-push
a2dissite 000-default.conf
a2enmod ssl
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
cat << EOF > /etc/apache2/ports.conf
<IfModule ssl_module>
Listen ${APACHE2PORT}
</IfModule>
<IfModule mod_gnutls.c>
Listen ${APACHE2PORT}
</IfModule>
EOF
cat << EOF > /etc/apache2/sites-available/z-push.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:${APACHE2PORT}>
ServerAdmin admin@mtm.lan
ServerName 127.0.0.1
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/z-push/
Alias /Microsoft-Server-ActiveSync /var/www/z-push/index.php
AliasMatch (?i)/Autodiscover/Autodiscover.xml /var/www/z-push/autodiscover/autodiscover.php
<Directory />
Require all granted
#AllowOverride None
</Directory>
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag magic_quotes_runtime off
php_flag short_open_tag on
# Logfiles
ErrorLog /var/log/z-push/error.log
CustomLog /var/log/z-push/access.log combined
# SSL
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
</IfModule>
EOF
a2ensite z-push.conf
systemctl restart apache2.service
}
conf_logrotate() {
cat << EOF > /etc/logrotate.d/z-push
/var/log/z-push/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
}
EOF
}
main
# iptables
if [ -f "/etc/iptables/rules.v4" ]; then
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a -A INPUT -p tcp -m tcp --dport '"${APACHE2PORT}"' -m state --state NEW -j ACCEPT' /etc/iptables/rules.v4
sed -i '/^-A INPUT -i lo -j ACCEPT.*/a # Z-PUSH' /etc/iptables/rules.v4
iptables-restore /etc/iptables/rules.v4
fi