mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
125 lines
2.9 KiB
Bash
Executable file
125 lines
2.9 KiB
Bash
Executable file
#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2008-2010 OpenWrt.org
|
|
|
|
START=60
|
|
USE_PROCD=1
|
|
|
|
. /lib/functions/network.sh
|
|
|
|
useradd()
|
|
{
|
|
local user
|
|
local password
|
|
config_get user $1 user
|
|
config_get password $1 password
|
|
adduser $user -s /bin/false -D -H -h /mnt/$user
|
|
/bin/smbpasswd $user $password
|
|
}
|
|
|
|
|
|
purgepasswd()
|
|
{
|
|
for us in `grep mnt /etc/passwd | cut -d":" -f1`; do
|
|
deluser $us
|
|
done
|
|
}
|
|
purgesmbpasswd()
|
|
{
|
|
rm -rf /etc/samba/smbpasswd
|
|
touch /etc/samba/smbpasswd
|
|
}
|
|
|
|
smb_header() {
|
|
local name
|
|
local workgroup
|
|
local description
|
|
local homes
|
|
local interfaces
|
|
local ifaces=""
|
|
local dev
|
|
|
|
config_get name $1 name
|
|
config_get workgroup $1 workgroup
|
|
config_get description $1 description
|
|
config_get homes $1 homes
|
|
config_get interfaces $1 interfaces
|
|
|
|
[ -z "$name" ] && name=openwrt
|
|
[ -z "$workgroup" ] && workgroup=openwrt
|
|
[ -z "$description" ] && description=openwrt
|
|
|
|
cp /etc/samba/smb.conf.template /tmp/smb.conf
|
|
[ -L /etc/samba/smb.conf ] || ln -nsf /tmp/smb.conf /etc/samba/smb.conf
|
|
sed -i "s/|NAME|/$name/g" /tmp/smb.conf
|
|
sed -i "s/|WORKGROUP|/$workgroup/g" /tmp/smb.conf
|
|
sed -i "s/|DESCRIPTION|/$description/g" /tmp/smb.conf
|
|
[ "$homes" == "1" ] && {
|
|
echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /tmp/smb.conf
|
|
}
|
|
|
|
if [ -n "$interfaces" ]; then
|
|
for ifc in $interfaces; do
|
|
network_get_device dev $ifc
|
|
ifaces="$ifaces $dev"
|
|
done
|
|
sed -i "s/interfaces = .*/interfaces = $ifaces/g" /tmp/smb.conf
|
|
sed -i "s/bind interfaces only = .*/bind interfaces only = yes/g" /tmp/smb.conf
|
|
else
|
|
# exit if no interface is selected; samba will not start
|
|
exit
|
|
fi
|
|
}
|
|
|
|
smb_add_share() {
|
|
local name
|
|
local path
|
|
local dirpath
|
|
local users
|
|
local read_only
|
|
local guest_ok
|
|
local create_mask
|
|
local dir_mask
|
|
|
|
config_get name $1 name
|
|
config_get path $1 path
|
|
config_get dirpath $1 dirpath
|
|
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
|
|
|
|
[ -z "$name" -o -z "$path" ] && return
|
|
|
|
echo -e "\n[$name]\n\tpath = $path$dirpath" >> /tmp/smb.conf
|
|
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /tmp/smb.conf
|
|
[ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /tmp/smb.conf
|
|
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /tmp/smb.conf
|
|
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /tmp/smb.conf
|
|
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /tmp/smb.conf
|
|
}
|
|
|
|
start_service() {
|
|
config_load samba
|
|
config_foreach useradd sambausers
|
|
config_foreach smb_header samba
|
|
config_foreach smb_add_share sambashare
|
|
service_start /bin/smbd -D
|
|
service_start /bin/nmbd -D
|
|
}
|
|
|
|
stop_service() {
|
|
service_stop /bin/smbd
|
|
service_stop /bin/nmbd
|
|
purgepasswd
|
|
purgesmbpasswd
|
|
}
|
|
|
|
reload_service() {
|
|
stop
|
|
start
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger samba network
|
|
}
|