#!/bin/sh


if [ -f /etc/bacula/bacula-fd.conf ];then
cli="/etc/bacula/bacula-fd.conf"
else
cli="NOT"
fi
if [ $cli = "NOT" ];then
if [ -f /opt/etc/bacula/bacula-fd.conf ];then
cli="/opt/etc/bacula/bacula-fd.conf"
else
cli="NOT"
fi
fi

if [ -f ../../../scripts/nozen ]; then 
DIALOG=dialog
else
DIALOG=Xdialog
fi

if [  $cli = "NOT" ] ;then
$DIALOG --title "lookin for bacula-fd.conf" --msgbox "oops, couldn't find a bacula-fd.conf \n I'm afraid you'll have to locate it yourself ..." 10 60
  $DIALOG --backtitle "Where is bacula-fd.conf? " --title "(spacebar to select)" --aspect 12 --begin 4 3 --fselect / 30 60 2>tmp
 
	if [ $? = 1 ];then
        $DIALOG --title "No bacula-fd.conf" --msgbox "I AM AFRAID WE CAN'T DO ANYTHING WITHOUT A bacula-fd.conf \n \n \n THIS USB KEY WILL BE USELESS WITHOUT BACULA RUNNING ON THE CLIENT \n \n \n ABORTING !!!!!!!!!!!!!!!!!!" 600 600
        echo "aborted!!!!!!!!!!!"
        exit 1
        fi

  


 bakonf=`cat tmp`
echo $bakonf|grep bacula-fd.conf
    if [ $? = 1 ];then
    $DIALOG --title "No bacula-fd.conf" --msgbox "I AM AFRAID WE CAN'T DO ANYTHING WITHOUT A bacula-fd.conf \n \n \n THIS USB KEY WILL BE USELESS WITHOUT BACULA RUNNING ON THE CLIENT \n \n \n ABORTING !!!!!!!!!!!!!!!!!!" 600 600
    echo "aborted!!!!!!!!!!!"
    exit 1
    fi
    bakonf=`cat tmp`
    rm tmp
 cp $bakonf ../diskinfo/
fi
if [ ! $cli = "NOT" ] ;then
$DIALOG --title "lookin for bacula-fd.conf" --yesno "we found a conf file in $cli, is that correct?" 10 60 


if [ $? = 0 ];then
  bakonf=$cli
  else

  $DIALOG --backtitle "Where is bacula-fd.conf? " --title "(spacebar to select)" --aspect 12 --begin 4 3 --fselect / 30 60 2>tmp
    if [ $? = 1 ];then
    $DIALOG --title "No bacula-fd.conf" --msgbox "I AM AFRAID WE CAN'T DO ANYTHING WITHOUT A bacula-fd.conf \n \n \n THIS USB KEY WILL BE USELESS WITHOUT BACULA RUNNING ON THE CLIENT \n \n \n ABORTING !!!!!!!!!!!!!!!!!!" 600 600
    echo "aborted!!!!!!!!!!!"
    exit 1
    fi
    bakonf=`cat tmp`
    rm tmp


   fi
   echo $bakonf|grep bacula-fd.conf
	if [ ! $? = 0 ];then
        $DIALOG --title "No bacula-fd.conf" --msgbox "I AM AFRAID WE CAN'T DO ANYTHING WITHOUT A bacula-fd.conf \n \n \n THIS USB KEY WILL BE USELESS WITHOUT BACULA RUNNING ON THE CLIENT \n \n \n ABORTING !!!!!!!!!!!!!!!!!!" 600 600
        echo "aborted!!!!!!!!!!!"
        exit 1
        fi
   cp $bakonf ../diskinfo/


fi
if [ -f /etc/bacula/bconsole.conf ];then
cli="/etc/bacula/bconsole.conf"
else
cli="NOT"
fi
if [ $cli = "NOT" ];then
if [ -f /opt/etc/bacula/bconsole.conf ];then
cli="/opt/etc/bacula/bconsole.conf"
else
cli="NOT"
fi
fi

if [ $cli = "NOT" ] ;then
$DIALOG --title "bconsole" --yesno "do you have bconsole installed on this machine ?" 10 60 
  if [ $? = 0 ];then


  $DIALOG --title "lookin for bconsole.conf" --msgbox "oops, couldn't find a bconsole.conf \n I'm afraid you'll have to locate it yourself ..." 10 60
  $DIALOG --backtitle "Where is bconsole.conf? " --title "(spacebar to select)" --aspect 12 --begin 4 3 --fselect / 30 60 2>tmp
    if [ $? = 1 ];then
  $DIALOG --title "No bconsole.conf" --msgbox "O.K. We'll do without it \n but you will need to know your director's version \n when you restore" 10 60

    else
    bakonf=`cat tmp`
    rm tmp


  
    cp $bakonf ../diskinfo/
    fi
  else
  $DIALOG --title "No bconsole.conf" --msgbox "O.K. We'll do without it \n but you will need to know your director's version \n when you restore" 10 60
  fi
fi


if [ ! $cli = "NOT" ] ;then
$DIALOG --title "lookin for bconsole.conf" --yesno "we found a conf file in $cli, is that correct?" 10 60 
  if [ $? = 0 ];then
bakonf=$cli
cp $bakonf ../diskinfo/
  else

  $DIALOG --backtitle "Where is bconsole.conf? " --title "(spacebar to select)" --aspect 12 --begin 4 3 --fselect / 30 60 2>tmp
    if [ $? = 1 ];then
    $DIALOG --title "No bconsole.conf" --msgbox "O.K. We'll do without it \n but you will need to know your director's version \n when you restore" 10 60

    else
    bakonf=`cat tmp`
    rm tmp


  echo $bakonf |grep bconsole.conf
        if [ $? = 0 ];then 
        cp $bakonf ../diskinfo/
        else
	$DIALOG --title "No bconsole.conf" --msgbox "That was no bconsole.conf, \n \n O.K. We'll do without it \n but you will need to know your director's version \n when you restore" 10 60
	fi
    fi

  fi
fi
