config 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # RETRIEVE ARGUMENTS
  16. #=================================================
  17. final_path=$(ynh_app_setting_get $app final_path)
  18. #=================================================
  19. # SPECIFIC GETTERS FOR TOML SHORT KEY
  20. #=================================================
  21. get__no_antenna() {
  22. if [[ $(iw_devices) == "" ]]
  23. then
  24. echo "value: true"
  25. else
  26. echo "value: false"
  27. fi
  28. }
  29. get__status() {
  30. local service_enabled=$(ynh_app_setting_get $app service_enabled)
  31. if systemctl is-active hostapd -q
  32. then
  33. if [ $service_enabled -eq 1 ]
  34. then
  35. cat << EOF
  36. style: success
  37. ask:
  38. en: |-
  39. Your Hotspot is running :)
  40. EOF
  41. else
  42. cat << EOF
  43. style: warning
  44. ask:
  45. en: Your Hotspot is running, but it shouldn't !
  46. EOF
  47. fi
  48. elif [ $service_enabled -eq 1 ]
  49. then
  50. cat << EOF
  51. style: danger
  52. ask:
  53. en: |-
  54. Your Hotspot is down ! Here are errors logged in the last 5 minutes
  55. \`\`\`
  56. $(journalctl -u hostapd -n10 -o cat | sed 's/^/ /g')
  57. \`\`\`
  58. EOF
  59. else
  60. cat << EOF
  61. style: info
  62. ask:
  63. en: Your Hotspot is down as expected.
  64. EOF
  65. fi
  66. }
  67. get__wifi_device() {
  68. if [[ $(iw_devices) == "" ]]
  69. then
  70. echo "choices: []"
  71. else
  72. cat << EOF
  73. choices:
  74. EOF
  75. for device in $(iw_devices | sed "s/|/ /g")
  76. do
  77. echo " $device: $device"
  78. done
  79. fi
  80. echo "value: '$(ynh_app_setting_get $app wifi_device)'"
  81. }
  82. #=================================================
  83. # SPECIFIC VALIDATORS FOR TOML SHORT KEYS
  84. #=================================================
  85. validate__wifi_ssid() {
  86. if [[ -z "${wifi_ssid}" ]]
  87. then
  88. echo 'SSID required'
  89. fi
  90. }
  91. validate__wifi_passphrase() {
  92. if [[ "${wifi_secure}" == "1" ]] && [[ -z "${wifi_passphrase}" ]]
  93. then
  94. echo 'In WPA2 secure mode, you need to provide a passphrase'
  95. fi
  96. }
  97. validate__ip4_nat_prefix() {
  98. if [[ -z "${ip4_nat_prefix}" ]]
  99. then
  100. echo 'Private IPv4 nat prefix required'
  101. fi
  102. }
  103. validate__dns() {
  104. if ! echo "${dns}" | grep -q "\."
  105. then
  106. echo 'IPv4 DNS required'
  107. fi
  108. if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":"
  109. then
  110. echo 'IPv6 DNS required'
  111. fi
  112. }
  113. #=================================================
  114. # SPECIFIC SETTERS FOR TOML SHORT KEYS
  115. #=================================================
  116. #=================================================
  117. # OVERWRITING VALIDATE STEP
  118. #=================================================
  119. #=================================================
  120. # OVERWRITING APPLY STEP
  121. #=================================================
  122. ynh_app_config_apply() {
  123. # Stop vpn client
  124. ynh_print_info --message="Stopping hotspot in order to edit files"
  125. /usr/local/bin/ynh-hotspot stop
  126. _ynh_app_config_apply
  127. if [ "${wifi_secure}" -eq 1 ]; then
  128. local sec_comment=""
  129. else
  130. local sec_comment="#"
  131. fi
  132. ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf"
  133. ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpdv4-ssid-${wifi_device}.conf"
  134. if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then
  135. ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpdv6-ssid-${wifi_device}.conf"
  136. fi
  137. # Start vpn client
  138. ynh_print_info --message="Starting hotspot service if needed"
  139. /usr/local/bin/ynh-hotspot start
  140. }
  141. ynh_app_config_run $1