Initial commit

This commit is contained in:
domenico
2025-06-24 15:51:28 +02:00
commit 22031d9dab
6862 changed files with 1462554 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
#!/bin/sh
#
# Copyright (C) 2018 OpenWrt.org
# Copyright (C) 2018 rosysong@rosinson.com
#
. /lib/functions.sh
FLAG_DEV_TYPE=
FLAG_DEV_MOPT=
FLAG_HAS_SECT=
samba_dev_filter() { # <devname> <[path,/dev/]>
case $1 in
${2}mtdblock*|\
${2}ubi*)
FLAG_DEV_TYPE="mtd"
;;
${2}loop*|\
${2}mmcblk*|\
${2}sd*|\
${2}hd*|\
${2}md*|\
${2}nvme*|\
${2}vd*|\
${2}xvd*)
FLAG_DEV_TYPE="not-mtd"
;;
*)
[ -b ${2}${1} ] && FLAG_DEV_TYPE="not-mtd"
[ -b /dev/mapper/$1 ] && FLAG_DEV_TYPE="not-mtd"
;;
esac
}
samba_cfg_lookup() { # <section> <name>
config_get name $1 name
[ "$name" = "$2" ] || return
FLAG_HAS_SECT=y
}
samba_cfg_delete() { # <section> <name>
config_get name $1 name
[ "$name" = "$2" ] || return
uci -q delete samba.$1
}
samba_find_mount_point() { # <devname>
# search mount point in /proc/mounts
while read l; do
local d=$(echo $l | awk '/^\/dev/ {print $1}')
[ "$d" = "/dev/$1" ] || continue
FLAG_DEV_MOPT=$(echo $l | awk '/^\/dev/ {print $2}')
break
done < /proc/mounts
}
_samba_add_section() { # <devname> <mount point>
uci -q batch <<-EOF
add samba sambashare
set samba.@sambashare[-1].browseable='yes'
set samba.@sambashare[-1].name='$1'
set samba.@sambashare[-1].path='$2'
set samba.@sambashare[-1].users='root'
set samba.@sambashare[-1].read_only='no'
set samba.@sambashare[-1].guest_ok='yes'
set samba.@sambashare[-1].create_mask='0755'
set samba.@sambashare[-1].dir_mask='0755'
EOF
}
samba_add_section() { # <devname> [<mount point>]
FLAG_HAS_SECT=
FLAG_DEV_MOPT=
config_foreach samba_cfg_lookup sambashare $1
[ -z "$FLAG_HAS_SECT" ] || return
samba_find_mount_point $1
[ -n "$FLAG_DEV_MOPT" ] || return
[ -n "$2" -a "$2" = "$FLAG_DEV_MOPT" ] || \
_samba_add_section $1 $FLAG_DEV_MOPT
}
samba_delete_section() { # <devname>
config_foreach samba_cfg_delete sambashare $1
}

View File

@@ -0,0 +1,6 @@
config samba
option 'name' 'OpenWrt'
option 'workgroup' 'WORKGROUP'
option 'description' 'OpenWrt'
option 'homes' '1'

View File

@@ -0,0 +1,11 @@
. /lib/samba/samba.sh
samba_dev_filter $DEVNAME
[ "$FLAG_DEV_TYPE" = "not-mtd" ] || exit
config_load samba
case $ACTION in
add) samba_add_section $DEVNAME;;
remove) samba_delete_section $DEVNAME;;
esac
uci commit samba

View File

@@ -0,0 +1,115 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2012 OpenWrt.org
START=60
USE_PROCD=1
smb_header() {
config_get samba_iface $1 interface "loopback lan"
# resolve interfaces
local interfaces=$(
. /lib/functions/network.sh
local net
for net in $samba_iface; do
local device
network_is_up $net || continue
network_get_device device "$net"
echo -n "${device:-$net} "
done
)
local name workgroup description charset
local hostname="$(uci_get system.@system[0].hostname)"
config_get name $1 name "${hostname:-OpenWrt}"
config_get workgroup $1 workgroup "${hostname:-OpenWrt}"
config_get description $1 description "Samba on ${hostname:-OpenWrt}"
config_get charset $1 charset "UTF-8"
mkdir -p /var/etc
sed -e "s#|NAME|#$name#g" \
-e "s#|WORKGROUP|#$workgroup#g" \
-e "s#|DESCRIPTION|#$description#g" \
-e "s#|INTERFACES|#$interfaces#g" \
-e "s#|CHARSET|#$charset#g" \
/etc/samba/smb.conf.template > /var/etc/smb.conf
local homes
config_get_bool homes $1 homes 0
[ $homes -gt 0 ] && {
cat <<EOT >> /var/etc/smb.conf
[homes]
comment = Home Directories
browsable = no
read only = no
create mode = 0750
EOT
}
[ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
}
smb_add_share() {
local name
local path
local users
local read_only
local guest_ok
local create_mask
local dir_mask
local browseable
config_get name $1 name
config_get path $1 path
config_get users $1 users
config_get read_only $1 read_only
config_get guest_ok $1 guest_ok
config_get create_mask $1 create_mask
config_get dir_mask $1 dir_mask
config_get browseable $1 browseable
[ -z "$name" -o -z "$path" ] && return
echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
[ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
[ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
}
init_config() {
config_load samba
config_foreach smb_header samba
config_foreach smb_add_share sambashare
}
service_triggers() {
procd_add_reload_trigger samba
local i
for i in $samba_iface; do
procd_add_reload_interface_trigger $i
done
}
start_service() {
init_config
procd_open_instance
procd_add_mdns "smb" "tcp" "445"
procd_set_param command /usr/sbin/smbd -F
procd_set_param respawn
procd_set_param file /var/etc/smb.conf
procd_close_instance
procd_open_instance
procd_set_param command /usr/sbin/nmbd -F
procd_set_param respawn
procd_set_param file /var/etc/smb.conf
procd_close_instance
}

View File

@@ -0,0 +1,20 @@
[global]
netbios name = |NAME|
display charset = |CHARSET|
interfaces = |INTERFACES|
server string = |DESCRIPTION|
unix charset = |CHARSET|
workgroup = |WORKGROUP|
bind interfaces only = yes
deadtime = 30
enable core files = no
invalid users = root
local master = no
map to guest = Bad User
max protocol = SMB2
min receivefile size = 16384
null passwords = yes
passdb backend = smbpasswd
security = user
smb passwd file = /etc/samba/smbpasswd
use sendfile = yes