pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/sysutils/user_darwin This implements a subset of usera...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/8f2fd87b1eb1
branches:  trunk
changeset: 471855:8f2fd87b1eb1
user:      danw <danw%pkgsrc.org@localhost>
date:      Thu Apr 01 02:58:32 2004 +0000

description:
This implements a subset of useradd(8)/groupadd(8) functionality on
Darwin that is sufficient for pkgsrc use.

diffstat:

 sysutils/user_darwin/DESCR             |   2 +
 sysutils/user_darwin/Makefile          |  28 ++++++++++++++
 sysutils/user_darwin/PLIST             |   5 ++
 sysutils/user_darwin/files/groupadd.sh |  42 +++++++++++++++++++++
 sysutils/user_darwin/files/groupdel.sh |  17 ++++++++
 sysutils/user_darwin/files/useradd.sh  |  66 ++++++++++++++++++++++++++++++++++
 sysutils/user_darwin/files/userdel.sh  |  17 ++++++++
 7 files changed, 177 insertions(+), 0 deletions(-)

diffs (206 lines):

diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/DESCR        Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,2 @@
+This implements a subset of useradd(8)/groupadd(8) functionality on
+Darwin that is sufficient for pkgsrc use.
\ No newline at end of file
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/Makefile     Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,28 @@
+# $NetBSD: Makefile,v 1.1.1.1 2004/04/01 02:58:32 danw Exp $
+#
+
+DISTNAME=              user-20040331
+CATEGORIES=            sysutils
+MASTER_SITES=          # empty
+DISTFILES=             # empty
+
+MAINTAINER=            danw%NetBSD.org@localhost
+COMMENT=               Limited NetBSD-compatible useradd/groupadd commands
+
+ONLY_FOR_PLATFORM=     Darwin-*-*
+
+PKG_INSTALLATION_TYPES=        overwrite pkgviews
+
+NO_CHECKSUM=           yes
+NO_BUILDLINK=          yes
+NO_CONFIGURE=          yes
+NO_TOOLS=              yes
+NO_BUILD=              yes
+
+do-install:
+       ${INSTALL_SCRIPT} ${FILESDIR}/useradd.sh ${PREFIX}/sbin/useradd
+       ${INSTALL_SCRIPT} ${FILESDIR}/userdel.sh ${PREFIX}/sbin/userdel
+       ${INSTALL_SCRIPT} ${FILESDIR}/groupadd.sh ${PREFIX}/sbin/groupadd
+       ${INSTALL_SCRIPT} ${FILESDIR}/groupdel.sh ${PREFIX}/sbin/groupdel
+
+.include "../../mk/bsd.pkg.mk"
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/PLIST        Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,5 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2004/04/01 02:58:32 danw Exp $
+sbin/groupadd
+sbin/groupdel
+sbin/useradd
+sbin/userdel
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/files/groupadd.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/files/groupadd.sh    Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+while [ $# -gt 1 ]; do
+    case $1 in
+       -g) gid="$2" ;;
+       *) echo "groupadd: Unrecognized option $1" 1>&2; exit 1; ;;
+    esac
+    shift; shift
+done
+
+group="$1"
+if [ -z "$group" ]; then
+    echo "groupadd: Must specify group name" 1>&2
+    exit 1
+fi
+
+if nireport . /groups/$group gid 2>/dev/null; then
+    echo "groupadd: Group '$group' already exists" 1>&2
+    exit 1
+fi
+
+if [ -n "$gid" ]; then
+    if nireport . /groups/gid=$gid gid 2>/dev/null; then
+       echo "groupadd: GID $gid already exists" 1>&2
+       exit 1
+    fi
+else
+    # Find a good unused gid. See the comments in useradd for
+    # more details
+    gid=300
+    nireport . /groups gid | sort -n | while read used_gid; do
+       if [ $gid = $used_gid ]; then
+           gid=`expr $gid + 1`
+       fi
+    done
+fi
+
+echo "${group}:*:${gid}:" | niload group .
+if ! nireport . /groups/$group gid 2>/dev/null; then
+    echo "groupadd: Could not create group" 1>&2
+    exit 1
+fi
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/files/groupdel.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/files/groupdel.sh    Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ $# -gt 1 ]; then
+    echo "groupdel: Unrecognized option $1" 1>&2
+    exit 1
+fi
+
+group="$1"
+if [ -z "$group" ]; then
+    echo "groupdel: Must specify group" 1>&2
+    exit 1
+fi
+
+if ! niutil -destroy . /groups/$group 2>/dev/null; then
+    echo "groupdel: Could not delete group" 1>&2
+    exit 1
+fi
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/files/useradd.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/files/useradd.sh     Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+homedir="/var/empty"
+shell="/usr/bin/false"
+
+while [ $# -gt 1 ]; do
+    case $1 in
+       -c) comment="$2" ;; 
+       -d) homedir="$2" ;;
+       -g) group="$2"   ;;
+       -s) shell="$2"   ;;
+       -u) uid="$2"     ;;
+       *) echo "useradd: Unrecognized option $1" 1>&2; exit 1; ;;
+    esac
+    shift; shift
+done
+
+user="$1"
+if [ -z "$user" ]; then
+    echo "useradd: Must specify username" 1>&2
+    exit 1
+fi
+if nireport . /users/$user uid 2>/dev/null; then
+    echo "useradd: User '$user' already exists" 1>&2
+    exit 1
+fi
+
+if [ -z "$group" ]; then
+    echo "useradd: Must specify group name" 1>&2
+    exit 1
+fi
+gid=`niutil -readprop . /groups/$group gid 2>/dev/null`
+if [ -z "$gid" ]; then
+    echo "useradd: No group '$group'" 1>&2
+    exit 1
+fi
+
+if [ -n "$uid" ]; then
+    if nireport . /users/uid=$uid uid 2>/dev/null; then
+       echo "useradd: UID $uid already exists" 1>&2
+       exit 1
+    fi
+else
+    # Find an unused uid, using the gid as the default value if it's
+    # not already being used. Assuming this is a system account, not
+    # a user account, we want a UID less than 500, so OS X won't
+    # display it in the login window or the Accounts preference pane.
+    # Apple seems to be using UIDs and GIDs below (but approaching) 100,
+    # and fink uses UIDs starting with 400, so we'll use the 300s.
+
+    uid=$gid
+    if [ $uid -lt 300 ]; then
+       uid=300
+    fi
+    nireport . /users uid | sort -n | while read used_uid; do
+       if [ $uid = $used_uid ]; then
+           uid=`expr $uid + 1`
+       fi
+    done
+fi
+
+echo "${user}:*:${uid}:${gid}::0:0:${comment}:${homedir}:${shell}" | niload passwd .
+if ! nireport . /users/$user uid 2>/dev/null; then
+    echo "useradd: Could not create user" 1>&2
+    exit 1
+fi
diff -r 7892b45ea45f -r 8f2fd87b1eb1 sysutils/user_darwin/files/userdel.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/user_darwin/files/userdel.sh     Thu Apr 01 02:58:32 2004 +0000
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ $# -gt 1 ]; then
+    echo "userdel: Unrecognized option $1" 1>&2
+    exit 1
+fi
+
+user="$1"
+if [ -z "$user" ]; then
+    echo "userdel: Must specify username" 1>&2
+    exit 1
+fi
+
+if ! niutil -destroy . /users/$user 2>/dev/null; then
+    echo "userdel: Could not delete user" 1>&2
+    exit 1
+fi



Home | Main Index | Thread Index | Old Index