mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-24 11:16:51 +00:00
Merge pull request #330 from escalade/sambafix
samba: move samba-defaults into the samba-config script
This commit is contained in:
commit
1ed40a16d6
@ -189,7 +189,6 @@ makeinstall_target() {
|
||||
|
||||
post_install() {
|
||||
if [ "$SAMBA_SERVER" = "yes" ]; then
|
||||
enable_service samba-defaults.service
|
||||
enable_service nmbd.service
|
||||
enable_service smbd.service
|
||||
fi
|
||||
|
@ -21,44 +21,46 @@ SMB_USERCONF="/storage/.config/samba.conf"
|
||||
SMB_DEFCONF="/etc/samba/smb.conf"
|
||||
SMB_CONF="/run/samba/smb.conf"
|
||||
|
||||
if [ -f /storage/.cache/services/samba.conf ]; then
|
||||
. /storage/.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
|
||||
|
||||
# handle external drives
|
||||
if [ "$SAMBA_AUTOSHARE" == "true" ] ; then
|
||||
for dir in /media/* ; do
|
||||
if [ -d "$dir" ] ; then
|
||||
name=$(basename "$dir")
|
||||
echo -e "[$name]\n path = $dir\n available = yes\n browsable = yes\n public = yes\n writable = yes\n" >> $SMB_CONF
|
||||
fi
|
||||
done
|
||||
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
|
||||
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = no |' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' -i $SMB_CONF
|
||||
else
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = yes |' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = share|' -i $SMB_CONF
|
||||
fi
|
||||
if [ ! -f /storage/.cache/services/samba.conf ]; then
|
||||
/bin/cp /usr/share/services/samba.conf /storage/.cache/services
|
||||
fi
|
||||
|
||||
. /storage/.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
|
||||
|
||||
# handle external drives
|
||||
if [ "$SAMBA_AUTOSHARE" == "true" ] ; then
|
||||
for dir in /media/* ; do
|
||||
if [ -d "$dir" ] ; then
|
||||
name=$(basename "$dir")
|
||||
echo -e "[$name]\n path = $dir\n available = yes\n browsable = yes\n public = yes\n writable = yes\n" >> $SMB_CONF
|
||||
fi
|
||||
done
|
||||
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
|
||||
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = no |' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' -i $SMB_CONF
|
||||
else
|
||||
sed -e 's|^.[ \t]*.public.=.*| public = yes |' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
|
||||
sed -e 's|^.[ \t]*.security.=.*| security = share|' -i $SMB_CONF
|
||||
fi
|
||||
|
@ -1,10 +1,6 @@
|
||||
[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
|
||||
After=network.target smbd.service
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
|
@ -1,11 +0,0 @@
|
||||
[Unit]
|
||||
Description=Samba configfile writer
|
||||
After=samba-defaults.service
|
||||
Requires=samba-defaults.service
|
||||
|
||||
ConditionPathExists=/storage/.cache/services/samba.conf
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/samba/samba-config
|
||||
StartLimitInterval=0
|
@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Samba defaults
|
||||
|
||||
ConditionPathExists=!/storage/.cache/services/samba.conf
|
||||
ConditionPathExists=!/storage/.cache/services/samba.disabled
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/cp /usr/share/services/samba.conf /storage/.cache/services/
|
||||
RemainAfterExit=yes
|
@ -1,16 +1,13 @@
|
||||
[Unit]
|
||||
Description=Samba SMB Daemon
|
||||
After=network.target samba-config.service nmbd.service
|
||||
Requires=samba-config.service
|
||||
|
||||
ConditionPathExists=/storage/.cache/services/samba.conf
|
||||
ConditionPathExists=/run/samba/smb.conf
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
PIDFile=/var/run/smbd-smb.conf.pid
|
||||
LimitNOFILE=16384
|
||||
ExecStart=/usr/bin/smbd --configfile=/run/samba/smb.conf
|
||||
ExecStartPre=/usr/lib/samba/samba-config
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
TimeoutStopSec=1s
|
||||
Restart=always
|
||||
|
Loading…
x
Reference in New Issue
Block a user