samba: clean up and rework samba-config

This commit is contained in:
Stefan Saraev 2013-08-29 12:06:25 +03:00
parent 9b2a8fbb9b
commit 61c804e42d

View File

@ -19,14 +19,12 @@
# http://www.gnu.org/copyleft/gpl.html # http://www.gnu.org/copyleft/gpl.html
################################################################################ ################################################################################
. /etc/profile
SMB_USERCONF="/storage/.config/samba.conf" SMB_USERCONF="/storage/.config/samba.conf"
SMB_DEFCONF="/etc/samba/smb.conf" SMB_DEFCONF="/etc/samba/smb.conf"
SMB_CONF="/run/samba/smb.conf" SMB_CONF="/run/samba/smb.conf"
if [ -f $CONFIG_CACHE/services/samba.conf ]; then if [ -f /storage/.cache/services/samba.conf ]; then
. $CONFIG_CACHE/services/samba.conf . /storage/.cache/services/samba.conf
mkdir -p /run/samba mkdir -p /run/samba
if [ -f $SMB_USERCONF ]; then if [ -f $SMB_USERCONF ]; then
@ -47,24 +45,12 @@ if [ -f $CONFIG_CACHE/services/samba.conf ]; then
echo -e "$SAMBA_PASSWORD\n$SAMBA_PASSWORD" | smbpasswd -s -a root >/dev/null 2>&1 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 echo -e "nobody = root\nroot = $SAMBA_USERNAME" > /var/run/samba.map
# set public = no sed -e 's|^.[ \t]*.public.=.*| public = no |' -i $SMB_CONF
sed -e 's|^.[ \t]*.public.=.*| public = no |' $SMB_CONF > $SMB_CONF.tmp && \ sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
mv $SMB_CONF.tmp $SMB_CONF sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' -i $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 else
# set public = yes sed -e 's|^.[ \t]*.public.=.*| public = yes |' -i $SMB_CONF
sed -e 's|^.[ \t]*.public.=.*| public = yes |' $SMB_CONF > $SMB_CONF.tmp && \ sed -e 's|^.[ \t]*.username map.=.*||' -i $SMB_CONF
mv $SMB_CONF.tmp $SMB_CONF sed -e 's|^.[ \t]*.security.=.*| security = share|' -i $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
fi fi