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.

92 lines
2.6 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. # needs long delay, otherwise service may not register correctly on stratup/reboot (not sure what the issues is?)
  12. sleep 5
  13. if [ -e /etc/ksmbd/smb.conf ] && [ -e /etc/init.d/ksmbd ] && /etc/init.d/ksmbd running; then
  14. SMB_CONF="/etc/ksmbd/smb.conf"
  15. fi
  16. [ -e /etc/samba/smb.conf ] && {
  17. if [ -e /etc/init.d/samba4 ] && /etc/init.d/samba4 running; then
  18. SMB_CONF="/etc/samba/smb.conf"
  19. elif [ -e /etc/init.d/samba ] && /etc/init.d/samba running; then
  20. SMB_CONF="/etc/samba/smb.conf"
  21. fi
  22. }
  23. [ -z "$SMB_CONF" ] && {
  24. logger -p daemon.error -t 'wsdd2' "samba36/4 or ksmbd is not running, can't start wsdd2!"
  25. exit 1
  26. }
  27. # cleanup comments
  28. local smb_conf
  29. smb_conf="$(grep '^[[:blank:]]*[^[:blank:]#;]' $SMB_CONF)"
  30. local nb_name
  31. nb_name="$(echo "$smb_conf" | grep -i 'netbios name' | awk -F'=' '{print $2}' | tr -d ' \n')"
  32. [ -n "$nb_name" ] && NB_PARM="$nb_name"
  33. # use uppercase for none mdns option
  34. local nb_option
  35. nb_option="$(echo "$smb_conf" | grep -i 'mdns name' | awk -F'=' '{print $2}' | tr -d ' \n')"
  36. [ "$nb_option" != "mdns" ] && NB_PARM="$(echo "$nb_name" | awk '{print toupper($0)}')"
  37. local wg_name
  38. wg_name="$(echo "$smb_conf" | grep -i 'workgroup' | awk -F'=' '{print $2}' | tr -d ' \n')"
  39. [ -n "$wg_name" ] && WG_PARM="$wg_name"
  40. # resolve lan interface (BUG: No multi-interface binds atm)
  41. local ifname
  42. network_get_device ifname lan
  43. local board_vendor
  44. local board_model
  45. local board_sku
  46. [ -e /tmp/sysinfo/board_name ] && {
  47. board_vendor="$(awk -F',' '{print $1}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
  48. board_sku="$(awk -F',' '{print $2}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
  49. }
  50. [ -e /tmp/sysinfo/model ] && {
  51. board_model="$(awk -F':' '{print $1}' /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
  52. }
  53. [ -n "$board_vendor" ] && [ -n "$board_model" ] && {
  54. if [ -n "$board_sku" ]; then
  55. BI_PARM="vendor:$board_vendor,model:$board_model,sku:$board_sku"
  56. else
  57. BI_PARM="vendor:$board_vendor,model:$board_model"
  58. fi
  59. }
  60. procd_open_instance
  61. procd_set_param command /usr/bin/wsdd2
  62. [ -n "$ifname" ] && procd_append_param command -i "$ifname"
  63. procd_append_param command -N "$NB_PARM"
  64. procd_append_param command -G "$WG_PARM"
  65. [ "x${BI_PARM}" = "x" ] || procd_append_param command -b "$BI_PARM"
  66. procd_set_param respawn
  67. procd_set_param file "$SMB_CONF"
  68. procd_close_instance
  69. }
  70. service_triggers() {
  71. # PROCD_RELOAD_DELAY=1000
  72. procd_add_reload_trigger "dhcp" "system" "samba" "samba4" "ksmbd"
  73. }