Update samba.sh

This commit is contained in:
Kroese 2025-10-09 18:44:11 +02:00 committed by GitHub
parent 45956f786f
commit 0da3ac29e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -114,6 +114,8 @@ addUser() {
local password="$1"
local cfg="$5"
if [[ "$groupname" != "root" && "$gid" != "0" ]]; then
# Check if the group exists, if not, create it
if ! getent group "$groupname" &>/dev/null; then
if ! groupadd -o -g "$gid" "$groupname" > /dev/null; then
@ -130,6 +132,10 @@ addUser() {
fi
fi
fi
if [[ "$username" != "root" && "$uid" != "0" ]]; then
# Check if the user already exists, if not, create it
if ! id "$username" &>/dev/null; then
if ! adduser --gid "$gid" --uid "$uid" --comment "$username" --no-create-home --disabled-login "$username"; then
@ -169,11 +175,11 @@ addUser() {
fi
fi
fi
return 0
}
SAMBA_USER="root"
SAMBA_GROUP="root"
SAMBA_CONFIG="/etc/samba/smb.conf"
{ echo "[global]"
@ -199,14 +205,10 @@ SAMBA_CONFIG="/etc/samba/smb.conf"
} > "$SAMBA_CONFIG"
# Setup user and group
if [[ "$SAMBA_UID" != "1000" || "$SAMBA_GID" != "1000" ]]; then
[[ "$SAMBA_UID" == "0" ]] && SAMBA_USER="root" || SAMBA_USER="samba"
[[ "$SAMBA_GID" == "0" ]] && SAMBA_GROUP="root" || SAMBA_GROUP="samba"
SAMBA_USER="samba"
SAMBA_GROUP="samba"
! addUser "$SAMBA_USER" "$SAMBA_UID" "$SAMBA_GROUP" "$SAMBA_GID" "$SAMBA_CONFIG" && return 0
fi
! addUser "$SAMBA_USER" "$SAMBA_UID" "$SAMBA_GROUP" "$SAMBA_GID" "$SAMBA_CONFIG" && return 0
# Add shared folders
share="/shared"