From d42d897ca7b09fb133a5de561aaf5fa3d0c49530 Mon Sep 17 00:00:00 2001 From: David Personette Date: Mon, 23 Oct 2017 07:15:10 -0400 Subject: [PATCH] Dockerfile / samba.sh cleanup --- Dockerfile | 60 +++++++++++++++++++++++++++++------------------------- samba.sh | 6 +++--- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index f91ebff..65f40e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,35 +2,39 @@ FROM alpine MAINTAINER David Personette # Install samba -RUN apk --no-cache add bash samba shadow && \ +RUN apk --no-cache --no-progress add bash samba shadow && \ adduser -D -G users -H -g 'Samba User' -h /tmp smbuser && \ - sed -i 's|^\( log file = \).*|\1/dev/stdout|' /etc/samba/smb.conf && \ - sed -i 's|^\( load printers = \).*|\1no|' /etc/samba/smb.conf && \ - sed -i 's|^\( printcap name = \).*|\1/dev/null|' /etc/samba/smb.conf && \ - sed -i 's|^;*\( printing = \).*|\1bsd|' /etc/samba/smb.conf && \ - sed -i 's|^\( unix password sync = \).*|\1no|' /etc/samba/smb.conf && \ - sed -i '/Share Definitions/,$d' /etc/samba/smb.conf && \ - echo ' pam password change = yes' >>/etc/samba/smb.conf && \ - echo ' map to guest = bad user' >>/etc/samba/smb.conf && \ - echo ' usershare allow guests = yes' >>/etc/samba/smb.conf && \ - echo ' create mask = 0664' >>/etc/samba/smb.conf && \ - echo ' force create mode = 0664' >>/etc/samba/smb.conf && \ - echo ' directory mask = 0775' >>/etc/samba/smb.conf && \ - echo ' force directory mode = 0775' >>/etc/samba/smb.conf && \ - echo ' force user = smbuser' >>/etc/samba/smb.conf && \ - echo ' force group = users' >>/etc/samba/smb.conf && \ - echo ' follow symlinks = yes' >>/etc/samba/smb.conf && \ - echo ' load printers = no' >>/etc/samba/smb.conf && \ - echo ' printing = bsd' >>/etc/samba/smb.conf && \ - echo ' printcap name = /dev/null' >>/etc/samba/smb.conf && \ - echo ' disable spoolss = yes' >>/etc/samba/smb.conf && \ - echo ' socket options = TCP_NODELAY' >>/etc/samba/smb.conf && \ - echo ' strict locking = no' >>/etc/samba/smb.conf && \ - echo ' vfs objects = recycle' >>/etc/samba/smb.conf && \ - echo ' recycle:keeptree = yes' >>/etc/samba/smb.conf && \ - echo ' recycle:versions = yes' >>/etc/samba/smb.conf && \ - echo ' min protocol = SMB2' >>/etc/samba/smb.conf && \ - echo '' >>/etc/samba/smb.conf && \ + file="/etc/samba/smb.conf" && \ + sed -i 's|^;* *\(log file = \).*| \1/dev/stdout|' $file && \ + sed -i 's|^;* *\(load printers = \).*| \1no|' $file && \ + sed -i 's|^;* *\(printcap name = \).*| \1/dev/null|' $file && \ + sed -i 's|^;* *\(printing = \).*| \1bsd|' $file && \ + sed -i 's|^;* *\(unix password sync = \).*| \1no|' $file && \ + sed -i 's|^;* *\(preserve case = \).*| \1yes|' $file && \ + sed -i 's|^;* *\(short preserve case = \).*| \1yes|' $file && \ + sed -i 's|^;* *\(default case = \).*| \1lower|' $file && \ + sed -i '/Share Definitions/,$d' $file && \ + echo ' pam password change = yes' >>$file && \ + echo ' map to guest = bad user' >>$file && \ + echo ' usershare allow guests = yes' >>$file && \ + echo ' create mask = 0664' >>$file && \ + echo ' force create mode = 0664' >>$file && \ + echo ' directory mask = 0775' >>$file && \ + echo ' force directory mode = 0775' >>$file && \ + echo ' force user = smbuser' >>$file && \ + echo ' force group = users' >>$file && \ + echo ' follow symlinks = yes' >>$file && \ + echo ' load printers = no' >>$file && \ + echo ' printing = bsd' >>$file && \ + echo ' printcap name = /dev/null' >>$file && \ + echo ' disable spoolss = yes' >>$file && \ + echo ' socket options = TCP_NODELAY' >>$file && \ + echo ' strict locking = no' >>$file && \ + echo ' vfs objects = recycle' >>$file && \ + echo ' recycle:keeptree = yes' >>$file && \ + echo ' recycle:versions = yes' >>$file && \ + echo ' min protocol = SMB2' >>$file && \ + echo '' >>$file && \ rm -rf /tmp/* COPY samba.sh /usr/bin/ diff --git a/samba.sh b/samba.sh index f8cdd90..7c55553 100755 --- a/samba.sh +++ b/samba.sh @@ -38,10 +38,10 @@ charmap() { local chars="$1" file=/etc/samba/smb.conf # option) raw option # Return: line added to smb.conf (replaces existing line with same key) global() { local key="${1%%=*}" value="${1#*=}" file=/etc/samba/smb.conf - if grep -qE '^\s*'"$key" "$file"; then - sed -i 's|^\s*'"$key"'.*| '"$key = $value"'|' "$file" + if grep -qE '^;*\s*'"$key" "$file"; then + sed -i 's|^;*\s*'"$key"'.*| '"${key% } = ${value# }"'|' "$file" else - sed -i '/\[global\]/a \ '"$key = $value" "$file" + sed -i '/\[global\]/a \ '"${key% } = ${value# }" "$file" fi }