Commit 159cdc39 authored by Marco Mariani's avatar Marco Mariani

cygwin: assing primary group to users, no special handling for grp_*

parent b443828c
#!/bin/bash
USER=$1
GROUP=$2
[ -z "$USER" ] && echo "User name is required" >&2 && exit 1
[ -z "$GROUP" ] && echo "Group name is required" >&2 && exit 2
GID=$(egrep "^$GROUP" /etc/group | cut -f3 -d':')
[ -z "$GID" ] && echo "User $USER not in passwd" >&2 && exit 3
sed -i "s/^$USER:unused:\([0-9]*\):[0-9]*:/$USER:unused:\1:$GID:/" /etc/passwd
echo "User $USER: primary group set to $GROUP"
...@@ -46,6 +46,7 @@ Source: "cygwin\opt\git\slapos.package\windows\scripts\ip"; DestDir: "{app}\cygw ...@@ -46,6 +46,7 @@ Source: "cygwin\opt\git\slapos.package\windows\scripts\ip"; DestDir: "{app}\cygw
Source: "cygwin\opt\git\slapos.package\windows\scripts\useradd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\useradd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\set_primary_group"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "cygwin\opt\git\slapos.package\windows\scripts\slapos-cron-config"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "cygwin\opt\git\slapos.package\windows\scripts\slapos-cron-config"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
......
...@@ -153,7 +153,7 @@ function add_member_to_group() ...@@ -153,7 +153,7 @@ function add_member_to_group()
{ {
local name=$1 local name=$1
local grpname=$2 local grpname=$2
net localgroup $grpname > /dev/null 2>&1 || grpname="grp_$grpname" net localgroup $grpname > /dev/null 2>&1 || grpname="$grpname"
net localgroup $grpname > /dev/null 2>&1 || return 1 net localgroup $grpname > /dev/null 2>&1 || return 1
if ! net localgroup $grpname | grep -q -e "^$name$" ; then if ! net localgroup $grpname | grep -q -e "^$name$" ; then
net localgroup $grpname $name /add net localgroup $grpname $name /add
...@@ -206,6 +206,8 @@ for grpname in ${USER_INIT_GROUP} ${USER_OTHER_GROUP} ; do ...@@ -206,6 +206,8 @@ for grpname in ${USER_INIT_GROUP} ${USER_OTHER_GROUP} ; do
(echo "Failed to add ${USER_NAME} to group $group" ; exit 1) (echo "Failed to add ${USER_NAME} to group $group" ; exit 1)
done done
set_primary_group $USER_NAME $USER_INIT_GROUP
# net user "${USER_NAME}" /delete || # net user "${USER_NAME}" /delete ||
# (echo "Failed to delete user ${USER_NAME}" ; exit 1) # (echo "Failed to delete user ${USER_NAME}" ; exit 1)
# sed -i -e "/^${USER_NAME}/d" /etc/passwd # sed -i -e "/^${USER_NAME}/d" /etc/passwd
...@@ -45,10 +45,10 @@ while getopts "Dd:g:G:p:s:r" opt ; do ...@@ -45,10 +45,10 @@ while getopts "Dd:g:G:p:s:r" opt ; do
USER_HOME=$OPTARG USER_HOME=$OPTARG
;; ;;
g) g)
USER_INIT_GROUP=grp_$OPTARG USER_INIT_GROUP=$OPTARG
;; ;;
G) G)
USER_OTHER_GROUP=grp_$OPTARG USER_OTHER_GROUP=$OPTARG
;; ;;
p) p)
USER_PASSWORD=$OPTARG USER_PASSWORD=$OPTARG
...@@ -76,4 +76,6 @@ USER_HOME=${USER_HOME:=/home/$USER_NAME} ...@@ -76,4 +76,6 @@ USER_HOME=${USER_HOME:=/home/$USER_NAME}
grep -q "^${USER_NAME}" /etc/passwd || mkpasswd | grep "^${USER_NAME}:" >> /etc/passwd grep -q "^${USER_NAME}" /etc/passwd || mkpasswd | grep "^${USER_NAME}:" >> /etc/passwd
[[ $USER_HOME == "/home/$USER_NAME" ]] || sed -i -e "s%:/home/${USER_NAME}:%:${USER_HOME}:%g" /etc/passwd [[ $USER_HOME == "/home/$USER_NAME" ]] || sed -i -e "s%:/home/${USER_NAME}:%:${USER_HOME}:%g" /etc/passwd
[[ ! "$USER_HOME" == "" ]] && [[ ! -f $USER_HOME ]] && mkdir -p $USER_HOME && chown $USER_NAME $USER_HOME [[ ! "$USER_HOME" == "" ]] && [[ ! -f $USER_HOME ]] && mkdir -p $USER_HOME && chown $USER_NAME.$USER_INIT_GROUP $USER_HOME
set_primary_group $USER_NAME $USER_INIT_GROUP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment