samba: add systemd support

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2013-08-06 23:44:43 +02:00
parent aca9d5192a
commit 7beaacfeff
8 changed files with 157 additions and 109 deletions

View File

@ -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
}

View File

@ -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
)&

View 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

View 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

View 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

View 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

View 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

View 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