samba.init 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2012 OpenWrt.org
  3. START=60
  4. USE_PROCD=1
  5. smb_header() {
  6. config_get samba_iface $1 interface "loopback lan"
  7. # resolve interfaces
  8. local interfaces=$(
  9. . /lib/functions/network.sh
  10. local net
  11. for net in $samba_iface; do
  12. local device
  13. network_is_up $net || continue
  14. network_get_device device "$net"
  15. echo -n "${device:-$net} "
  16. done
  17. )
  18. local name workgroup description charset
  19. local hostname="$(uci_get system.@system[0].hostname)"
  20. config_get name $1 name "${hostname:-Lede}"
  21. config_get workgroup $1 workgroup "${hostname:-Lede}"
  22. config_get description $1 description "Samba on ${hostname:-Lede}"
  23. config_get charset $1 charset "UTF-8"
  24. mkdir -p /var/etc
  25. sed -e "s#|NAME|#$name#g" \
  26. -e "s#|WORKGROUP|#$workgroup#g" \
  27. -e "s#|DESCRIPTION|#$description#g" \
  28. -e "s#|INTERFACES|#$interfaces#g" \
  29. -e "s#|CHARSET|#$charset#g" \
  30. /etc/samba/smb.conf.template > /var/etc/smb.conf
  31. local homes
  32. config_get_bool homes $1 homes 0
  33. [ $homes -gt 0 ] && {
  34. cat <<EOT >> /var/etc/smb.conf
  35. [homes]
  36. comment = Home Directories
  37. browsable = no
  38. read only = no
  39. create mode = 0750
  40. EOT
  41. }
  42. [ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
  43. }
  44. smb_add_share() {
  45. local name
  46. local path
  47. local users
  48. local read_only
  49. local guest_ok
  50. local create_mask
  51. local dir_mask
  52. local browseable
  53. config_get name $1 name
  54. config_get path $1 path
  55. config_get users $1 users
  56. config_get read_only $1 read_only
  57. config_get guest_ok $1 guest_ok
  58. config_get create_mask $1 create_mask
  59. config_get dir_mask $1 dir_mask
  60. config_get browseable $1 browseable
  61. [ -z "$name" -o -z "$path" ] && return
  62. echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
  63. [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
  64. [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
  65. [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
  66. [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
  67. [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
  68. [ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
  69. }
  70. init_config() {
  71. config_load samba
  72. config_foreach smb_header samba
  73. config_foreach smb_add_share sambashare
  74. }
  75. service_triggers() {
  76. procd_add_reload_trigger samba
  77. local i
  78. for i in $samba_iface; do
  79. procd_add_reload_interface_trigger $i
  80. done
  81. }
  82. start_service() {
  83. init_config
  84. procd_open_instance
  85. procd_set_param command /usr/sbin/smbd -F
  86. procd_set_param respawn
  87. procd_set_param file /var/etc/smb.conf
  88. procd_close_instance
  89. procd_open_instance
  90. procd_set_param command /usr/sbin/nmbd -F
  91. procd_set_param respawn
  92. procd_set_param file /var/etc/smb.conf
  93. procd_close_instance
  94. }