install 4.0 KB

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