install 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #wifiadmin!/bin/bash
  2. # Retrieve arguments
  3. domain=${1}
  4. url_path=${2}
  5. wifi_ssid=${3}
  6. wifi_passphrase=${4}
  7. wifi_device=${5}
  8. ip6_net=${6}
  9. # Check arguments
  10. # TODO
  11. sudo yunohost app checkurl ${domain}${url_path} -a hotspot
  12. if [ ! $? -eq 0 ]; then
  13. exit 1
  14. fi
  15. # Install packages
  16. # TODO: Replace isc-dhcp-server by dnsmasq (currently negotiating with the YunoHost team to
  17. # also replace bind9 by dnsmasq)
  18. sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables php5-fpm
  19. # Install extra packages
  20. sudo apt-get --assume-yes --force-yes install sipcalc
  21. # Compute extra arguments
  22. if [ -z "${ip6_net}" ]; then
  23. ip6_net=none
  24. ip6_addr=none
  25. else
  26. ip6_expanded_net=$(sipcalc "${ip6_net}" | grep Expanded | awk '{ print $NF; }')
  27. ip6_net=$(sipcalc "${ip6_net}" | grep Compressed | awk '{ print $NF; }')
  28. ip6_addr=$(echo "$(echo "${ip6_expanded_net}" | cut -d: -f1-7):1")
  29. ip6_addr=$(sipcalc "${ip6_addr}" | grep Compressed | awk '{ print $NF; }')
  30. fi
  31. # Save arguments
  32. sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
  33. sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
  34. sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
  35. sudo yunohost app setting hotspot wifi_channel -v 6
  36. sudo yunohost app setting hotspot wifi_n -v 0
  37. sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
  38. sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
  39. sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
  40. sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
  41. sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
  42. sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
  43. sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
  44. # Copy confs
  45. sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/
  46. sudo install -b -o root -g root -m 0644 ../conf/radvd.conf.tpl /etc/
  47. sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf.tpl /etc/dhcp/
  48. sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  49. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf
  50. # Copy web sources
  51. sudo mkdir -pm 0755 /var/www/wifiadmin/
  52. sudo cp -a ../sources/* /var/www/wifiadmin/
  53. sudo chown -R root: /var/www/wifiadmin/
  54. sudo chmod -R 0644 /var/www/wifiadmin/*
  55. sudo find /var/www/wifiadmin/ -type d -exec chmod +x {} \;
  56. # Create user for the web admin
  57. sudo useradd -MUr wifiadmin
  58. # Fix confs
  59. ## hostapd
  60. sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
  61. ## nginx
  62. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  63. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  64. sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  65. ## php-fpm
  66. sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  67. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  68. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  69. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  70. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  71. # Fix sources
  72. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
  73. # Copy init script
  74. sudo install -b -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
  75. # Set default inits
  76. # The boot order of these services are important, so they are disabled by default
  77. # and the ynh-hotspot service handles them.
  78. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  79. sudo yunohost service add isc-dhcp-server
  80. sudo yunohost service stop isc-dhcp-server
  81. sudo yunohost service disable isc-dhcp-server
  82. sudo yunohost service add radvd
  83. sudo yunohost service stop radvd
  84. sudo yunohost service disable radvd
  85. sudo yunohost service add hostapd
  86. sudo yunohost service stop hostapd
  87. sudo yunohost service disable hostapd
  88. sudo yunohost service add php5-fpm
  89. sudo yunohost service enable php5-fpm
  90. sudo yunohost service stop php5-fpm
  91. sudo yunohost service start php5-fpm
  92. sudo service nginx reload
  93. # Remove IPv6 address set if there is a VPN installed
  94. if [ "${ip6_addr}" != none ]; then
  95. sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
  96. if [ "$?" -eq 0 ]; then
  97. sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
  98. fi
  99. fi
  100. sudo yunohost service add ynh-hotspot
  101. sudo yunohost service enable ynh-hotspot
  102. sudo service ynh-hotspot start
  103. # Update SSO for wifiadmin
  104. sudo yunohost app ssowatconf
  105. exit 0