install 5.9 KB

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