#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/add-user-to-additional-group - add user to additional group # # Creation: 2003-07-20 fm # Last Update: $Id$ # # Copyright (c) 2001-2007 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib #exec 2> /tmp/add-user$$.log #set -x #---------------------------------------------------------------------------- # add user to group #---------------------------------------------------------------------------- add_user_to_group () { if [ "${quietflag}" = "-quiet" ] then user=${1} ag=${2} fi if [ "${quietflag}" = "" ] then clrhome myecho -info "Add user to additional group" mecho tty=`tty` mecho mecho /var/install/bin/ask "User:" '' '*' > /tmp/ask.$$ rc=${?} user=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then exit 1 fi fi oldifs="${IFS}" if [ "${user}" != "" ] then myecho line=`grep "^${user}:" /etc/passwd` if [ "${line}" != "" ] then # get GID of primary group primgid=`grep "^${user}:" /etc/passwd | cut -f4 -d:` groups='' free_groups='' IFS=':' while read line do set -- ${line} g="${1}" gid="${3}" u="${4}" IFS=',' set -- ${u} group_found=false for j in ${*} do if [ ${j} = ${user} ] then group_found=true break fi done if [ ${group_found} = true ] then if [ "${groups}" = "" ] then groups="${g}" else groups="${groups} "${g} fi else # check for primgid if [ $gid != $primgid ] then if [ "${free_groups}" = "" ] then free_groups="${g}" else free_groups="${free_groups} ${g}" fi fi fi IFS=':' done /tmp/ask.$$ rc=$? ag=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi fi myecho if [ "${ag}" != "" ] then group_found=false for j in ${free_groups} do if [ ${ag} = ${j} ] then group_found=true break fi done if [ ${group_found} = true ] then g=`echo "${groups} ${ag}" | sed 's/ /,/g'` /usr/sbin/usermod -G ${g} ${user} else myecho -warn "additional group ${ag} for user ${user} not found!" fi else myecho -warn "Command aborted" fi else myecho -warn "No additional group for ${user} found!" fi else myecho -warn "User ${user} does not exist!" fi else myecho myecho -warn "Command aborted" fi if [ "${quietflag}" = "" ] then mecho anykey fi } myecho () { case ${quietflag} in -quiet) # nothing to do ;; *) mecho ${1} "${2}" ;; esac } #---------------------------------------------------------------------------- # main #---------------------------------------------------------------------------- user='' group='' quietflag='-quiet' usage () { cat <