#!/bin/sh
#VectorLinux package install system vers 0.1
FTP=ftp://ibiblio.org/pub/linux/distributions/vectorlinux/veclinux-2.5/packages

locinstall() {
DIALOG=${DIALOG=Xdialog}
FILE=`$DIALOG --stdout --title "Please select the package" --fselect $HOME/ 0 0`
case $? in
0)
Xdialog --title "Package Selected" \
--yesno "Okay $FILE has been selected. Continue with package installation?" 0 0
case $? in
0)
xterm -e pkg -i $FILE
if [ $? = 0 ]; then
Xdialog --title "Package Installed" \
--msgbox "The file $FILE has been installed successfully. To check the
installation please view /var/log/packages for further details." 0 0
exit 0
else
Xdialog --title "Package install failure" \
--msgbox "The package $FILE did not install properly. Maybe a corrupted
download. Try downloading again and reinstalling." 0 0
exit 1
fi
;;
1)
exit 1
;;
255)
exit 1
;;
esac
 
;;
1)
echo "nada" ;;
255)
echo "nada" ;;
esac
}

intinstall() {
Xdialog --title "Internet Installation" \
--msgbox " You have chosen to download and install a package from the
ftp site. To continue make sure your internet connection is up.
Then hit enter and a list of available packages will
be retrieved and presented for your selection." 0 0
case $? in
0)
wget -P /tmp $FTP/pkglist.txt
Xdialog --title "File listing" \
--tailbox  /tmp/pkglist.txt 24 64 &
Xdialog --title "Select file" \
--inputbox "Please enter the name of the file you wish to install from
the display box here. Please type out the whole file name below:" 0 0 2> \
/tmp/fselect.tmp.$$
fselect=`cat /tmp/fselect.tmp.$$`
rm -f /tmp/fselect.tmp.$$
retval=$?
case $retval in
0)
echo "input string is $fselect"
killall -5 Xdialog --tailbox
Xdialog --title "Getting and installing file" \
--yesno "Okay ready to retrieve $fselect from the ftp site. Select yes to
continue or no to cancel" 0 0
if [ $? = 0 ]; then
xterm -e wget -P /tmp $FTP/$fselect
if [ $? = 0 ]; then
xterm -e pkg -i /tmp/$fselect
if [ $? = 0 ]; then
Xdialog --title "Packaged Installed" \
--msgbox "The package $fselect has been installed successfully. You can get
more details of the install by viewing /var/log/packages/$fselect. Have fun
with your new software !!" 0 0
else
exit 1
fi
fi
fi
rm -f /tmp/$fselect
rm -f /tmp/pkglist.txt
;;
255)
echo "box closed"
;;
esac
exit 0
;;
255)
echo "Escape has been pressed"
exit 1
;;
esac
}
uninstall() {
UNINSTALL=/var/log/packages
Xdialog --title "Uninstall a package" \
--yesno "This will uninstall a package already installed on your system.
To continue and get a list of the installed packages to choose for removal
click [yes], otherwise click [no] to exit." 0 0
retval=$?
case $retval in
0)
FILE=`Xdialog --stdout --title "Please select the package" --fselect $UNINSTALL/ 0 0`
Xdialog --title "Are you sure" \
--yesno "Are you sure you wish to uninstall $FILE ?
If yes then click [yes] [no] will cancel." 0 0
if [ $? = 0 ]; then
FILE=`echo $FILE | cut -f5 -d '/'`
xterm -e pkg -r $FILE
Xdialog --title "Success" \
--msgbox "The package $FILE has been successfully removed
from your system! Ya all come back soon now." 0 0

exit 0
fi
;; 
1)
echo "Box closed"
;;
255)
echo "damn they escaped"
;;
esac
}


clear
Xdialog --title "Vector Linux package System" \
--msgbox "This is the Vectorlinux package manager. It's sole purpose
in life is to install or uninstall a software package. It will install 
packages from the local system or from the VectorLinux ftp site. You can also
choose to uninstall packages as well So with the
introductions out of the way lets continue." 10 74
Xdialog --title "Location Menu" \
--radiolist "Please select the location of the package you wish to install.
Internet takes you to the Vectorlinux ftp site and you will be presented with a
list of packages to choose from. Local is a tgz package that you have already on
the local system and just need to get it installed. Uninstall is if you wish to
delete an already installed package. Please choose Local, Internet or uninstall:" 16 72 3 \
"Local"  "Install a local package" on \
"uninstall" "Remove a software package from the system" off \
"Internet"  "Get and install a package from ftp site" off 2> /tmp/location

retval=$?
choice=`cat /tmp/location`
rm -f /tmp/location
case $retval in
0)
if [ $choice = "Local" ]; then
locinstall
fi
if [ $choice = "uninstall" ]; then
uninstall
fi
if [ $choice = "Internet" ]; then
intinstall
fi
;;
1)
echo "Cancel pressed."
exit 1
;;
255)
echo "Escape pressed."
exit 1
;;
esac
