You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. USE_PROCD=1
  4. SMB_CONF=""
  5. BIND_IF_PARM=""
  6. NB_PARM="$(cat /proc/sys/kernel/hostname)"
  7. WG_PARM="WORKGROUP"
  8. BI_PARM=""
  9. start_service() {
  10. . /lib/functions/network.sh
  11. if [ -e /etc/ksmbd/smb.conf ] && [ -e /etc/init.d/ksmbd ] && /etc/init.d/ksmbd running; then
  12. SMB_CONF="/etc/ksmbd/smb.conf"
  13. fi
  14. [ -e /etc/samba/smb.conf ] && {
  15. if [ -e /etc/init.d/samba4 ] && /etc/init.d/samba4 running; then
  16. SMB_CONF="/etc/samba/smb.conf"
  17. elif [ -e /etc/init.d/samba ] && /etc/init.d/samba running; then
  18. SMB_CONF="/etc/samba/smb.conf"
  19. fi
  20. }
  21. [ -z "$SMB_CONF" ] && {
  22. logger -p daemon.error -t 'wsdd2' "samba36/4 or ksmbd is not running, can't start wsdd2!"
  23. exit 1
  24. }
  25. # cleanup comments
  26. local smb_conf
  27. smb_conf="$(grep '^[[:blank:]]*[^[:blank:]#;]' $SMB_CONF)"
  28. local nb_name
  29. nb_name="$(echo "$smb_conf" | grep -i 'netbios name' | awk -F'=' '{print $2}' | tr -d ' \n')"
  30. [ -n "$nb_name" ] && NB_PARM="$nb_name"
  31. # use uppercase for none mdns option
  32. local nb_option
  33. nb_option="$(echo "$smb_conf" | grep -i 'mdns name' | awk -F'=' '{print $2}' | tr -d ' \n')"
  34. [ "$nb_option" != "mdns" ] && NB_PARM="$(echo "$nb_name" | awk '{print toupper($0)}')"
  35. local wg_name
  36. wg_name="$(echo "$smb_conf" | grep -i 'workgroup' | awk -F'=' '{print $2}' | tr -d ' \n')"
  37. [ -n "$wg_name" ] && WG_PARM="$wg_name"
  38. # resolve lan interface (BUG: No multi-interface binds atm)
  39. local ifname
  40. network_get_device ifname lan
  41. local board_vendor
  42. local board_model
  43. local board_sku
  44. [ -e /tmp/sysinfo/board_name ] && {
  45. board_vendor="$(awk -F',' '{print $1}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
  46. board_sku="$(awk -F',' '{print $2}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
  47. }
  48. [ -e /tmp/sysinfo/model ] && {
  49. board_model="$(awk -F':' '{print $1}' /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
  50. }
  51. [ -n "$board_vendor" ] && [ -n "$board_model" ] && {
  52. if [ -n "$board_sku" ]; then
  53. BI_PARM="vendor:$board_vendor,model:$board_model,sku:$board_sku"
  54. else
  55. BI_PARM="vendor:$board_vendor,model:$board_model"
  56. fi
  57. }
  58. procd_open_instance
  59. procd_set_param command /usr/bin/wsdd2
  60. [ -n "$ifname" ] && procd_append_param command -i "$ifname"
  61. procd_append_param command -N "$NB_PARM"
  62. procd_append_param command -G "$WG_PARM"
  63. [ "x${BI_PARM}" = "x" ] || procd_append_param command -b "$BI_PARM"
  64. procd_set_param respawn
  65. procd_set_param file "$SMB_CONF"
  66. procd_close_instance
  67. }
  68. service_triggers() {
  69. PROCD_RELOAD_DELAY=1000
  70. procd_add_reload_trigger "dhcp" "system" "samba" "samba4" "ksmbd"
  71. }