summaryrefslogtreecommitdiff
path: root/sysutils/user_cygwin
diff options
context:
space:
mode:
authorobache <obache>2013-03-13 12:35:15 +0000
committerobache <obache>2013-03-13 12:35:15 +0000
commit0f53c39db3bd3a0dedaa73ace78658f935d035ab (patch)
tree8b38a7b37af4b8e3397344b3a36919a030ae7fbd /sysutils/user_cygwin
parent122b6ea7b248811669877f1d58656029fcabf4ee (diff)
downloadpkgsrc-0f53c39db3bd3a0dedaa73ace78658f935d035ab.tar.gz
Update user_cygwin to 20130313.
* let verbose output to stderr, so that such output is mixed to the command output (for example, using redirect). * avoid to use `flock', it is not a part of base. * useradd * add skel support * set homedir properly * avoid to try dropping from "Users" when uid=gid (pseudo group as user). * also chgrp gid for created homedir. * userdel * catch up error correctly when trying to delete Windows users.
Diffstat (limited to 'sysutils/user_cygwin')
-rw-r--r--sysutils/user_cygwin/Makefile4
-rwxr-xr-xsysutils/user_cygwin/files/groupadd.sh6
-rwxr-xr-xsysutils/user_cygwin/files/groupdel.sh4
-rwxr-xr-xsysutils/user_cygwin/files/useradd.sh49
-rwxr-xr-xsysutils/user_cygwin/files/userdel.sh6
5 files changed, 43 insertions, 26 deletions
diff --git a/sysutils/user_cygwin/Makefile b/sysutils/user_cygwin/Makefile
index eb67a8a062a..8e48790e190 100644
--- a/sysutils/user_cygwin/Makefile
+++ b/sysutils/user_cygwin/Makefile
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.3 2013/03/12 05:41:39 obache Exp $
+# $NetBSD: Makefile,v 1.4 2013/03/13 12:35:15 obache Exp $
#
-DISTNAME= user-20130312
+DISTNAME= user-20130313
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/sysutils/user_cygwin/files/groupadd.sh b/sysutils/user_cygwin/files/groupadd.sh
index 564e8aec3d9..7195edccd0a 100755
--- a/sysutils/user_cygwin/files/groupadd.sh
+++ b/sysutils/user_cygwin/files/groupadd.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# $NetBSD: groupadd.sh,v 1.2 2013/03/12 05:41:39 obache Exp $
+# $NetBSD: groupadd.sh,v 1.3 2013/03/13 12:35:16 obache Exp $
export PATH=/bin:"$(/bin/cygpath -S)"
@@ -10,7 +10,7 @@ show_usage () {
verbose=false
run_cmd () {
- if $verbose; then printf '%s\n' "+ $*"; fi
+ if $verbose; then printf '%s\n' "+ $*" >&2; fi
"$@"
}
@@ -29,4 +29,4 @@ $verbose || exec >/dev/null
run_cmd net localgroup $1 /add /comment:"Group added by Cygwin groupadd command" || exit 1
### regenerate cygwin /etc/group
-(/bin/flock -x -n 9 || exit 1; /bin/mkgroup -l -g "$1" >&9 ) 9>> /etc/group
+run_cmd /bin/mkgroup -l -g "$1" >> /etc/group || exit 1
diff --git a/sysutils/user_cygwin/files/groupdel.sh b/sysutils/user_cygwin/files/groupdel.sh
index 85c60f077ea..89649308d2e 100755
--- a/sysutils/user_cygwin/files/groupdel.sh
+++ b/sysutils/user_cygwin/files/groupdel.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# $NetBSD: groupdel.sh,v 1.2 2013/03/12 05:41:39 obache Exp $
+# $NetBSD: groupdel.sh,v 1.3 2013/03/13 12:35:16 obache Exp $
export PATH=/bin:"$(/bin/cygpath -S)"
@@ -10,7 +10,7 @@ show_usage () {
verbose=false
run_cmd () {
- if $verbose; then printf '%s\n' "+ $*"; fi
+ if $verbose; then printf '%s\n' "+ $*" >&2; fi
"$@"
}
diff --git a/sysutils/user_cygwin/files/useradd.sh b/sysutils/user_cygwin/files/useradd.sh
index 53160b13a04..b3621ef9ba2 100755
--- a/sysutils/user_cygwin/files/useradd.sh
+++ b/sysutils/user_cygwin/files/useradd.sh
@@ -1,17 +1,17 @@
#!/bin/bash
-# $NetBSD: useradd.sh,v 1.3 2013/03/12 05:41:39 obache Exp $
+# $NetBSD: useradd.sh,v 1.4 2013/03/13 12:35:16 obache Exp $
export PATH=/bin:"$(/bin/cygpath -S)"
show_usage () {
- echo "usage: $0 [-mv] [-G secondary-group] [-b base-dir] [-c comment] [-d home-dir] [-g group|=uid] user" >&2
+ echo "usage: $0 [-mv] [-G secondary-group] [-b base-dir] [-c comment] [-d home-dir] [-g group|=uid] [-k skel-dir] user" >&2
echo " $0 -D" >&2
exit 1
}
verbose=false
run_cmd () {
- if $verbose; then printf '%s\n' "+ $*"; fi
+ if $verbose; then printf '%s\n' "+ $*" >&2; fi
"$@"
}
@@ -22,10 +22,12 @@ create_homedir=false
gecos=
group=Users
home_dir=
+skel_dir=/etc/skel
user_is_group=false
show_defaults () {
printf 'base_dir\t%s\n' "$base_dir"
+ printf 'skel_dir\t%s\n' "$skel_dir"
printf 'comment\t\t%s\n' "$gecos"
printf 'group\t\t%s\n' "$group"
exit 0
@@ -42,7 +44,7 @@ while getopts 'DG:L:b:c:d:e:f:g:k:mp:or:s:u:v' f; do
e) echo "$0: expiry time not yet supported; ignoring" >&2;;
f) echo "$0: inactive time not yet supported; ignoring" >&2;;
g) group="$OPTARG";;
- k) echo "$0: skeleton files not yet supported; ignoring" >&22;;
+ k) skel_dir="$OPTARG";;
m) create_homedir=true;;
p) echo "$0: cannot set password from command line; aborting" >&2; exit 1;;
o) echo "$0: cannot reuse numeric uid of another user; aborting" >&2; exit 1;;
@@ -61,9 +63,11 @@ $verbose || exec >/dev/null
### check for existence of desired groups
if [ "$group" != "=uid" ]; then
- if ! net localgroup "${group#+}" >/dev/null 2>&1; then
+ if ! net localgroup "${group}" >/dev/null 2>&1; then
echo "$0: group '$group' does not exist" >&2; exit 1
fi
+else
+ group="$1"
fi
for g in "${extra_groups[@]}"; do
@@ -78,9 +82,12 @@ if $create_homedir && [ "$home_dir" = "" ]; then
if [ ! -d "$base_dir" ]; then
echo "$0: base dir '$base_dir' does not exist" >&2; exit 1
fi
+fi
+if [ "$home_dir" = "" ]; then
home_dir="$base_dir/$1"
fi
+home_dir_nt="$(/bin/cygpath -m "$home_dir")"
if $create_homedir && [ -d "$home_dir" ]; then
echo "$0: home dir '$home_dir' already exists; not clobbering" >&2
@@ -90,23 +97,24 @@ fi
### add the user if it same name one is not in groups
if ! net localgroup "$1" >/dev/null 2>&1; then
- run_cmd net user $1 /add /fullname:"$gecos" /comment:"User added by Cygwin useradd command" || exit 1
- (/bin/flock -x -n 9 || exit 1; /bin/mkpasswd -l -u "$1" >&9 ) 9>> /etc/passwd
+ run_cmd net user $1 /add /fullname:"$gecos" /comment:"User added by Cygwin useradd command" /homedir:"$home_dir_nt" || exit 1
+ run_cmd /bin/mkpasswd -l -u "$1" >> /etc/passwd || exit 1
else
user_is_group=true;
- (/bin/flock -x -n 9 || exit 1; /bin/mkgroup -l -g "$1" | /bin/awk -F : -v home_dir=$home_dir '{printf "%s:*:%d:%d:,%s:%s:\n",$1,$3,$3,$2,home_dir}' >&9 ) 9>> /etc/passwd
+ run_cmd /bin/mkgroup -l -g "$1" | /bin/awk -F : -v home_dir=$home_dir '{printf "%s:*:%d:%d:,%s:%s:\n",$1,$3,$3,$2,home_dir}' >> /etc/passwd || exit 1
fi
### put user in groups
if [ "${group}" != "Users" ]; then
- # "Users" added by default; remove and add the real one here:
- run_cmd net localgroup "Users" $1 /delete || exit 1
-
- # Under Windows, a user *is* a group. Do nothing if =uid is given.
- if [ "$group" != "=uid" -a "$group" != "$1" ]; then
+ # Under Windows, a user *is* a group. Do nothing if uid=group.
+ if [ "$group" != "$1" ]; then
run_cmd net localgroup "${group}" $1 /add || exit 1
fi
+ # "Users" added by default; remove and add the real one here:
+ if [ ! $user_is_group ]; then
+ run_cmd net localgroup "Users" $1 /delete || exit 1
+ fi
fi
for g in "${extra_groups[@]}"; do
@@ -123,11 +131,20 @@ if [ "$home_dir" != "" ]; then
if $create_homedir; then
run_cmd /bin/mkdir -p "$home_dir" || exit 1
- run_cmd /bin/chown "$1" "$home_dir" || exit 1
+ run_cmd /bin/chown "$1":"${group}" "$home_dir" || exit 1
run_cmd /bin/setfacl -r -m d:u:"$1":rwx,u:SYSTEM:rwx,u:Administrators:rwx "$home_dir" || exit 1
+ if cd "$skel_dir"; then
+ /bin/find . -type f | while read f; do
+ fdest=${f#.}
+ if [ ! -e "${home_dir}${fdest}" -a ! -L "${home_dir}${fdest}" ]; then
+ run_cmd /bin/install -D -p -o "$1" -g "${group}" "${f}" "${home_dir}${fdest}"
+ fi
+ done
+ unset fdest
+ else
+ echo "WARNING: Failed to cd skeltone directory $_skel_dir" >&2
+ fi
fi
-
- $user_is_group || run_cmd net user "$1" /homedir:"$home_dir_nt" || exit 1
fi
diff --git a/sysutils/user_cygwin/files/userdel.sh b/sysutils/user_cygwin/files/userdel.sh
index 6328d4bf4d9..b07b79c1bef 100755
--- a/sysutils/user_cygwin/files/userdel.sh
+++ b/sysutils/user_cygwin/files/userdel.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# $NetBSD: userdel.sh,v 1.3 2013/03/12 05:41:39 obache Exp $
+# $NetBSD: userdel.sh,v 1.4 2013/03/13 12:35:16 obache Exp $
export PATH=/bin:"$(/bin/cygpath -S)"
@@ -10,7 +10,7 @@ show_usage () {
verbose=false
run_cmd () {
- if $verbose; then printf '%s\n' "+ $*"; fi
+ if $verbose; then printf '%s\n' "+ $*" >&2; fi
"$@"
}
@@ -48,5 +48,5 @@ if $remove_home_dir; then
esac
fi
-$user_is_group || run_cmd net user $1 /delete
+$user_is_group || run_cmd net user $1 /delete || exit 1
/bin/sed -i -e "/^$1.*/d" /etc/passwd