#! /bin/bash
#======================================================================
# Copyright (c) 1997 Daniele Giacomini daniele@pluto.linux.it
#
# 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.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
# .AGGIUNGI
#
# Questo script esegue semplicemente un adduser e in questo senso
# pu essere eseguito solo dall'utente root.
# Questo script viene avviato automaticamente quando si effettua
# il login con il nome AGGIUNGI che non richiede password.
# Per questo, il file /etc/passwd contiene la riga seguente:
#
# AGGIUNGI::0:0:Nuovo utente:/tmp:/etc/script/.AGGIUNGI
#
# In pratica, ogni utente pu eseguire adduser facendo il
# login come utente AGGIUNGI, eventualmente attraverso ``rlogin'':
#
#   rlogin -l AGGIUNGI `hostname`
#
# Nello stesso modo si pu fare attraverso la rete da un altro
# computer:
#
#   rlogin -l AGGIUNGI <nome-del-computer>
#
#======================================================================

#======================================================================
# Inizio.
#======================================================================

    #------------------------------------------------------------------
    # Verifica la presenza del file AGGIUNGI.OK
    #------------------------------------------------------------------
    if [ -f /etc/script/data/AGGIUNGI.OK ]
    then
        #--------------------------------------------------------------
        # Il file esiste e si pu aggiungere l'utente.
        # Si inizia ottenendo il nome da utilizzare.
        #--------------------------------------------------------------
        echo "Inserisci il nome dell'utente."
        echo "Si possono utilizzare al massimo 8 caratteri."
	read
        #--------------------------------------------------------------
        # Controlla la risposta data dall'utente.
        #--------------------------------------------------------------
        if [ ${#REPLY} = 0 ]
        then
            #----------------------------------------------------------
	    # La risposta  nulla, cos interrompe l'inserimento.
            #----------------------------------------------------------
	    exit
        fi
        #--------------------------------------------------------------
        # Finalmente viene creato l'utente.
        #--------------------------------------------------------------
	NUOVO_UTENTE=$REPLY
        /usr/sbin/adduser $NUOVO_UTENTE
        #--------------------------------------------------------------
        # Viene definita la password.
        #--------------------------------------------------------------
        while [ 0 ]                                           # FOREVER
        do
            if /usr/bin/passwd $NUOVO_UTENTE
            then
                #------------------------------------------------------
                # La password  stata inserita correttamente.
                #------------------------------------------------------
                break
            else
                #------------------------------------------------------
                # Meglio ripetere l'operazione.
                #------------------------------------------------------
                continue
            fi
        done
    else
        #--------------------------------------------------------------
        # L'operazione non  consentita.
        #--------------------------------------------------------------
        echo "L'operazione richiesta non  consentita!"
    fi

#======================================================================
# Fine.
#======================================================================
