Skip to content

Commit

Permalink
samba: create share per NC user
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Feb 13, 2018
1 parent 30a8bdd commit cac81ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
10 changes: 8 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

[v0.46.7](https://github.com/nextcloud/nextcloudpi/commit/5eba8d6) (2018-02-12) update: fix typo in check version
[v0.46.10](https://github.com/nextcloud/nextcloudpi/commit/b2c809c) (2018-02-09) samba: create share per NC user

[v0.46.6](https://github.com/nextcloud/nextcloudpi/commit/9101b0d) (2018-02-08) Update ncp-check-version
[v0.46.9](https://github.com/nextcloud/nextcloudpi/commit/19ccdb4) (2018-02-13) letsencrypt: only call update-rc.d in docker builds

[v0.46.8 ](https://github.com/nextcloud/nextcloudpi/commit/354c767) (2018-02-12) preactivate useful apps for a selfhosted instance

[v0.46.7 ](https://github.com/nextcloud/nextcloudpi/commit/5fd3cfa) (2018-02-12) update: fix typo in check version

[v0.46.6 ](https://github.com/nextcloud/nextcloudpi/commit/9101b0d) (2018-02-08) Update ncp-check-version

[v0.46.5 ](https://github.com/nextcloud/nextcloudpi/commit/69242d0) (2018-02-09) nc-backup: stronger permissions for backup file

Expand Down
52 changes: 39 additions & 13 deletions etc/nextcloudpi-config.d/samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#

ACTIVE_=no
NCUSER_=admin
USER_=ncp
PWD_=ownyourbits
DESCRIPTION="SMB/CIFS file server (for Mac/Linux/Windows)"

Expand All @@ -40,6 +38,11 @@ install()

# disable the [homes] share by default
sed -i /\[homes\]/s/homes/homes_disabled_ncp/ /etc/samba/smb.conf

cat >> /etc/samba/smb.conf <<EOF
# NextCloudPi automatically generated from here. Do not remove this comment
EOF
}

configure()
Expand All @@ -55,32 +58,55 @@ configure()
}
[ -d "$DATADIR" ] || { echo -e "data directory $DATADIR not found" ; return 1; }

local DIR="$DATADIR/$NCUSER_/files"
[ -d "$DIR" ] || { echo -e "INFO: directory $DIR does not exist."; return 1; }

# CONFIG
################################
sed -i '/\[NextCloudPi\]/,+10d' /etc/samba/smb.conf

# remove files from this line to the end
sed -i '/# NextCloudPi automatically/,/\$/d' /etc/samba/smb.conf

# restore this line
cat >> /etc/samba/smb.conf <<EOF
[NextCloudPi]
path = $DIR
writeable = yes
# NextCloudPi automatically generated from here. Do not remove this comment
EOF

# create a share per Nextcloud user
local USERS=()
while read -r path; do
USERS+=( "$( basename $( dirname "$path" ) )" )
done < <( ls -d "$DATADIR"/*/files )

for user in ${USERS[@]}; do
echo "adding SAMBA share for user $user"
local DIR="$DATADIR/$user/files"
[ -d "$DIR" ] || { echo -e "INFO: directory $DIR does not exist."; return 1; }

cat >> /etc/samba/smb.conf <<EOF
[ncp-$user]
path = $DIR
writeable = yes
; browseable = yes
valid users = $USER_
valid users = $user
force group = www-data
create mask = 0770
directory mask = 0771
force create mode = 0660
force directory mode = 0770
EOF

## create user with no login if it doesn't exist
id "$user" &>/dev/null || adduser --disabled-password --gecos "" "$user"
echo -e "$PWD_\n$PWD_" | smbpasswd -s -a $user

usermod -aG www-data $user
sudo chmod g+w $DIR
done

update-rc.d smbd defaults
update-rc.d smbd enable
service smbd start

usermod -aG www-data $USER_
echo -e "$PWD_\n$PWD_" | smbpasswd -s -a $USER_
sudo chmod g+w $DIR
echo "SMB enabled"
}

Expand Down

0 comments on commit cac81ec

Please sign in to comment.