install 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/bash
  2. # PirateBox app for YunoHost
  3. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. # Contribute at https://github.com/labriqueinternet/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=${2}
  21. opt_domain=${3}
  22. opt_name=${4}
  23. opt_deleting=${5}
  24. opt_renaming=${6}
  25. opt_chat=${7}
  26. if [ "${opt_deleting}" == yes ]; then
  27. opt_deleting=1
  28. else
  29. opt_deleting=0
  30. fi
  31. if [ "${opt_renaming}" == yes ]; then
  32. opt_renaming=1
  33. else
  34. opt_renaming=0
  35. fi
  36. if [ "${opt_chat}" == yes ]; then
  37. opt_chat=1
  38. else
  39. opt_chat=0
  40. fi
  41. # Check domain/path availability
  42. sudo yunohost app checkurl ${domain}${url_path} -a piratebox
  43. if [ ! $? -eq 0 ]; then
  44. exit 1
  45. fi
  46. # Save arguments
  47. sudo yunohost app setting piratebox service_enabled -v 0
  48. sudo yunohost app setting piratebox opt_domain -v "${opt_domain}"
  49. sudo yunohost app setting piratebox opt_name -v "${opt_name}"
  50. sudo yunohost app setting piratebox opt_renaming -v "${opt_renaming}"
  51. sudo yunohost app setting piratebox opt_deleting -v "${opt_deleting}"
  52. sudo yunohost app setting piratebox opt_chat -v "${opt_chat}"
  53. sudo yunohost app setting piratebox wifi_device_id -v -1
  54. # Install packages
  55. packages='php5-fpm iptables libnet-dns-perl git'
  56. export DEBIAN_FRONTEND=noninteractive
  57. sudo apt-get --assume-yes --force-yes install ${packages}
  58. if [ $? -ne 0 ]; then
  59. sudo apt-get update
  60. sudo apt-get --assume-yes --force-yes install ${packages}
  61. fi
  62. # Copy confs
  63. sudo mkdir -pm 0755 /var/log/nginx/
  64. sudo mkdir -pm 0755 /var/spool/piratebox/
  65. sudo chown www-data: /var/spool/piratebox/
  66. sudo install -b -o root -g root -m 0644 ../conf/nginx_captive-piratebox.conf /etc/nginx/captive-piratebox.conf
  67. sudo install -b -o root -g root -m 0644 ../conf/nginx_piratebox.conf "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  68. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_piratebox.conf /etc/php5/fpm/pool.d/piratebox.conf
  69. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_captive-piratebox.conf /etc/php5/fpm/pool.d/captive-piratebox.conf
  70. # Copy web sources (piratebox)
  71. sudo git clone https://github.com/jvaubourg/php-piratebox.git /var/www/piratebox/
  72. sudo chown -R root: /var/www/piratebox/
  73. sudo chmod -R 0644 /var/www/piratebox/
  74. sudo find /var/www/piratebox/ -type d -exec chmod +x {} \;
  75. sudo rm -f /var/www/piratebox/config.php
  76. sudo install -b -o root -g root -m 0644 ../conf/piratebox_config.php.tpl /var/www/piratebox/config.tpl.php
  77. # Copy web sources (admin)
  78. sudo mkdir -pm 0755 /var/www/piratebox_admin/
  79. sudo cp -a ../sources/* /var/www/piratebox_admin/
  80. sudo chown -R root: /var/www/piratebox_admin/
  81. sudo chmod -R 0644 /var/www/piratebox_admin/*
  82. sudo find /var/www/piratebox_admin/ -type d -exec chmod +x {} \;
  83. # Fix permissions
  84. sudo chown -R www-data: /var/www/piratebox/public/uploads/
  85. sudo chown -R www-data: /var/www/piratebox/public/chat/
  86. # Fix php-piratebox configuration
  87. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /var/www/piratebox/config.tpl.php
  88. # Fix confs
  89. ## nginx captive portal
  90. sudo sed "s|<TPL:DOMAIN>|${opt_domain}|g" -i /etc/nginx/captive-piratebox.conf
  91. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/nginx/captive-piratebox.conf
  92. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/nginx/captive-piratebox.conf
  93. ## nginx admin
  94. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  95. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox_admin/|g' -i "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  96. sudo sed 's|<TPL:PHP_NAME>|piratebox_admin|g' -i "/etc/nginx/conf.d/${domain}.d/piratebox.conf"
  97. ## php-fpm captive portal
  98. sudo sed 's|<TPL:PHP_NAME>|piratebox|g' -i /etc/php5/fpm/pool.d/captive-piratebox.conf
  99. sudo sed 's|<TPL:PHP_USER>|www-data|g' -i /etc/php5/fpm/pool.d/captive-piratebox.conf
  100. sudo sed 's|<TPL:PHP_GROUP>|www-data|g' -i /etc/php5/fpm/pool.d/captive-piratebox.conf
  101. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox/|g' -i /etc/php5/fpm/pool.d/captive-piratebox.conf
  102. ## php-fpm admin
  103. sudo sed 's|<TPL:PHP_NAME>|piratebox_admin|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  104. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  105. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  106. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/piratebox_admin/|g' -i /etc/php5/fpm/pool.d/piratebox.conf
  107. # Fix sources
  108. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/piratebox_admin/config.php
  109. # Install fakedns
  110. sudo install -o root -g root -m 0755 ../conf/piratebox_fakedns /usr/local/bin/
  111. # Copy init script
  112. sudo install -o root -g root -m 0755 ../conf/ynh-piratebox /usr/local/bin/
  113. sudo install -o root -g root -m 0644 ../conf/ynh-piratebox.service /etc/systemd/system/
  114. # Update firewall
  115. sudo yunohost firewall allow --no-upnp UDP 4253
  116. sudo yunohost firewall allow --no-upnp TCP 4280
  117. # Set default inits
  118. sudo systemctl enable php5-fpm
  119. sudo systemctl restart php5-fpm
  120. sudo systemctl reload nginx
  121. sudo systemctl enable ynh-piratebox
  122. sudo systemctl start ynh-piratebox
  123. # Update SSO
  124. sudo yunohost app ssowatconf
  125. echo "WARNING: PirateBox is not started because you need to define an associated wifi hotspot through the web admin" >&2
  126. exit 0