#!/bin/sh

# these ought to be overridable by environment variables or
# command-line options!
GRAB="curl -f"
GARLIST=/etc/garpkg/gar.list

PACKAGES=/tmp/list-packages.$$

cat $GARLIST | while read URL
do
$GRAB $URL/packages.txt >> $PACKAGES
done

if [ ! -s $PACKAGES ] 
then
	dialog --msgbox "Sorry, $(basename $0) could not find any available packages.  The network connection may be down, or the package servers may be unavailable or configured incorrectly." 0 0
	rm $PACKAGES
	exit 1
fi

P=$(cat $PACKAGES | sed 's/ /\\ /g' | xargs dialog --menu "(By default, these packages will be installed into memory; it is possible to exhaust the space available for this purpose.  You can install onto a disk instead by mounting a disk on /usr/local.)\n\nAvailable downloadable packages:" 0 0 0 2>&1 >/dev/tty)

if [ "$P" ]
then
	clear
	garpkg -i "$P"
else
	clear
fi

rm -f $PACKAGES
