#!/bin/sh #---------------------------------------------------------------------------- # add-group - add a group # # Creation: 2001-11-04 fm # Last Update: $Id$ # # Copyright (c) 2001-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # usage: add-group # or: add-group group gid # # 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 #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi ASK=/var/install/bin/ask MKTEMP=/usr/bin/mktemp RM=/usr/bin/rm EXPR=/usr/bin/expr GROUPADD=/usr/sbin/groupadd GETENT=/usr/bin/getent #---------------------------------------------------------------------------- # usage #---------------------------------------------------------------------------- usage() { cat <&2 fi } #---------------------------------------------------------------------------- # add group #---------------------------------------------------------------------------- add_group() { group="${1}" gid="${2}" if "${interactive}" then clrhome mecho --info "Add group" mecho fi if [ -z "${gid}" ] then oldifs=${IFS} gid=200 while read line do IFS=':' set -- ${line} if [ ${3} -gt ${gid} -a ${3} -lt 300 ] then gid=${3} fi IFS="${oldifs}" done ${_ask_tmpfile} rc=${?} read group < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} if [ ${rc} = 255 ] then exit 1 fi fi if [ -z "${group}" ] then mecho myecho --warn "No group added" do_exit 1 fi if [ "${#group}" -gt 32 ] then mecho myecho --warn "Name of group is too long" do_exit 1 fi if ${GETENT} group "${group}" >/dev/null then mecho myecho --warn "Group '${group}' already exists" do_exit 1 fi ${GROUPADD} -g "${gid}" "${group}" } #---------------------------------------------------------------------------- # main #---------------------------------------------------------------------------- main() { group='' gid='' interactive=false case ${#} in 0) interactive=true ;; 1) group="${1}" ;; 2) group="${1}" gid="${2}" ;; *) usage exit 1 ;; esac add_group ${group} ${gid} } #---------------------------------------------------------------------------- # call function main #---------------------------------------------------------------------------- main "${@}" #---------------------------------------------------------------------------- # end #----------------------------------------------------------------------------