mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-30 14:16:40 +00:00
samba: add systemd support
Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
parent
aca9d5192a
commit
7beaacfeff
@ -166,23 +166,30 @@ makeinstall_target() {
|
||||
ln -sf samba_multicall $INSTALL/usr/bin/nmbd
|
||||
ln -sf samba_multicall $INSTALL/usr/bin/smbpasswd
|
||||
|
||||
mkdir -p $INSTALL/etc/samba
|
||||
cp ../codepages/lowcase.dat $INSTALL/etc/samba
|
||||
cp ../codepages/upcase.dat $INSTALL/etc/samba
|
||||
cp ../codepages/valid.dat $INSTALL/etc/samba
|
||||
|
||||
mkdir -p $INSTALL/lib/systemd/system
|
||||
cp $PKG_DIR/system.d.opt/* $INSTALL/lib/systemd/system
|
||||
|
||||
enable_service smbd-monitor.path
|
||||
enable_service nmbd.service
|
||||
enable_service smbd.service
|
||||
|
||||
mkdir -p $INSTALL/usr/lib/samba
|
||||
cp $PKG_DIR/scripts/samba-config $INSTALL/usr/lib/samba
|
||||
|
||||
if [ -f $PROJECT_DIR/$PROJECT/config/smb.conf ]; then
|
||||
mkdir -p $INSTALL/etc/samba
|
||||
cp ../codepages/lowcase.dat $INSTALL/etc/samba
|
||||
cp ../codepages/upcase.dat $INSTALL/etc/samba
|
||||
cp ../codepages/valid.dat $INSTALL/etc/samba
|
||||
cp $PROJECT_DIR/$PROJECT/config/smb.conf $INSTALL/etc/samba
|
||||
else
|
||||
mkdir -p $INSTALL/etc/samba
|
||||
cp $PKG_DIR/config/smb.conf $INSTALL/etc/samba
|
||||
mkdir -p $INSTALL/usr/config
|
||||
cp $PKG_DIR/config/smb.conf $INSTALL/usr/config/samba.conf.sample
|
||||
fi
|
||||
|
||||
mkdir -p $INSTALL/etc/init.d
|
||||
cp $PKG_DIR/scripts/52_samba $INSTALL/etc/init.d
|
||||
|
||||
if [ -f $PROJECT_DIR/$PROJECT/config/smb.conf ]; then
|
||||
mkdir -p $INSTALL/etc/samba
|
||||
cp $PROJECT_DIR/$PROJECT/config/smb.conf $INSTALL/etc/samba
|
||||
else
|
||||
mkdir -p $INSTALL/etc/samba
|
||||
cp $PKG_DIR/config/smb.conf $INSTALL/etc/samba
|
||||
mkdir -p $INSTALL/usr/config
|
||||
cp $PKG_DIR/config/smb.conf $INSTALL/usr/config/samba.conf.sample
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -1,93 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2009-2010 OpenELEC.tv
|
||||
# http://www.openelec.tv
|
||||
#
|
||||
# This Program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This Program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with OpenELEC.tv; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
|
||||
# http://www.gnu.org/copyleft/gpl.html
|
||||
################################################################################
|
||||
|
||||
# start Samba Server
|
||||
#
|
||||
# runlevels: openelec, textmode
|
||||
|
||||
(
|
||||
# can be called from openelec addon.
|
||||
# ensure that environment is sane
|
||||
. /etc/profile
|
||||
|
||||
SAMBA_ENABLED=true
|
||||
if [ -f $CONFIG_CACHE/service_samba.conf ]; then
|
||||
. $CONFIG_CACHE/service_samba.conf
|
||||
fi
|
||||
|
||||
if [ "$SAMBA_ENABLED" = "true" ]; then
|
||||
|
||||
# wait for network
|
||||
wait_for_inet_addr force
|
||||
|
||||
progress "Starting Samba server"
|
||||
|
||||
SMB_USERCONF="/storage/.config/samba.conf"
|
||||
SMB_DEFCONF="/etc/samba/smb.conf"
|
||||
SMB_CONF="/var/run/smb.conf"
|
||||
|
||||
mkdir -p /var/run
|
||||
if [ -f $SMB_USERCONF ]; then
|
||||
cp $SMB_USERCONF $SMB_CONF
|
||||
else
|
||||
cp $SMB_DEFCONF $SMB_CONF
|
||||
fi
|
||||
|
||||
# only letters & numbers permitted for username & password
|
||||
SAMBA_USERNAME=`echo $SAMBA_USERNAME | sed "s/[^a-zA-Z0-9]//g;"`
|
||||
SAMBA_PASSWORD=`echo $SAMBA_PASSWORD | sed "s/[^a-zA-Z0-9]//g;"`
|
||||
|
||||
if [ "$SAMBA_SECURE" == "true" -a ! "$SAMBA_USERNAME" == "" -a ! "$SAMBA_PASSWORD" == "" ] ; then
|
||||
# username map: first line makes sure plain root does not work all the time
|
||||
# processing continues, so if user chooses root as username, second line overrides the first
|
||||
# this is done always in case user uses passwords in userconf.
|
||||
# many thanks to viljoviitanen for this
|
||||
echo -e "$SAMBA_PASSWORD\n$SAMBA_PASSWORD" | smbpasswd -s -a root >/dev/null 2>&1
|
||||
echo -e "nobody = root\nroot = $SAMBA_USERNAME" > /var/run/samba.map
|
||||
|
||||
# set public = no
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = no |' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# remove username map (if any in userconfig)
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# set security = share, add username map
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
else
|
||||
# set public = yes
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = yes |' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# remove username map (if any in userconfig)
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# set security = share
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = share|' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
fi
|
||||
|
||||
SMB_ARG="--configfile=$SMB_CONF"
|
||||
mkdir -p /var/log/samba
|
||||
rm /var/run/smbd-smb.conf.pid &>/dev/null
|
||||
rm /var/run/nmbd-smb.conf.pid &>/dev/null
|
||||
nmbd --daemon $SMB_ARG > /dev/null 2>&1
|
||||
smbd --daemon $SMB_ARG > /dev/null 2>&1
|
||||
fi
|
||||
)&
|
70
packages/network/samba/scripts/samba-config
Executable file
70
packages/network/samba/scripts/samba-config
Executable file
@ -0,0 +1,70 @@
|
||||
#!/bin/sh
|
||||
################################################################################
|
||||
# This file is part of OpenELEC - http://www.openelec.tv
|
||||
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
|
||||
#
|
||||
# This Program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This Program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with OpenELEC.tv; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
|
||||
# http://www.gnu.org/copyleft/gpl.html
|
||||
################################################################################
|
||||
|
||||
. /etc/profile
|
||||
|
||||
SMB_USERCONF="/storage/.config/samba.conf"
|
||||
SMB_DEFCONF="/etc/samba/smb.conf"
|
||||
SMB_CONF="/run/samba/smb.conf"
|
||||
|
||||
if [ -f $CONFIG_CACHE/services/samba.conf ]; then
|
||||
. $CONFIG_CACHE/services/samba.conf
|
||||
|
||||
mkdir -p /run/samba
|
||||
if [ -f $SMB_USERCONF ]; then
|
||||
cp $SMB_USERCONF $SMB_CONF
|
||||
else
|
||||
cp $SMB_DEFCONF $SMB_CONF
|
||||
fi
|
||||
|
||||
# only letters & numbers permitted for username & password
|
||||
SAMBA_USERNAME=`echo $SAMBA_USERNAME | sed "s/[^a-zA-Z0-9]//g;"`
|
||||
SAMBA_PASSWORD=`echo $SAMBA_PASSWORD | sed "s/[^a-zA-Z0-9]//g;"`
|
||||
|
||||
if [ "$SAMBA_SECURE" == "true" -a ! "$SAMBA_USERNAME" == "" -a ! "$SAMBA_PASSWORD" == "" ] ; then
|
||||
# username map: first line makes sure plain root does not work all the time
|
||||
# processing continues, so if user chooses root as username, second line overrides the first
|
||||
# this is done always in case user uses passwords in userconf.
|
||||
# many thanks to viljoviitanen for this
|
||||
echo -e "$SAMBA_PASSWORD\n$SAMBA_PASSWORD" | smbpasswd -s -a root >/dev/null 2>&1
|
||||
echo -e "nobody = root\nroot = $SAMBA_USERNAME" > /var/run/samba.map
|
||||
|
||||
# set public = no
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = no |' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# remove username map (if any in userconfig)
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# set security = share, add username map
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
else
|
||||
# set public = yes
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = yes |' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# remove username map (if any in userconfig)
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
# set security = share
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = share|' $SMB_CONF > $SMB_CONF.tmp && \
|
||||
mv $SMB_CONF.tmp $SMB_CONF
|
||||
fi
|
||||
fi
|
16
packages/network/samba/system.d.opt/nmbd.service
Normal file
16
packages/network/samba/system.d.opt/nmbd.service
Normal file
@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=Samba NMB Daemon
|
||||
After=network.target samba-config.service
|
||||
Requires=samba-config.service
|
||||
|
||||
ConditionPathExists=/storage/.cache/services/samba.conf
|
||||
ConditionPathExists=/run/samba/smb.conf
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
PIDFile=/var/run/nmbd-smb.conf.pid
|
||||
ExecStart=/usr/bin/nmbd --configfile=/run/samba/smb.conf
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
10
packages/network/samba/system.d.opt/samba-config.service
Normal file
10
packages/network/samba/system.d.opt/samba-config.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Samba configfile writer
|
||||
After=local-fs.target
|
||||
|
||||
ConditionPathExists=/storage/.cache/services/samba.conf
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/samba/samba-config
|
||||
|
9
packages/network/samba/system.d.opt/smbd-monitor.path
Normal file
9
packages/network/samba/system.d.opt/smbd-monitor.path
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Samba configfile monitor
|
||||
|
||||
[Path]
|
||||
PathModified=/storage/.cache/services/samba.conf
|
||||
PathModified=/storage/.config/samba.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
packages/network/samba/system.d.opt/smbd-monitor.service
Normal file
12
packages/network/samba/system.d.opt/smbd-monitor.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Samba configfile monitor
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=/bin/systemctl restart samba-config.service
|
||||
ExecStartPre=/bin/systemctl restart nmbd.service
|
||||
ExecStart=/bin/systemctl restart smbd.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
17
packages/network/samba/system.d.opt/smbd.service
Normal file
17
packages/network/samba/system.d.opt/smbd.service
Normal file
@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Samba SMB Daemon
|
||||
After=network.target samba-config.service nmb.service
|
||||
Requires=samba-config.service
|
||||
|
||||
ConditionPathExists=/storage/.cache/services/samba.conf
|
||||
ConditionPathExists=/run/samba/smb.conf
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
PIDFile=/var/run/smbd-smb.conf.pid
|
||||
LimitNOFILE=16384
|
||||
ExecStart=/usr/bin/smbd --configfile=/run/samba/smb.conf
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user