#!/bin/sh
# VectorLinux package install system vers 5.0
# Duh, with the new package directory structure,
# the FTP list must be wrong. Somebody FIX IT please
#
# 20040820: Kocil
# - change FTP site for VL 5.0
# - change string (formerly using external tcl script
#

# return string length
function string()
{
    echo ${#1}
}

FTP=ftp://ibiblio.org/pub/linux/distributions/vectorlinux/veclinux-5.0/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)
if echo $FILE | cut -f 1 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 1 -d '/'`
fi
if echo $FILE | cut -f 2 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 2 -d '/'`
fi
if echo $FILE | cut -f 3 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 3 -d '/'`
fi
if echo $FILE | cut -f 4 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 4 -d '/'`
fi
if echo $FILE | cut -f 5 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 5 -d '/'`
fi
if echo $FILE | cut -f 6 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 6 -d '/'`
fi
if echo $FILE | cut -f 7 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 7 -d '/'`
fi
if echo $FILE | cut -f 8 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 8 -d '/'`
fi
if echo $FILE | cut -f 9 -d '/' | grep -F "tgz" ; then
FLN=`echo $FILE | cut -f 9 -d '/'`
fi

echo $FLN > file.txt
chk=`echo $FLN | sed -e "s/....$//g"`
tst1=`echo $chk | cut -f 1 -d '.'`
tst2=`ls /var/log/packages | grep -F $tst1`
tst3=`string $chk`
tst4=`string $tst2`
if ls /var/log/packages | grep -F $chk || [[ "$chk" < "$tst2" ]] || [[ $tst3 -lt $tst4 ]]; then
echo "already there or older"
Xdialog --title "Installation Failed" \
--msgbox "The package $FLN is the same or older than what is \n \
 already installed. Exiting local install." 0 0
main
else
xterm -e pkg -i $FILE
if [ $? = 0 ]; then
Xdialog --title "Package Installed" \
--msgbox "The file $FLN has been installed successfully. To check the
installation please view /var/log/packages for further details." 0 0
main
else
Xdialog --title "Package install failure" \
--msgbox "The package $FLN did not install properly. Maybe a corrupted
download. Try downloading again and reinstalling." 0 0
main
fi
fi
main
;;
1)
main
;;
255)
main
;;
esac
 
;;
1)
main
echo "nada" ;;
255)
main
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)
rm -f /tmp/pkglist.txt
wget --passive-ftp -P /tmp $FTP/pkglist.txt
PKGL=""
cat /tmp/pkglist.txt | while read LINE; do
if [ ! "$LINE" = "" ]; then
chk=`echo $LINE | sed -e "s/....$//g"`
tst1=`echo $chk | cut -f 1 -d '.'`
tst2=`ls /var/log/packages | grep -F $tst1`
tst3=`string $chk`
tst4=`string $tst2`
if ls /var/log/packages | grep -F $chk || [[ "$chk" < "$tst2" ]] || [[ $tst3 -lt $tst4 ]]; then
echo "already there or older"
else
PKGL="${PKGL} ${LINE} package off"
echo $PKGL>/tmp/pkglist.tb
fi
fi
done

rm -f /tmp/pkglist.txt

PKGLIST=`cat /tmp/pkglist.tb`

if [ "$PKGLIST" = "" ]; then
Xdialog --title "Internet Package Install" \
--msgbox "No packages to install at this time" 5 40
main
fi

Xdialog --title "Select Packages to Install" \
--checklist "Check the boxes on Packages to Install" 20 70 15 \
 $PKGLIST 2>/tmp/pkgpick

choice=`cat /tmp/pkgpick | sed -e 's!/! !g'`
rm -f /tmp/pkgpick
retval=$?
case $retval in
0)
for i in $choice; do
echo "input string is $i"
Xdialog --title "Getting and installing $i package" \
--yesno "Okay ready to retrieve $i from the ftp site. Select yes to
continue or no to cancel" 0 0
if [ $? = 0 ]; then
xterm -e wget --passive-ftp -P /tmp $FTP/$i
if [ $? = 0 ]; then
xterm -e pkg -i /tmp/$i
if [ $? = 0 ]; then
f=`echo $i | sed -e "s/....$//g"`
Xdialog --title "Packaged Installed" \
--msgbox "The package $i has been installed successfully. You can get
more details of the install by viewing /var/log/packages/$f. Have fun
with your new software !!" 0 0
else
main
fi
fi
fi
rm -f /tmp/$i
done
rm -f /tmp/pkg*
;;
255)
echo "box closed"
main
;;
esac
main
;;
255)
echo "Escape has been pressed"
main
;;
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
main
else
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

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

main () {
clear
Xdialog --title "Vector Linux Package System" \
--radiolist "This is the Vector Linux Package System. \n \n \
Please select the location of the package you wish to install." 18 72 2 \
"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 \
"Quit"  "Quit The Vector Linux Package System" 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
if [ $choice = "Quit" ]; then
exit
fi
;;
1)
echo "Cancel pressed."
exit 1
;;
255)
echo "Escape pressed."
exit 1
;;
esac
}

main
