#!/bin/sh
#(c) Copyright Barry Kauler 2009
#This is a GUI frontend for Woof.
#121102 file DISTRO_SPECS has new variable DISTRO_DB_SUBNAME. ex: for 14.0-based slacko, DISTRO_DB_SUBNAME=slacko14
#130306 fix arch linux build.

export LANG=C

#Specifications
[ ! -f DISTRO_SPECS ] && exit

. ./DISTRO_SPECS
[ ! "$DISTRO_DB_SUBNAME" ] && DISTRO_DB_SUBNAME="$DISTRO_COMPAT_VERSION" #121102 fallback if DISTRO_DB_SUBNAME not defined in file DISTRO_SPECS.
. ./support/HISTORY_DISTRO_SPECS
. ./DISTRO_PET_REPOS
if [ -f DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #130306
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}"
else
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}"
fi

if [ -f ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then 
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
else
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} #130306
fi

rm -f /tmp/CHOSEN_PET_PKGS     #see 'Choose pkgs' tab.
rm -f /tmp/CHOSEN_COMPAT_PKGS  # "

DEFAULTTABNUM="0"

while [ 1 ]
do
 ./woof_gui_tabs $DEFAULTTABNUM > /tmp/woof_gui_tabs

. /tmp/woof_gui_tabs

 if [ "$EXIT" = "UPDATE_DS" ];then #'Specifications' tab.
. ./DISTRO_SPECS
  rm -f /tmp/CHOSEN_PET_PKGS     #see 'Choose pkgs' tab.
  rm -f /tmp/CHOSEN_COMPAT_PKGS  # "
  DEFAULTTABNUM="0"
  continue
 fi
 if [ "$EXIT" = "UPDATE_PR" ];then #'PET repos' tab.
. ./DISTRO_PET_REPOS
  DEFAULTTABNUM="1"
  continue
 fi
 if [ "$EXIT" = "UPDATE_CR" ];then #'Compat repos' tab.
  if [ -f ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #130306
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
  else
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} #130306
  fi
  DEFAULTTABNUM="2"
  continue
 fi

 if [ "$EXIT" = "UPDATE_DB" ];then #'Download dbs' tab.
  rxvt -bg yellow -title "Update databases" -e ./0setup
  DEFAULTTABNUM="3"
  continue
 fi

 if [ "$EXIT" = "UPDATE_DP" ];then #see 'Download pkgs' tab.
  DEFAULTTABNUM="5"
  continue
 fi

 break
done

