#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/remove-user-from-additional-group - remove user from 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/remove-user$$.log #set -x #---------------------------------------------------------------------------- # remove user from group #---------------------------------------------------------------------------- remove_user_from_group () { if [ "${quietflag}" = "-quiet" ] then user=${1} rg=${2} fi if [ "${quietflag}" = "" ] then clrhome myecho -info "Remove user from 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 groups='' myecho " Additional groups of user ${user}:" myecho IFS=':' while read line do set -- ${line} g="${1}" u="${4}" IFS=',' set -- ${u} for j in ${*} do if [ ${j} = ${user} ] then myecho -std " ${g}" if [ "${groups}" = "" ] then groups="${g}" else groups="${groups} "${g} fi break fi done IFS=':' done /tmp/ask.$$ rc=${?} rg=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then exit 1 fi mecho fi if [ "${rg}" != "" ] then group_found=false for j in ${groups} do if [ ${rg} = ${j} ] then group_found=true break fi done if [ ${group_found} = true ] then g='' for j in ${groups} do if [ ${j} != ${rg} ] then if [ "${g}" = "" ] then g=${j} else g="${g},${j}" fi fi done /usr/sbin/usermod -G "${g}" ${user} else myecho -warn "additional group ${rg} 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 <