install 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # Retrieve arguments
  3. wifi_ssid=$1
  4. wifi_passphrase=$2
  5. wifi_device=$3
  6. ip6_net=$4
  7. ip6_dns0=$5
  8. ip6_dns1=$6
  9. ip4_dns0=$7
  10. ip4_dns1=$8
  11. # Check arguments
  12. # TODO
  13. # Install packages
  14. # TODO: Replace isc-dhcp-server by dnsmasq (currently negotiating with the YunoHost team to
  15. # also replace bind9 by dnsmasq)
  16. sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables
  17. # Install extra packages
  18. sudo apt-get --assume-yes --force-yes install sipcalc
  19. # Compute extra arguments
  20. ip6_expanded_net=$(sipcalc "${ip6_net}" | grep Expanded | awk '{ print $NF; }')
  21. ip6_net=$(sipcalc "${ip6_net}" | grep Compressed | awk '{ print $NF; }')
  22. ip6_addr=$(echo "$(echo "${ip6_expanded_net}" | cut -d: -f1-7):1")
  23. ip6_addr=$(sipcalc "${ip6_addr}" | grep Compressed | awk '{ print $NF; }')
  24. ip4_nat_prefix=10.0.242
  25. # Save arguments for future upgrades
  26. sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
  27. sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
  28. sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
  29. sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
  30. sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
  31. sudo yunohost app setting hotspot ip6_dns0 -v "${ip6_dns0}"
  32. sudo yunohost app setting hotspot ip6_dns1 -v "${ip6_dns1}"
  33. sudo yunohost app setting hotspot ip4_dns0 -v "${ip4_dns0}"
  34. sudo yunohost app setting hotspot ip4_dns1 -v "${ip4_dns1}"
  35. sudo yunohost app setting hotspot ip4_nat_prefix -v "${ip4_nat_prefix}"
  36. # Copy confs
  37. sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/
  38. sudo install -b -o root -g root -m 0644 ../conf/radvd.conf.tpl /etc/
  39. sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf.tpl /etc/dhcp/
  40. # Copy init script
  41. sudo install -b -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
  42. ## hostapd
  43. sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
  44. # Set default inits
  45. # The boot order of these services are important, so they are disabled by default
  46. # and the ynh-hotspot service handles them.
  47. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  48. sudo yunohost service add isc-dhcp-server
  49. sudo yunohost service stop isc-dhcp-server
  50. sudo yunohost service disable isc-dhcp-server
  51. sudo yunohost service add radvd
  52. sudo yunohost service stop radvd
  53. sudo yunohost service disable radvd
  54. sudo yunohost service add hostapd
  55. sudo yunohost service stop hostapd
  56. sudo yunohost service disable hostapd
  57. # Remove IPv6 address set if there is a VPN installed
  58. sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
  59. if [ "$?" -eq 0 ]; then
  60. sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
  61. fi
  62. # Gooo
  63. sudo yunohost service add ynh-hotspot
  64. sudo yunohost service enable ynh-hotspot
  65. sudo yunohost service start ynh-hotspot
  66. exit 0