samba.init 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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:-libreCMC}"
  21. config_get workgroup $1 workgroup "${hostname:-libreCMC}"
  22. config_get description $1 description "Samba on ${hostname:-libreCMC}"
  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_APPEND=1 UCI_CONFIG_DIR=/var/run/config config_load samba
  73. config_foreach smb_header samba
  74. config_foreach smb_add_share sambashare
  75. }
  76. service_triggers() {
  77. procd_add_reload_trigger samba
  78. local i
  79. for i in $samba_iface; do
  80. procd_add_reload_interface_trigger $i
  81. done
  82. }
  83. start_service() {
  84. init_config
  85. procd_open_instance
  86. procd_add_mdns "smb" "tcp" "445"
  87. procd_set_param command /usr/sbin/smbd -F
  88. procd_set_param respawn
  89. procd_set_param file /var/etc/smb.conf
  90. procd_close_instance
  91. procd_open_instance
  92. procd_set_param command /usr/sbin/nmbd -F
  93. procd_set_param respawn
  94. procd_set_param file /var/etc/smb.conf
  95. procd_close_instance
  96. }