#!/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.
#======================================================================
# ElencoAssenti
#
# Confronta la situazione attuale con l'elenco di file generato in
# precedenza e visualizza l'elenco dei file mancanti.
#======================================================================

#======================================================================
# Variabili.
#======================================================================

    #------------------------------------------------------------------
    # Il nome del file usato per accogliere l'elenco di file attuale.
    #------------------------------------------------------------------
    NUOVO_ELENCO_FILE="/tmp/ElencoAttuale.tmp"
    #------------------------------------------------------------------
    # Il nome del file contenente l'elenco generato in precedenza.
    #------------------------------------------------------------------
    ELENCO_FILE="/etc/Elenco"
    #------------------------------------------------------------------
    # Il nome del file contenente l'elenco generato in precedenza.
    #------------------------------------------------------------------
    ELENCO_FILE_MANCANTI="/tmp/ElencoFileMancanti.tmp"

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

    #------------------------------------------------------------------
    # Verifica la quantita' di argomenti.
    #------------------------------------------------------------------
    if [ $# != 0 ]
    then
        echo "Questo script non utilizza alcun argomento."
        #--------------------------------------------------------------
        # L'esecuzione dello script termina restituendo un valore
        # falso.
        #--------------------------------------------------------------
        exit 1
    fi
    #------------------------------------------------------------------
    # Salva la situazione attuale del filesystem root.
    # Sono esclusi i percorsi ``/tmp'' e ``/proc''.
    #------------------------------------------------------------------
    reset
    echo "---------------------------------------------------"
    echo "E' in corso la scansione del filesystem root per "
    echo "determinare la situazione attuale dei file esistenti."
    echo ""
    echo "Attendere prego..."
    echo "---------------------------------------------------"
    find \
/ -xdev -path "/proc" -prune -o -path "/tmp" -prune -o -print | \
sort > $NUOVO_ELENCO_FILE
    #------------------------------------------------------------------
    # Confronta i due file ed emette solo le righe del secondo elenco
    # che non appaiono nel primo.
    # Salva il risultato in un altro file temporaneo.
    #------------------------------------------------------------------
    comm -13 \
$NUOVO_ELENCO_FILE $ELENCO_FILE > $ELENCO_FILE_MANCANTI
    #------------------------------------------------------------------
    # Verifica che il file generato non sia vuoto.
    #------------------------------------------------------------------
    if [ ! -z "`cat $ELENCO_FILE_MANCANTI`" ]
    then
        #--------------------------------------------------------------
        # Ha trovato dei file mancanti.
        #--------------------------------------------------------------
        echo "Attenzione: sono scomparsi i file seguenti:"
        cat $ELENCO_FILE_MANCANTI
        read
    fi
    #------------------------------------------------------------------
    # Elimina gli elenchi temporanei.
    #------------------------------------------------------------------
    rm $NUOVO_ELENCO_FILE $ELENCO_FILE_MANCANTI

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