install 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # Retrieve arguments
  3. wifi_ssid=$1
  4. wifi_passphrase=$2
  5. wifi_device=$3
  6. wired_device=$4
  7. ip6_net=$5
  8. ip6_dns0=$6
  9. ip6_dns1=$7
  10. ip4_dns0=$8
  11. ip4_dns1=$9
  12. # Check arguments
  13. # TODO
  14. # Save arguments for future upgrades
  15. sudo yunohost app setting hotspot wifi_ssid -v $wifi_ssid
  16. sudo yunohost app setting hotspot wifi_passphrase -v $wifi_passphrase
  17. sudo yunohost app setting hotspot wifi_device -v $wifi_device
  18. sudo yunohost app setting hotspot wired_device -v $wired_device
  19. sudo yunohost app setting hotspot ip6_net -v $ip6_net
  20. sudo yunohost app setting hotspot ip6_dns0 -v $ip6_dns0
  21. sudo yunohost app setting hotspot ip6_dns1 -v $ip6_dns1
  22. sudo yunohost app setting hotspot ip4_dns0 -v $ip4_dns0
  23. sudo yunohost app setting hotspot ip4_dns1 -v $ip4_dns1
  24. # Install packages
  25. sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server
  26. # Install extra packages
  27. sudo apt-get --assume-yes --force-yes install sipcalc
  28. # Compute extra arguments
  29. ip6_expanded_net=$(sipcalc ${ip6_net} | grep Expanded | awk '{ print $NF; }')
  30. ip6_net=$(sipcalc ${ip6_net} | grep Compressed | awk '{ print $NF; }')
  31. ip6_addr=$(echo "$(echo ${ip6_expanded_net} | cut -d: -f1-7):42")
  32. ip6_addr=$(sipcalc ${ip6_addr} | grep Compressed | awk '{ print $NF; }')
  33. ip4_nat_prefix=10.0.242
  34. # Copy confs
  35. sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf /etc/hostapd/
  36. sudo install -b -o root -g root -m 0644 ../conf/radvd.conf /etc/
  37. sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf /etc/dhcp/
  38. # Fix confs
  39. ## hostapd
  40. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/hostapd/hostapd.conf
  41. sudo sed "s|<TPL:WIFI_SSID>|${wifi_ssid}|g" -i /etc/hostapd/hostapd.conf
  42. sudo sed "s|<TPL:WIFI_PASSPHRASE>|${wifi_passphrase}|g" -i /etc/hostapd/hostapd.conf
  43. ## radvd
  44. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/radvd.conf
  45. sudo sed "s|<TPL:IP6_NET>|${ip6_net}|g" -i /etc/radvd.conf
  46. sudo sed "s|<TPL:IP6_DNS0>|${ip6_dns0}|g" -i /etc/radvd.conf
  47. sudo sed "s|<TPL:IP6_DNS1>|${ip6_dns1}|g" -i /etc/radvd.conf
  48. ## dhcpd
  49. sudo sed "s|<TPL:IP4_DNS0>|${ip4_dns0}|g" -i /etc/dhcp/dhcpd.conf
  50. sudo sed "s|<TPL:IP4_DNS1>|${ip4_dns1}|g" -i /etc/dhcp/dhcpd.conf
  51. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/dhcp/dhcpd.conf
  52. sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/dhcp/dhcpd.conf
  53. # Copy init script
  54. sudo install -b -o root -g root -m 0755 ../conf/ynh-hotspot /etc/init.d/
  55. # Fix init script
  56. ## ynh-hostspot
  57. sudo sed "s|<TPL:IP6_ADDR>|${ip6_addr}|g" -i /etc/init.d/ynh-hotspot
  58. sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/init.d/ynh-hotspot
  59. sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/init.d/ynh-hotspot
  60. sudo sed "s|<TPL:WIRED_DEVICE>|${wired_device}|g" -i /etc/init.d/ynh-hotspot
  61. ## hostapd
  62. sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
  63. # Set default inits
  64. # The boot order of these services are important, so they are disabled by default
  65. # and the ynh-hotspot service handles them.
  66. # All services are registred by yunohost in order to prevent conflicts after the uninstall.
  67. sudo yunohost service add isc-dhcp-server
  68. sudo yunohost service stop isc-dhcp-server
  69. sudo yunohost service disable isc-dhcp-server
  70. sudo yunohost service add radvd
  71. sudo yunohost service stop radvd
  72. sudo yunohost service disable radvd
  73. sudo yunohost service add hostapd
  74. sudo yunohost service stop hostapd
  75. sudo yunohost service disable hostapd
  76. # Gooo
  77. sudo yunohost service add ynh-hotspot
  78. sudo yunohost service enable ynh-hotspot
  79. sudo yunohost service start ynh-hotspot
  80. exit 0