install 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. # TODO: Replace isc-dhcp-server by dnsmasq (currently negotiating with the YunoHost team to
  35. # also replace bind9 by dnsmasq)
  36. packages='php5-fpm sipcalc hostapd radvd isc-dhcp-server iptables wireless-tools wireless-tools'
  37. sudo apt-get --assume-yes --force-yes install ${packages}
  38. if [ $? -ne 0 ]; then
  39. sudo apt-get update
  40. sudo apt-get --assume-yes --force-yes install ${packages}
  41. fi
  42. # Compute extra arguments
  43. if [ -z "${ip6_net}" ]; then
  44. ip6_net=none
  45. ip6_addr=none
  46. #else
  47. # ip6_net=$(bash ../conf/ipv6_expanded "${ip6_net}")
  48. #
  49. # if [ -z "${ip6_net}" ]; then
  50. # echo "ERROR: The IPv6 Delegated Prefix format looks bad" >&2
  51. # exit 1
  52. # fi
  53. #
  54. # ip6_addr="$(echo "${ip6_net}" | cut -d: -f1-7):42"
  55. # ip6_net=$(bash ../conf/ipv6_compressed "${ip6_net}")
  56. # ip6_addr=$(bash ../conf/ipv6_compressed "${ip6_addr}")
  57. fi
  58. wifi_device=$(sudo iwconfig 2>&1 | grep 802.11 | head -n1 | awk '{ print $1 }')
  59. wifi_n=0
  60. if [ -z "${wifi_device}" ]; then
  61. echo "ERROR: No wifi interface found" >&2
  62. exit 1
  63. fi
  64. sudo iwconfig "${wifi_device}" | grep -q 'n *ESSID'
  65. if [ $? -eq 0 ]; then
  66. wifi_n=1
  67. fi
  68. # Save arguments
  69. sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
  70. sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
  71. sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
  72. sudo yunohost app setting hotspot wifi_channel -v 6
  73. sudo yunohost app setting hotspot wifi_n -v "${wifi_n}"
  74. sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
  75. sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
  76. sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
  77. sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
  78. sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
  79. sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
  80. sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
  81. sudo yunohost app setting hotspot vpnclient -v no
  82. # Install IPv6 scripts
  83. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  84. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  85. # Copy confs
  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/radvd.conf.tpl /etc/
  88. sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf.tpl /etc/dhcp/
  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. # Set default inits
  115. # The boot order of these services are important, so they are disabled by default
  116. # and the ynh-hotspot service handles them.
  117. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  118. sudo yunohost service add isc-dhcp-server
  119. sudo yunohost service stop isc-dhcp-server
  120. sudo yunohost service disable isc-dhcp-server
  121. sudo yunohost service add radvd
  122. sudo yunohost service stop radvd
  123. sudo yunohost service disable radvd
  124. sudo yunohost service add hostapd
  125. sudo yunohost service stop hostapd
  126. sudo yunohost service disable hostapd
  127. sudo yunohost service add php5-fpm
  128. sudo yunohost service enable php5-fpm
  129. sudo service nginx reload
  130. # Remove IPv6 address set if there is a VPN installed
  131. if [ "${ip6_addr}" != none ]; then
  132. sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
  133. if [ "$?" -eq 0 ]; then
  134. sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
  135. fi
  136. fi
  137. sudo yunohost service add ynh-hotspot
  138. sudo yunohost service enable ynh-hotspot
  139. sudo service ynh-hotspot start
  140. # Update SSO for wifiadmin
  141. sudo yunohost app ssowatconf
  142. exit 0