install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. # Save arguments
  45. sudo yunohost app setting piratebox wifi_device_id -v 0
  46. # Install packages
  47. packages='php5-fpm iptables libnet-dns-perl git'
  48. export DEBIAN_FRONTEND=noninteractive
  49. sudo apt-get --assume-yes --force-yes install ${packages}
  50. if [ $? -ne 0 ]; then
  51. sudo apt-get update
  52. sudo apt-get --assume-yes --force-yes install ${packages}
  53. fi
  54. # Copy confs
  55. sudo mkdir -pm 0755 /var/log/nginx/
  56. sudo mkdir -pm 0755 /var/spool/piratebox/
  57. sudo chown www-data: /var/spool/piratebox/
  58. sudo install -b -o root -g root -m 0644 ../conf/nginx_captive-piratebox.conf /etc/nginx/conf.d/captive-piratebox.conf
  59. sudo install -b -o root -g root -m 0644 ../conf/nginx_piratebox.conf "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  60. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_piratebox.conf /etc/php5/fpm/pool.d/piratebox.conf
  61. # Copy web sources
  62. sudo git clone https://github.com/jvaubourg/php-piratebox.git /var/www/piratebox/
  63. sudo chown -R root: /var/www/piratebox/
  64. sudo chmod -R 0644 /var/www/piratebox/
  65. sudo find /var/www/piratebox/ -type d -exec chmod +x {} \;
  66. sudo install -b -o root -g root -m 0644 ../conf/piratebox_config.php.tpl /var/www/piratebox/config.php
  67. # Fix permissions
  68. sudo chown -R www-data: /var/www/piratebox/public/uploads/
  69. sudo chown -R www-data: /var/www/piratebox/public/chat/
  70. # Fix php-piratebox configuration
  71. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /var/www/piratebox/config.php
  72. sudo sed "s|<TPL:OPT_RENAMING>|$opt_renaming|g" -i /var/www/piratebox/config.php
  73. sudo sed "s|<TPL:OPT_DELETING>|$opt_deleting|g" -i /var/www/piratebox/config.php
  74. sudo sed "s|<TPL:OPT_CHAT>|$opt_chat|g" -i /var/www/piratebox/config.php
  75. # Fix confs
  76. ## nginx
  77. sudo sed "s|<TPL:DOMAIN>|${domain}|g" -i /etc/nginx/conf.d/captive-piratebox.conf
  78. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/nginx/conf.d/captive-piratebox.conf
  79. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/nginx/conf.d/captive-piratebox.conf
  80. ## php-fpm
  81. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  82. sudo sed 's|<TPL:PHP_USER>|www-data|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  83. sudo sed 's|<TPL:PHP_GROUP>|www-data|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  84. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  85. # Install fakedns
  86. sudo install -o root -g root -m 0755 ../conf/piratebox_fakedns /usr/local/bin/
  87. # Copy init script
  88. sudo install -o root -g root -m 0755 ../conf/init_ynh-piratebox /etc/init.d/ynh-piratebox
  89. # Update firewall
  90. sudo yunohost firewall allow --no-upnp UDP 4253
  91. sudo yunohost firewall allow --no-upnp TCP 4280
  92. # Set default inits
  93. sudo yunohost service add php5-fpm
  94. sudo yunohost service enable php5-fpm
  95. sudo service php5-fpm restart
  96. sudo service nginx reload
  97. sudo yunohost service add ynh-piratebox
  98. sudo yunohost service enable ynh-piratebox
  99. sudo service ynh-piratebox start
  100. # Update SSO
  101. sudo yunohost app setting piratebox skipped_uris -v /
  102. sudo yunohost app ssowatconf
  103. exit 0