Advertisement
trupsalms

Untitled

May 17th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. #!/bin/bash
  2. # Z-Push for Modoboa install script v0.1 ALPHA
  3. # This script is very messy and basic, calendar is not tested and is only set up to get easy configuration to mobile and outlook clients.
  4. # No support provided, however someone in https://discord.gg/WuQ3v3PXGR might be able to help?
  5.  
  6. # Pre-flight check to see if Modoboa's default NginX config have been removed
  7. tld=`awk -F "[, ]+" '/server_name/{print substr($3, 12, length($3)-12)}' /etc/nginx/sites-available/autoconfig.*.conf`
  8. if [ "$tld" = "" ];
  9. then
  10. echo "No Domain found, please enter a domain (note: must be DOMAIN.TLD format and not include subdomain)"
  11. read -p "Domain: " tld
  12. fi
  13.  
  14. echo -e "Install PHP dependencies"
  15. apt install -y php-fpm php-mbstring php-imap php-soap php-common php-xsl php-curl libawl-php wget -y
  16. phpenmod -v ALL imap
  17. phpenmod -v ALL mbstring
  18. phpenmod -v ALL soap
  19. phpenmod -v ALL xsl
  20. phpenmod -v ALL curl
  21.  
  22. echo -e "Download Z-Push"
  23. cd /tmp/
  24. wget -O /tmp/z-push.zip https://github.com/bob4os/Z-Push/archive/refs/heads/develop.zip
  25.  
  26. echo -e "Extract and move Z-Push into /srv/"
  27. unzip /tmp/z-push.zip -d /tmp/
  28. mv /tmp/Z-Push-develop/src /srv/z-push
  29. rm -rf /tmp/Z-Push-develop /tmp/z-push.zip
  30.  
  31. echo -e "Create log dir and set permissions"
  32. mkdir /var/log/z-push
  33. chown www-data:adm /var/log/z-push
  34. chmod 755 /var/log/z-push
  35.  
  36. echo -e "Lets edit these Configs to work on Modoboa's setup"
  37. sed -i "s/\/var\/lib\/z-push/\/srv\/z-push/g" /srv/z-push/config.php
  38. sed -i "s/BACKEND_PROVIDER', ''/BACKEND_PROVIDER', 'BackenCombined'/g" /srv/z-push/config.php
  39. sed -i "s/BACKEND_PROVIDER', ''/BACKEND_PROVIDER', 'BackenCombined'/g" /srv/z-push/autodiscover/config.php
  40. sed -i "s/USE_FULLEMAIL_FOR_LOGIN', false/USE_FULLEMAIL_FOR_LOGIN', true/g" /srv/z-push/config.php
  41. sed -i "s/STATE_DIR', '\/var\/lib\/z-push\//STATE_DIR', '\/srv\/z-push\/lib\//g" /srv/z-push/config.php
  42. sed -i "s/IMAP_PORT', 143/IMAP_PORT', 993/g" /srv/z-push/backend/imap/config.php
  43. sed -i "s/IMAP_OPTIONS', '\/notls\/norsh/IMAP_OPTIONS', '\/ssl\/novalidate-cert/g" /srv/z-push/backend/imap/config.php
  44. sed -i "s/IMAP_FOLDER_CONFIGURED', false/IMAP_FOLDER_CONFIGURED', true/g" /srv/z-push/backend/imap/config.php
  45. sed -i "s/IMAP_FOLDER_SPAM', 'SPAM'/IMAP_FOLDER_SPAM', 'JUNK'/g" /srv/z-push/backend/imap/config.php
  46. sed -i "s/USE_FULLEMAIL_FOR_LOGIN', false/USE_FULLEMAIL_FOR_LOGIN', true/g" /srv/z-push/autodiscover/config.php
  47. sed -i "s/CALDAV_SERVER', 'caldavserver.domain.com'/CALDAV_SERVER', 'localhost'/g" /srv/z-push/backend/caldav/config.php
  48. sed -i "s/CALDAV_PATH', '\/caldav.php/CALDAV_PATH', '\/radicale/g" /srv/z-push/backend/caldav/config.php
  49. sed -i "s/CALDAV_SUPPORTS_SYNC', false/CALDAV_SUPPORTS_SYNC', true/g" /srv/z-push/backend/caldav/config.php
  50. sed -i "s/CARDDAV_PATH', '\/caldav.php/CARDDAV_PATH', '\/radicale/g" /srv/z-push/backend/carddav/config.php
  51. sed -i "s/CARDDAV_DEFAULT_PATH', '\/caldav.php\/%u\/addresses/CARDDAV_DEFAULT_PATH', '\/radicale\/%u\/contacts/g" /srv/z-push/backend/carddav/config.php
  52. sed -i "s/CARDDAV_SUPPORTS_SYNC', false/CARDDAV_SUPPORTS_SYNC', true/g" /srv/z-push/backend/carddav/config.php
  53. sed -i "s/\$val = stream_get_contents(\$message->asbody->data);/\$val = \$this->escape(stream_get_contents(\$message->asbody->data));/g" /srv/z-push/backend/carddav/carddav.php
  54.  
  55. cp -a /srv/z-push/backends/combined/config.php /srv/z-push/backend/combined/config.php.old
  56. wget -O /srv/z-push/backend/combined/config.php https://raw.githubusercontent.com/dborg89/modoboa-z-push/main/backend_combined_config.php
  57.  
  58. cp -a /srv/z-push/include/z_carddav.php /srv/z-push/include/z_carddav.php.old
  59. wget -O /srv/z-push/include/z_carddav.php https://raw.githubusercontent.com/dborg89/modoboa-z-push/main/include_z_carddav.php
  60.  
  61. echo -e "Setting Ownership to www-data"
  62. chown www-data:www-data -R /srv/z-push
  63.  
  64. echo -e "Lets setup a generic calendar creation script to ensure that everyone gets the same calendar name"
  65. wget -O /srv/modoboa/env/lib/python3.9/site-packages/calsync.py https://raw.githubusercontent.com/dborg89/radicale_create/main/calsync.py
  66. chown modoboa: /srv/modoboa/env/lib/python3.9/site-packages/calsync.py
  67. sed -i "7 i PACKAGES=/srv/modoboa/env/lib/python3.9/site-packages" /etc/cron.d/modoboa
  68. echo -e "\n# Generic calendar creation script" >> /etc/cron.d/modoboa
  69. echo -e "*/5\t*\t*\t*\t*\troot\t\$PYTHON \$PACKAGES/calsync.py >/dev/null 2>&1" >> /etc/cron.d/modoboa
  70.  
  71. echo -e "Time to edit the NignX configs"
  72. cd /etc/nginx/sites-available
  73. phpfpmpath=`find /run/php/ -name "php*-fpm.sock" |head -n 1`
  74.  
  75. echo -e "Backing up the NginX configs \n"
  76. cp -a /etc/nginx/sites-available/autoconfig.$tld.conf /etc/nginx/sites-available/autoconfig.$tld.conf.bkup-`date +"%F-%T"`
  77. cp -a /etc/nginx/sites-available/mail.$tld.conf /etc/nginx/sites-available/mail.$tld.conf.bkup-`date +"%F-%T"`
  78.  
  79. echo -e "Domain's TLD is "$tld" We need to know this to make the changes"
  80.  
  81. echo -e "Creating a new autoconfig/autodiscover config for port 80"
  82. printf "# This file was automatically installed on `date +"%F-%T.%s"`
  83. server {
  84. listen 80;
  85. listen [::]:80;
  86. server_name autoconfig.$tld;
  87. root /srv/z-push;
  88.  
  89. access_log /var/log/nginx/autoconfig.$tld-access.log;
  90. error_log /var/log/nginx/autoconfig.$tld-error.log;
  91.  
  92. # Z-Push (Microsoft Exchange ActiveSync)
  93. location /Microsoft-Server-ActiveSync {
  94. include /etc/nginx/fastcgi_params;
  95. fastcgi_pass unix:$phpfpmpath;
  96. fastcgi_param SCRIPT_FILENAME /srv/z-push/index.php;
  97. fastcgi_param PHP_VALUE "include_path=.:/usr/share/php:/usr/share/pear";
  98. fastcgi_read_timeout 630;
  99.  
  100. client_max_body_size 128M;
  101. }
  102.  
  103. # Z-Push Z-Push (Auto Discover)
  104. location ~* ^/autodiscover/autodiscover.xml {
  105. include /etc/nginx/fastcgi_params;
  106. fastcgi_pass unix:$phpfpmpath;
  107. fastcgi_param SCRIPT_FILENAME /srv/z-push/autodiscover/autodiscover.php;
  108. fastcgi_param PHP_VALUE "include_path=.:/usr/share/php:/usr/share/pear";
  109. }
  110. }" > /etc/nginx/sites-available/autoconfig.$tld.conf
  111.  
  112. echo -e "Time to edit the main Mail config (HTTPS/443)"
  113. echo -e "Search for the old automx settings and comment them out"
  114. sed -i -r "/location/{/\n/{P;D;};:1;N; /\}/!b1;/automx/s/[^\n]*\n*\n*/#&/g}" /etc/nginx/sites-available/mail.$tld.conf
  115.  
  116. echo -e "Inserting Date into line 2"
  117. sed -i "2 i \# Config edited for z-Push `date +%F-%T.%s`\n" /etc/nginx/sites-available/mail.$tld.conf
  118.  
  119. echo -e "Inserting new "
  120. sed -i "\$i\
  121. \ # Z-Push (Microsoft Exchange ActiveSync)\n\
  122. location /Microsoft-Server-ActiveSync {\n\
  123. include /etc/nginx/fastcgi_params;\n\
  124. fastcgi_pass unix:$phpfpmpath;\n\
  125. fastcgi_param SCRIPT_FILENAME /srv/z-push/index.php;\n\
  126. fastcgi_param PHP_VALUE "include_path=.:/usr/share/php:/usr/share/pear";\n\
  127. fastcgi_read_timeout 630;\n\
  128. client_max_body_size 128M;\n\
  129. }\n\
  130. \n\
  131. # Z-Push Z-Push (Auto Discover)\n\
  132. location ~* ^/autodiscover/autodiscover.xml$ {\n\
  133. include /etc/nginx/fastcgi_params;\n\
  134. fastcgi_pass unix:$phpfpmpath;\n\
  135. fastcgi_param SCRIPT_FILENAME /srv/z-push/autodiscover/autodiscover.php;\n\
  136. fastcgi_param PHP_VALUE "include_path=.:/usr/share/php:/usr/share/pear";\n\
  137. }\n\
  138. " /etc/nginx/sites-available/mail.$tld.conf
  139.  
  140. echo -e "Restarting NginX to apply the changes"
  141.  
  142. service nginx restart
  143.  
  144. echo -e "All Done!"
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement