install 6.3 KB

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