diff options
-rw-r--r-- | sysutils/user_darwin/DESCR | 2 | ||||
-rw-r--r-- | sysutils/user_darwin/Makefile | 28 | ||||
-rw-r--r-- | sysutils/user_darwin/PLIST | 5 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/groupadd.sh | 42 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/groupdel.sh | 17 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/useradd.sh | 66 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/userdel.sh | 17 |
7 files changed, 177 insertions, 0 deletions
diff --git a/sysutils/user_darwin/DESCR b/sysutils/user_darwin/DESCR new file mode 100644 index 00000000000..6c9c655c3ba --- /dev/null +++ b/sysutils/user_darwin/DESCR @@ -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 --git a/sysutils/user_darwin/Makefile b/sysutils/user_darwin/Makefile new file mode 100644 index 00000000000..850154510fb --- /dev/null +++ b/sysutils/user_darwin/Makefile @@ -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 +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 --git a/sysutils/user_darwin/PLIST b/sysutils/user_darwin/PLIST new file mode 100644 index 00000000000..cfb65be5ab1 --- /dev/null +++ b/sysutils/user_darwin/PLIST @@ -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 --git a/sysutils/user_darwin/files/groupadd.sh b/sysutils/user_darwin/files/groupadd.sh new file mode 100755 index 00000000000..f7e9d92ec61 --- /dev/null +++ b/sysutils/user_darwin/files/groupadd.sh @@ -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 --git a/sysutils/user_darwin/files/groupdel.sh b/sysutils/user_darwin/files/groupdel.sh new file mode 100755 index 00000000000..678a0c0450c --- /dev/null +++ b/sysutils/user_darwin/files/groupdel.sh @@ -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 --git a/sysutils/user_darwin/files/useradd.sh b/sysutils/user_darwin/files/useradd.sh new file mode 100755 index 00000000000..fa92ffeeb55 --- /dev/null +++ b/sysutils/user_darwin/files/useradd.sh @@ -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 --git a/sysutils/user_darwin/files/userdel.sh b/sysutils/user_darwin/files/userdel.sh new file mode 100755 index 00000000000..eed42cb0e86 --- /dev/null +++ b/sysutils/user_darwin/files/userdel.sh @@ -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 |