install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. # PirateBox app for YunoHost
  3. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. # Contribute at https://github.com/jvaubourg/piratebox_ynh
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. # Retrieve arguments
  19. domain=${1}
  20. url_path=/piratebox
  21. opt_deleting=${2}
  22. opt_renaming=${3}
  23. opt_chat=${4}
  24. if [ "${opt_deleting}" == yes ]; then
  25. opt_deleting=true
  26. else
  27. opt_deleting=false
  28. fi
  29. if [ "${opt_renaming}" == yes ]; then
  30. opt_renaming=true
  31. else
  32. opt_renaming=false
  33. fi
  34. if [ "${opt_chat}" == yes ]; then
  35. opt_chat=true
  36. else
  37. opt_chat=false
  38. fi
  39. # Check domain/path availability
  40. sudo yunohost app checkurl ${domain}${url_path} -a piratebox
  41. if [ ! $? -eq 0 ]; then
  42. exit 1
  43. fi
  44. # Install packages
  45. packages='php5-fpm iptables libnet-dns-perl git'
  46. export DEBIAN_FRONTEND=noninteractive
  47. sudo apt-get --assume-yes --force-yes install ${packages}
  48. if [ $? -ne 0 ]; then
  49. sudo apt-get update
  50. sudo apt-get --assume-yes --force-yes install ${packages}
  51. fi
  52. # Copy confs
  53. sudo mkdir -pm 0755 /var/log/nginx/
  54. sudo mkdir -pm 0755 /var/spool/piratebox/
  55. sudo chown www-data: /var/spool/piratebox/
  56. sudo install -b -o root -g root -m 0644 ../conf/nginx_captive-piratebox.conf /etc/nginx/conf.d/captive-piratebox.conf
  57. sudo install -b -o root -g root -m 0644 ../conf/nginx_piratebox.conf "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  58. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_piratebox.conf /etc/php5/fpm/pool.d/piratebox.conf
  59. # Copy web sources
  60. sudo git clone https://github.com/jvaubourg/php-piratebox.git /var/www/piratebox/
  61. sudo chown -R root: /var/www/piratebox/
  62. sudo chmod -R 0644 /var/www/piratebox/
  63. sudo find /var/www/piratebox/ -type d -exec chmod +x {} \;
  64. sudo install -b -o root -g root -m 0644 ../conf/piratebox_config.php.tpl /var/www/piratebox/config.php
  65. # Fix permissions
  66. sudo chown -R www-data: /var/www/piratebox/public/uploads/
  67. sudo chown -R www-data: /var/www/piratebox/public/chat/
  68. # Fix php-piratebox configuration
  69. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /var/www/piratebox/config.php
  70. sudo sed "s|<TPL:OPT_RENAMING>|$opt_renaming|g" -i /var/www/piratebox/config.php
  71. sudo sed "s|<TPL:OPT_DELETING>|$opt_deleting|g" -i /var/www/piratebox/config.php
  72. sudo sed "s|<TPL:OPT_CHAT>|$opt_chat|g" -i /var/www/piratebox/config.php
  73. # Fix confs
  74. ## nginx
  75. sudo sed "s|<TPL:DOMAIN>|${domain}|g" -i /etc/nginx/conf.d/captive-piratebox.conf
  76. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/nginx/conf.d/captive-piratebox.conf
  77. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/nginx/conf.d/captive-piratebox.conf
  78. ## php-fpm
  79. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  80. sudo sed 's|<TPL:PHP_USER>|www-data|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  81. sudo sed 's|<TPL:PHP_GROUP>|www-data|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  82. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  83. # Install fakedns
  84. sudo install -o root -g root -m 0755 ../conf/piratebox_fakedns /usr/local/bin/
  85. # Copy init script
  86. sudo install -o root -g root -m 0755 ../conf/init_ynh-piratebox /etc/init.d/ynh-piratebox
  87. # Update firewall
  88. sudo yunohost firewall allow --no-upnp UDP 4253
  89. sudo yunohost firewall allow --no-upnp TCP 4280
  90. # Set default inits
  91. sudo yunohost service add php5-fpm
  92. sudo yunohost service enable php5-fpm
  93. sudo service php5-fpm restart
  94. sudo service nginx reload
  95. sudo yunohost service add ynh-piratebox
  96. sudo yunohost service enable ynh-piratebox
  97. sudo service ynh-piratebox start
  98. # Update SSO
  99. sudo yunohost app setting piratebox skipped_uris -v /
  100. sudo yunohost app ssowatconf
  101. exit 0