#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/add-user-to-additional-group - add user to additional group # # Copyright (c) 2001-2005 The Eisfair Team, c/o Frank Meyer, frank(at)eisfair(dot)org # # Creation: 20.07.2003 fm # Last Update: $Id$ # # 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 clrhome mecho -info "Add user to additional group" echo tty=`tty` echo echo /var/install/bin/ask "User:" '' '*' > /tmp/ask.$$ rc=$? user=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi oldifs="$IFS" if [ "$user" != "" ] then echo 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 echo 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 mecho -warn "additional group $ag for user $user not found!" fi else mecho -warn "Command aborted" fi else mecho -warn "No additional group for $user found!" fi else mecho -warn "User $user does not exist!" fi else echo mecho -warn "Command aborted" fi echo anykey