install 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 /etc/hostapd/
  38. sudo install -b -o root -g root -m 0644 ../conf/radvd.conf /etc/
  39. sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf /etc/dhcp/
  40. # Fix confs
  41. ## hostapd
  42. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/hostapd/hostapd.conf
  43. sudo sed "s|<TPL:WIFI_SSID>|${wifi_ssid}|g" -i /etc/hostapd/hostapd.conf
  44. sudo sed "s|<TPL:WIFI_PASSPHRASE>|${wifi_passphrase}|g" -i /etc/hostapd/hostapd.conf
  45. ## radvd
  46. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/radvd.conf
  47. sudo sed "s|<TPL:IP6_NET>|${ip6_net}|g" -i /etc/radvd.conf
  48. sudo sed "s|<TPL:IP6_DNS0>|${ip6_dns0}|g" -i /etc/radvd.conf
  49. sudo sed "s|<TPL:IP6_DNS1>|${ip6_dns1}|g" -i /etc/radvd.conf
  50. ## dhcpd
  51. sudo sed "s|<TPL:IP4_DNS0>|${ip4_dns0}|g" -i /etc/dhcp/dhcpd.conf
  52. sudo sed "s|<TPL:IP4_DNS1>|${ip4_dns1}|g" -i /etc/dhcp/dhcpd.conf
  53. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/dhcp/dhcpd.conf
  54. sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/dhcp/dhcpd.conf
  55. # Copy init script
  56. sudo install -b -o root -g root -m 0755 ../conf/ynh-hotspot /etc/init.d/
  57. # Fix init script
  58. ## ynh-hostspot
  59. sudo sed "s|<TPL:IP6_ADDR>|${ip6_addr}|g" -i /etc/init.d/ynh-hotspot
  60. sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/init.d/ynh-hotspot
  61. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/init.d/ynh-hotspot
  62. ## hostapd
  63. sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
  64. # Set default inits
  65. # The boot order of these services are important, so they are disabled by default
  66. # and the ynh-hotspot service handles them.
  67. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  68. sudo yunohost service add isc-dhcp-server
  69. sudo yunohost service stop isc-dhcp-server
  70. sudo yunohost service disable isc-dhcp-server
  71. sudo yunohost service add radvd
  72. sudo yunohost service stop radvd
  73. sudo yunohost service disable radvd
  74. sudo yunohost service add hostapd
  75. sudo yunohost service stop hostapd
  76. sudo yunohost service disable hostapd
  77. # Remove IPv6 address if vpnclient is installed because from now this one is handle by this app
  78. sudo yunohost app list -f vpnclient --json | grep -q '"installed": true'
  79. if [ "$?" -eq 0 ]; then
  80. ip a d ${ip6_addr}/128 dev tun0 &> /dev/null
  81. fi
  82. # Gooo
  83. sudo yunohost service add ynh-hotspot
  84. sudo yunohost service enable ynh-hotspot
  85. sudo yunohost service start ynh-hotspot
  86. exit 0