#!/bin/sh
# <BEGIN COPYRIGHT>
# This file is part of the "Bad Penguin" GNU/Linux distribution
# Copyright (C) 1997-98-99 by Antonio GALLO
# Author of this file: Antonio GALLO aka AGX
# Home Page at ......: http://www.badpenguin.org
# Home Page at ......: http://www.linux.it/~agx/
# e-mail contact ....: mailto:agx@linux.it	mailto:agx@geocities.com
# This program is distributed under the GNU General Public License
# You are not allowed to remove the copyright notice
# <END COPYRIGHT>

# setup--postinstall, call post-install scripts
# Post-install mode his called by ~/.bash_profile
# or after 'finalize' when installing in interactive mode
# His goal is to execute any scheduled post-installation script
#19990505 - Version 1.1.0 by AGX
#19990629 - Version 1.1.3 by AGX
#19990830 - Version 1.2.0 by AGX : X-POST-INSTALL support
# 1999-11-11, Version 1.6.0 by AGX

# --------------------------------------------------------

if [ "$SETUP_MODE" = "" ]; then
    echoc RED "This script cannot be launched interactively, use setup --help"
    USCITA=100 ; exit 100
fi

[ $SETUP_VERBOSE -gt 1 ] && echo "- Entro in setup--postinstall"
POSTLOG="$SETUP_TARGETDIR/var/log/post-install.log"

POST_RAN=0
if [ "$SETUP_MODE" = "XPOST" ]; then
  POST_MASK="x-post-install"
else
  POST_MASK="post-install"
fi

for i in $PKG_SPOOL/*.${POST_MASK} ; do

  if [ -f $i ]; then

    if [ $POST_RAN -eq 0 ]; then
      echo "- Eseguo lo script $POST_MASK ..."
    fi

    POST_RAN=1
    PKGNAME=`basename $i .$POST_MASK`
    echo
    if [ "$SETUP_MODE" = "XPOST" ]; then
	echo -e "[ $PKGNAME ]--------------------------------------------- "
    else
        echo -e "[\033[0;37m\033[1;36m $PKGNAME \033[0;37m]--------------------------------------------- "
    fi
    date >> "$POSTLOG"
    echo -n "setup: Configurazione di $PKGNAME" >> $POSTLOG
    ( cd $PKG_SPOOL ; chmod 755 $i ; exec $i )
    if [ $? -eq 0 ]; then
      echo "setup: $PKGNAME e' stato configurato con successo." >> $POSTLOG
      rm -f $i
      sleep 1
    else
      echoc RED "- Errore durante la configurazione del pacchetto !"
      echo "setup: $PKGNAME ERRORE durante la configurazione del pacchetto !" >> $POSTLOG
      if [ $SETUP_RELAXED -eq 1 ]; then
        sleep 1
      else
        echo "Premi INVIO per continuare ..."
	read x
      fi
    fi

    # Se lo script persiste ed il package non c'e' rimuovilo
    if [ -f $i -a ! -d $PKG_SPOOL/$PKGNAME ]; then
      echoc YELLOW "- Il pacchetto di questo script e' stato rimosso,"
      echoc YELLOW "  non c'e' piu' motivo di eseguire questo script ..."
      echo "setup: $PKGNAME rimosso, purgo lo script $POST_MASK" >> $POSTLOG
      sleep 2
      rm -f $i
      continue
    fi
  fi
done


if [ $POST_RAN -gt 0 ]; then
  # Updating libraries, this is done only in 'interactive' mode
  [ $SETUP_VERBOSE -gt 0 ] && echo "- Configurazione delle librerie dinamiche"
  ldconfig
  echo "---------------------------------------------------------------------- "
fi

USCITA=0 ; exit 0
