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.

86 lines
2.2 KiB

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