3 # useradd(8) wrapper for vservers
5 # Copyright (c) 2004 The Trustees of Princeton University (Trustees).
7 # $Id: vuseradd,v 1.24 2005/09/02 20:00:39 mlhuang Exp $
10 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
11 test -e "$UTIL_VSERVER_VARS" || {
12 echo "Can not find util-vserver installation; aborting..."
15 . "$UTIL_VSERVER_VARS"
24 [ "$1" == "--static" ] && { STATIC=yes; shift; }
27 # add slices group if not already present
28 groupadd slices 2>/dev/null || :
31 [ -z "$STATIC" ] && useradd -g slices -s /bin/vsh $NAME
33 # openssh-server 3.8 and above refuse login for "locked" accounts
34 for file in /etc/passwd /etc/shadow ; do
35 [ -f $file ] && sed -i -e "s/$NAME:\!\!:\(.*\)/$NAME:*:\1/" $file
40 GROUPNAME=`id -gn $NAME`
42 # create vserver configuration file
43 if [ ! -f $__CONFDIR/$NAME.conf ] ; then
45 -e "s/.*S_CONTEXT=.*/S_CONTEXT=$USERID/" \
46 -e "s/.*ONBOOT=.*/ONBOOT=yes/" \
47 < $__PKGLIBDIR/defaults/sample.conf \
48 > $__CONFDIR/$NAME.conf
51 if [ ! -d "$__DEFAULT_VSERVERDIR/$NAME" ] ; then
54 for i in "$__DEFAULT_VSERVERDIR/.vcache/"* ; do
55 [ -d "$i" ] && mv "$i" "$__DEFAULT_VSERVERDIR/$NAME" && break
58 if [ ! -d "$__DEFAULT_VSERVERDIR/$NAME" ] ; then
59 # build in temporary directory
60 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.$NAME.XXXXXX")
61 "$__PKGLIBDIR/vbuild" "$__DEFAULT_VSERVERDIR/vserver-reference" "$TMP"
63 # move it to its permanent location when complete
64 if [ $RETVAL -ne 0 ] ; then
65 echo "Error $RETVAL building $__DEFAULT_VSERVERDIR/$NAME"
66 rm -rf "$TMP" $__CONFDIR/$NAME.conf $__PKGSTATEDIR/$NAME.ctx
71 vnewsize=$(du -s "$TMP" | awk "{ print \$1 }")
72 vrefsize=$(du -s "$__DEFAULT_VSERVERDIR/vserver-reference" | awk "{ print \$1 }")
73 if [ $vnewsize -lt $vrefsize ] ; then
74 echo "WARNING: Unexpected for 'du -s $__DEFAULT_VSERVERDIR/$NAME'=$vnewsize to be less than 'du -s $__DEFAULT_VSERVERDIR/vserver-reference'=$vrefsize"
77 mv "$TMP" "$__DEFAULT_VSERVERDIR/$NAME"
82 if [ -d "$__DEFAULT_VSERVERDIR/$NAME" ] ; then
84 chmod 755 "$__DEFAULT_VSERVERDIR/$NAME"
87 $_VSERVER_LEGACY $NAME suexec root sh -c \
88 "groupadd -g $GROUPID $GROUPNAME ; useradd -u $USERID -g $GROUPID -p '' $NAME"
90 # add an unrestricted entry to /etc/sudoers file
91 if [ -f "$__DEFAULT_VSERVERDIR/$NAME/etc/sudoers" ] && \
92 ! grep -q "^$NAME" "$__DEFAULT_VSERVERDIR/$NAME/etc/sudoers" ; then
93 echo "$NAME ALL=(ALL) ALL" >> "$__DEFAULT_VSERVERDIR/$NAME/etc/sudoers"