install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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=${2}
  21. # Check domain/path availability
  22. sudo yunohost app checkurl ${domain}${url_path} -a piratebox
  23. if [ ! $? -eq 0 ]; then
  24. exit 1
  25. fi
  26. # Install packages
  27. packages='php5-fpm iptables libnet-dns-perl'
  28. export DEBIAN_FRONTEND=noninteractive
  29. sudo apt-get --assume-yes --force-yes install ${packages}
  30. if [ $? -ne 0 ]; then
  31. sudo apt-get update
  32. sudo apt-get --assume-yes --force-yes install ${packages}
  33. fi
  34. # Create web user
  35. sudo useradd -r dropcenter
  36. # Copy confs
  37. sudo install -b -o root -g root -m 0644 ../conf/nginx_piratebox.conf "/etc/nginx/conf.d/piratebox.conf"
  38. sudo install -b -o root -g root -m 0644 ../conf/nginx_dropcenter.conf "/etc/nginx/conf.d/${domain}.d/dropcenter.conf"
  39. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_dropcenter.conf /etc/php5/fpm/pool.d/dropcenter.conf
  40. # Copy web sources
  41. sudo mkdir -pm 0755 /var/www/dropcenter/
  42. sudo cp -a ../sources/* /var/www/dropcenter/
  43. sudo mkdir /var/www/dropcenter/tpl/tmp/
  44. sudo chown -R root: /var/www/dropcenter/
  45. sudo chmod -R 0644 /var/www/dropcenter/*
  46. sudo find /var/www/dropcenter/ -type d -exec chmod +x {} \;
  47. # Fix permissions
  48. sudo chown -R dropcenter: /var/www/dropcenter/tpl/tmp/
  49. sudo chown -R dropcenter: /var/www/dropcenter/uploads/
  50. # Create fixed DC user
  51. sudo tee /var/www/dropcenter/uploads/.dc/.user.dc.php > /dev/null << EOF
  52. <?php /*{"login":"pirate","avatar":"","password":"","rank":"admin","mail":"","notifMail":"off","lang":"en - English"}*/ ?>
  53. EOF
  54. sudo touch /var/www/dropcenter/uploads/avatars/pirate.jpg
  55. # Fix confs
  56. ## nginx
  57. sudo sed "s|<TPL:URL_PATH>|${url_path}|g" -i "/etc/nginx/conf.d/piratebox.conf"
  58. sudo sed "s|<TPL:DOMAIN>|${domain}|g" -i "/etc/nginx/conf.d/piratebox.conf"
  59. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/dropcenter.conf"
  60. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/dropcenter/|g' -i "/etc/nginx/conf.d/${domain}.d/dropcenter.conf"
  61. sudo sed 's|<TPL:PHP_NAME>|dropcenter|g' -i "/etc/nginx/conf.d/${domain}.d/dropcenter.conf"
  62. ## php-fpm
  63. sudo sed 's|<TPL:PHP_NAME>|dropcenter|g' -i /etc/php5/fpm/pool.d/dropcenter.conf
  64. sudo sed 's|<TPL:PHP_USER>|dropcenter|g' -i /etc/php5/fpm/pool.d/dropcenter.conf
  65. sudo sed 's|<TPL:PHP_GROUP>|dropcenter|g' -i /etc/php5/fpm/pool.d/dropcenter.conf
  66. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/dropcenter/|g' -i /etc/php5/fpm/pool.d/dropcenter.conf
  67. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  68. # Install fakedns
  69. sudo install -o root -g root -m 0755 ../conf/piratebox_fakedns /usr/local/bin/
  70. # Copy init script
  71. sudo install -o root -g root -m 0755 ../conf/init_ynh-piratebox /etc/init.d/ynh-piratebox
  72. # Update firewall
  73. sudo yunohost firewall allow --no-upnp UDP 4253
  74. sudo yunohost firewall allow --no-upnp TCP 4280
  75. # Set default inits
  76. sudo yunohost service add php5-fpm
  77. sudo yunohost service enable php5-fpm
  78. sudo service php5-fpm restart
  79. sudo service nginx reload
  80. sudo yunohost service add ynh-piratebox
  81. sudo yunohost service enable ynh-piratebox
  82. sudo service ynh-piratebox start
  83. # Update SSO
  84. sudo yunohost app setting piratebox skipped_uris -v /
  85. sudo yunohost app ssowatconf
  86. exit 0