install 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. # Retrieve arguments
  3. domain=${1}
  4. url_path=${2}
  5. wifi_ssid=${3}
  6. wifi_passphrase=${4}
  7. ##
  8. ## These arguments are optional but YunoHost is not yet able to handle them with the web installer
  9. ## See manifest.json.options
  10. ##
  11. #
  12. #ip6_net=${5}
  13. # Check arguments
  14. if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
  15. echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
  16. exit 1
  17. fi
  18. wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
  19. if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
  20. echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
  21. exit 1
  22. fi
  23. echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
  24. if [ $? -eq 0 ]; then
  25. echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
  26. exit 1
  27. fi
  28. # Check domain/path availability
  29. sudo yunohost app checkurl ${domain}${url_path} -a hotspot
  30. if [ ! $? -eq 0 ]; then
  31. exit 1
  32. fi
  33. # Install packages
  34. packages='php5-fpm sipcalc hostapd iptables wireless-tools'
  35. sudo apt-get --assume-yes --force-yes install ${packages}
  36. if [ $? -ne 0 ]; then
  37. sudo apt-get update
  38. sudo apt-get --assume-yes --force-yes install ${packages}
  39. fi
  40. # Compute extra arguments
  41. if [ -z "${ip6_net}" ]; then
  42. ip6_net=none
  43. ip6_addr=none
  44. #else
  45. # ip6_net=$(bash ../conf/ipv6_expanded "${ip6_net}")
  46. #
  47. # if [ -z "${ip6_net}" ]; then
  48. # echo "ERROR: The IPv6 Delegated Prefix format looks bad" >&2
  49. # exit 1
  50. # fi
  51. #
  52. # ip6_addr="$(echo "${ip6_net}" | cut -d: -f1-7):42"
  53. # ip6_net=$(bash ../conf/ipv6_compressed "${ip6_net}")
  54. # ip6_addr=$(bash ../conf/ipv6_compressed "${ip6_addr}")
  55. fi
  56. wifi_device=$(sudo iwconfig 2>&1 | grep 802.11 | head -n1 | awk '{ print $1 }')
  57. wifi_n=0
  58. if [ -z "${wifi_device}" ]; then
  59. echo "ERROR: No wifi interface found" >&2
  60. exit 1
  61. fi
  62. sudo iwconfig "${wifi_device}" | grep -q 'n *ESSID'
  63. if [ $? -eq 0 ]; then
  64. wifi_n=1
  65. fi
  66. # Save arguments
  67. sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
  68. sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
  69. sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
  70. sudo yunohost app setting hotspot wifi_channel -v 6
  71. sudo yunohost app setting hotspot wifi_n -v "${wifi_n}"
  72. sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
  73. sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
  74. sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
  75. sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
  76. sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
  77. sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
  78. sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
  79. sudo yunohost app setting hotspot vpnclient -v no
  80. # Install IPv6 scripts
  81. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  82. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  83. # Copy confs
  84. sudo mkdir -pm 0755 /etc/dnsmasq.d.tpl/
  85. sudo chown root: /etc/dnsmasq.d.tpl/
  86. sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/
  87. sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.d.tpl/dhcpdv6.conf.tpl
  88. sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.d.tpl/dhcpdv4.conf.tpl
  89. sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  90. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf
  91. # Copy web sources
  92. sudo mkdir -pm 0755 /var/www/wifiadmin/
  93. sudo cp -a ../sources/* /var/www/wifiadmin/
  94. sudo chown -R root: /var/www/wifiadmin/
  95. sudo chmod -R 0644 /var/www/wifiadmin/*
  96. sudo find /var/www/wifiadmin/ -type d -exec chmod +x {} \;
  97. # Fix confs
  98. ## hostapd
  99. sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
  100. ## nginx
  101. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  102. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  103. sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
  104. ## php-fpm
  105. sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  106. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  107. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  108. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
  109. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  110. # Fix sources
  111. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
  112. # Copy init script
  113. sudo install -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
  114. # Update firewall for DHCP
  115. sudo yunohost firewall allow --no-upnp --ipv6 UDP 547
  116. sudo yunohost firewall allow --no-upnp UDP 67
  117. # Set default inits
  118. # The boot order of these services are important, so they are disabled by default
  119. # and the ynh-hotspot service handles them.
  120. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  121. sudo yunohost service add hostapd
  122. sudo yunohost service stop hostapd
  123. sudo yunohost service disable hostapd
  124. sudo yunohost service add php5-fpm
  125. sudo yunohost service enable php5-fpm
  126. sudo service nginx reload
  127. # Remove IPv6 address set if there is a VPN installed
  128. if [ "${ip6_addr}" != none ]; then
  129. sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
  130. if [ "$?" -eq 0 ]; then
  131. sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
  132. fi
  133. fi
  134. sudo yunohost service add ynh-hotspot
  135. sudo yunohost service enable ynh-hotspot
  136. sudo service ynh-hotspot start
  137. # Update SSO for wifiadmin
  138. sudo yunohost app ssowatconf
  139. exit 0