#!/bin/sh
#tarea_para:todos

DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
export DEBIAN_PRIORITY=high

dpkg --configure -a
apt-get -f install

##############
apt-get -y remove --purge ocsinventory-agent
rm -Rf  /etc/ocsinventory-client
############
RUTA=`route|grep default`

if [ -z "$RUTA" ]; then
	LEASES="/var/lib/dhcp/dhclient.leases"
	if [ ! -e $LEASES ]; then
		LEASES="/var/lib/dhcp3/dhclient.leases"	
	fi	
	SERVIDOR=`grep routers $LEASES|tail -n 1|tr -s " "|cut -f 4 -d" "|cut -f 1 -d ";"`
	if [ ! -z "$SERVIDOR" ]; then
		route add default gw $SERVIDOR
	fi
fi

################
DOMINIO=`hostname -d`

if [ -z "$DOMINIO" ]; then
	DOMINIO=`grep search /etc/resolv.conf|head -n 1|tr -s " "|cut -f 2 -d" "`
fi
if [ -z "$DOMINIO" ]; then
	DOMINIO=`cut -f 2 -d. /etc/hostname`
fi
if [ -z "$DOMINIO" ]; then
	DOMINIO="SIN_DOMINIO"
fi
###############3


echo "ocsinventory-agent	ocsinventory-agent/tag	string	$DOMINIO
ocsinventory-agent	ocsinventory-agent/method	select	http
ocsinventory-agent	ocsinventory-agent/server	string	inventario.educarex.es">/tmp/selections.ocsinventory-agent

debconf-set-selections /tmp/selections.ocsinventory-agent
apt-get -yf install ocsinventory-agent

ocsinv
