mirror of
https://github.com/dockur/windows.git
synced 2025-10-18 22:12:31 +00:00
Update samba.sh
This commit is contained in:
parent
0822f9a168
commit
9ec2d34867
39
src/samba.sh
39
src/samba.sh
@ -96,51 +96,62 @@ addShare() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addUser() {
|
addUser() {
|
||||||
local cfg="$1"
|
|
||||||
local username="$2"
|
local username="$2"
|
||||||
local uid="$3"
|
local uid="$3"
|
||||||
local groupname="$4"
|
local groupname="$4"
|
||||||
local gid="$5"
|
local gid="$5"
|
||||||
local password="$6"
|
|
||||||
local homedir="$7"
|
|
||||||
|
|
||||||
# Check if the group exists, if not, create it
|
# Check if the group exists, if not, create it
|
||||||
if ! getent group "$groupname" &>/dev/null; then
|
if ! getent group "$groupname" &>/dev/null; then
|
||||||
groupadd -o -g "$gid" "$groupname" > /dev/null || { echo "Failed to create group $groupname"; return 1; }
|
if ! groupadd -o -g "$gid" "$groupname" > /dev/null; then
|
||||||
|
error "Failed to create group $groupname" && return 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# Check if the gid right,if not, change it
|
# Check if the gid is right, if not, change it
|
||||||
local current_gid
|
local current_gid
|
||||||
current_gid=$(getent group "$groupname" | cut -d: -f3)
|
current_gid=$(getent group "$groupname" | cut -d: -f3)
|
||||||
if [[ "$current_gid" != "$gid" ]]; then
|
if [[ "$current_gid" != "$gid" ]]; then
|
||||||
l groupmod -o -g "$gid" "$groupname" > /dev/null || { echo "Failed to update GID for group $groupname"; return 1; }
|
if ! groupmod -o -g "$gid" "$groupname" > /dev/null; then
|
||||||
|
error "Failed to update GID for group $groupname" && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the user already exists, if not, create it
|
# Check if the user already exists, if not, create it
|
||||||
if ! id "$username" &>/dev/null; then
|
if ! id "$username" &>/dev/null; then
|
||||||
adduser -S -D -s /sbin/nologin -G "$groupname" -u "$uid" -g "Samba User" "$username" || { echo "Failed to create user $username"; return 1; }
|
if ! adduser -S -D -s /sbin/nologin -G "$groupname" -u "$uid" -g "Samba User" "$username"; then
|
||||||
|
error "Failed to create user $username" && return 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# Check if the uid right,if not, change it
|
# Check if the uid is right, if not, change it
|
||||||
local current_uid
|
local current_uid
|
||||||
current_uid=$(id -u "$username")
|
current_uid=$(id -u "$username")
|
||||||
if [[ "$current_uid" != "$uid" ]]; then
|
if [[ "$current_uid" != "$uid" ]]; then
|
||||||
usermod -o -u "$uid" "$username" > /dev/null || { echo "Failed to update UID for user $username"; return 1; }
|
if ! usermod -o -u "$uid" "$username" > /dev/null; then
|
||||||
|
error "Failed to update UID for user $username" && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update user's group
|
# Update user's group
|
||||||
usermod -g "$groupname" "$username" > /dev/null || { echo "Failed to update group for user $username"; return 1; }
|
if ! usermod -g "$groupname" "$username" > /dev/null; then
|
||||||
|
echo "Failed to update group for user $username" && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SAMBA_USER="root"
|
||||||
|
SAMBA_GROUP="root"
|
||||||
|
|
||||||
# Setup user and group
|
# Setup user and group
|
||||||
if [[ "$SAMBA_UID" == "1000" && "$SAMBA_GID" == "1000" ]]; then
|
if [[ "$SAMBA_UID" != "1000" || "$SAMBA_GID" != "1000" ]]; then
|
||||||
SAMBA_USER="root"
|
|
||||||
SAMBA_GROUP="root"
|
|
||||||
else
|
|
||||||
SAMBA_USER="samba"
|
SAMBA_USER="samba"
|
||||||
SAMBA_GROUP="samba"
|
SAMBA_GROUP="samba"
|
||||||
|
|
||||||
|
! addUser "$SAMBA_USER" "$SAMBA_UID" "$SAMBA_GROUP" "$SAMBA_GID" && return 0
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{ echo "[global]"
|
{ echo "[global]"
|
||||||
|
Loading…
Reference in New Issue
Block a user