minix/commands/scripts/packman.sh

219 lines
5.2 KiB
Bash
Raw Normal View History

2006-02-03 16:41:58 +01:00
#!/bin/sh
TAG=`uname -p`-`uname -r`.`uname -v`
2006-08-15 17:56:42 +02:00
PACKDIR=`uname -p`/`uname -r`.`uname -v`
2006-02-03 16:41:58 +01:00
RC=/usr/etc/rc.package
CDDIR=PACKAGES
CDMP=/mnt
CDPACK=${CDMP}/install/packages
CDSRC=${CDMP}/install/package-sources
SRC=/usr/bigsrc
LISTFILE=/etc/packages-$TAG
LISTURL=http://www.minix3.org/packages/$PACKDIR/List
TMPDIR=/usr/tmp/packages
mkdir -p $TMPDIR
2006-08-15 17:56:42 +02:00
URL1=http://www.minix3.org/packages/$PACKDIR
SRCURL1=http://www.minix3.org/software
PATH=/bin:/sbin:/usr/bin:/usr/sbin
2006-02-03 16:41:58 +01:00
if [ ! "$PAGER" ]
then PAGER=more
fi
# can we execute bunzip2?
if bunzip2 --help 2>&1 | grep usage >/dev/null
then BUNZIP2=bunzip2
else BUNZIP2=smallbunzip2
fi
if id | fgrep "uid=0(" >/dev/null
then :
else echo "Please run $0 as root."
exit 1
fi
2006-03-26 18:46:37 +02:00
chmod 700 $TMPDIR
2006-02-03 16:41:58 +01:00
if [ -f "$RC" ]
then . "$RC"
fi
cd /
2007-03-12 17:55:02 +01:00
# Make sure there is a $SRC dir
if [ ! -d "$SRC" ]
then mkdir $SRC || exit
fi
# Is there a usable CD to install packages from?
cdpackages=""
2006-02-03 16:41:58 +01:00
if [ -n "$cddrive" ]
then pack=${cddrive}p2
umount $pack >/dev/null 2>&1 || true
echo "Checking for CD in $pack."
if mount -r $pack $CDMP 2>/dev/null
then fn="$CDPACK/List"
echo "Found."
cdpackages=$fn
if [ ! -f $cdpackages ]
then cdpackages=""
echo "No package list found on CD in $fn."
fi
else echo "Not found."
fi
2006-03-17 16:32:14 +01:00
else echo "Don't know where the install CD is. You can set it in $RC."
2006-02-03 16:41:58 +01:00
fi
2006-02-06 11:55:38 +01:00
2006-03-26 18:46:37 +02:00
TMPF=$TMPDIR/.list.$$
rm -f $TMPF
rm -f $TMPDIR/.* # Remove any remaining .postinstall script or .list*
2007-03-12 17:55:02 +01:00
# Check for network packages too
netpackages=""
2006-03-26 21:30:33 +02:00
if ( : </dev/tcp ) 2>/dev/null
then echo -n "Update package list from network? (Y/n) "
read y
if [ "$y" != n -a "$y" != N ]
then echo "Fetching package list from $LISTURL."
2006-03-27 13:08:04 +02:00
urlget $LISTURL >$TMPF && mv $TMPF $LISTFILE || echo "Update not successful."
fi
netpackages=$LISTFILE
if [ ! -f "$netpackages" -o ! `cat "$netpackages" 2>/dev/null | wc -l | awk '{ print $1 }'` -gt 1 ]
then netpackages=""
fi
else echo "No working network detected."
fi
2007-03-12 17:55:02 +01:00
# Is there at least one package type?
if [ ! -n "$netpackages" -a ! -n "$cdpackages" ]
then echo "No packages found."
exit 1
fi
# Is there more than one package type?
if [ -n "$netpackages" -a -n "$cdpackages" ]
then echo -n "Would you like to install from (C)D or (N)etwork? [C] "
read whichsrc
if [ "$whichsrc" = N -o "$whichsrc" = n ]
then unset cdpackages
else unset netpackages
fi
fi
2007-03-12 17:55:02 +01:00
if [ -n "$netpackages" ]
then source=net
else source=cdrom
fi
cont=y
while [ "$cont" = y ]
do cd $TMPDIR
echo ""
echo "Showing you a list of packages using $PAGER. Press q when"
echo "you want to leave the list."
echo -n "Press RETURN to continue.."
read xyzzy
echo "Package list:"
2007-03-12 17:55:02 +01:00
( echo "No.|Package|Description"
(
2007-04-13 19:13:53 +02:00
if [ -f "$netpackages" -a "$source" = net ]
2007-03-12 17:55:02 +01:00
then cat $netpackages
fi
2007-04-13 19:13:53 +02:00
if [ -f "$cdpackages" -a "$source" = cdrom ]
2007-03-12 17:55:02 +01:00
then cat $cdpackages
fi
) | sort -f -t'|' +0 | awk '{ n++; printf "%d|%s\n", n, $0 }'
) >$TMPF
2007-04-02 14:09:43 +02:00
highest="`wc -l $TMPF | awk '{ print $1 - 1 }'`"
awk -F'|' <$TMPF '{ printf "%3s %-15s %s\n", $1, $2, $3 }' | $PAGER
2007-03-12 17:55:02 +01:00
echo "Format examples: '3', '3,6', '3-9', '3-9,11-15', 'all'"
2007-04-02 16:44:16 +02:00
echo -n "Package(s) to install (RETURN or q to exit)? "
2007-03-12 17:55:02 +01:00
read packnolist
2007-04-02 16:44:16 +02:00
if [ "$packnolist" = "" -o "$packnolist" = "q" ]
2007-03-21 10:54:09 +01:00
then exit 0
fi
2007-03-12 17:55:02 +01:00
if [ "$packnolist" = all ]
then packnolist=1-$highest
fi
IFS=','
set $packnolist
echo -n "Get source(s) too? (y/N) "
read getsources
for packrange in $packnolist
do
# Get a-b range.
IFS='-'
set $packrange
start=$1
if [ $# = 2 ]
then end=$2
else end=$1
fi
IFS=' '
# use awk to make the range list
for packno in `awk </dev/null "BEGIN { for(i=$start; i<=$end; i++) { printf \"%d \", i } }"`
do
2006-03-26 18:46:37 +02:00
ok=y
pat="^$packno|"
2007-03-12 17:55:02 +01:00
if [ "`grep -c $pat $TMPF`" -ne 1 ]
2006-03-26 18:46:37 +02:00
then if [ "$packno" ]
2007-03-12 17:55:02 +01:00
then echo "$packno: Wrong package number."
2006-03-26 18:46:37 +02:00
fi
ok=n
fi
if [ $ok = y ]
2007-03-12 17:55:02 +01:00
then
packagename="`grep $pat $TMPF | awk -F'|' '{ print $2 }'`"
file=$packagename.tar.bz2
echo ""
if [ -f $file ]
then echo "Skipping $file - it's already in $TMPDIR."
echo "Remove that file if you want to re-retrieve and install this package."
else
case $source in
2007-03-12 17:55:02 +01:00
net*) echo "Retrieving $packno ($packagename) from primary location into $TMPDIR .."
srcurl=""
if urlget $URL1/$file >$file
2006-03-26 18:46:37 +02:00
then echo "Retrieved ok. Installing .."
2006-03-26 17:51:34 +02:00
packit $file && echo Installed ok.
srcurl=$SRCURL1/$file
2006-08-15 17:56:42 +02:00
else echo "Retrieval failed."
fi
2007-03-12 17:55:02 +01:00
if [ "$getsources" = y -o "$getsources" = Y ]
then ( cd $SRC || exit
srcfile=${packagename}-src.tar.bz2
echo "Retrieving source from $srcurl .."
urlget $srcurl >$srcfile || exit
echo "Source retrieved in $SRC/$srcfile."
$BUNZIP2 -dc $srcfile | tar xf - >/dev/null || exit
echo "Source unpacked in $SRC."
)
fi
;;
cdrom*)
2006-03-26 18:46:37 +02:00
if [ -f $CDPACK/$file ]
then echo "Installing from $CDPACK/$file .."
2007-03-12 17:55:02 +01:00
packit $CDPACK/$file && echo Installed ok.
2006-03-26 18:46:37 +02:00
else echo "$CDPACK/$file not found."
fi
2007-04-13 19:13:53 +02:00
srcfile=$CDSRC/${packagename}.tar.bz2
if [ -f $srcfile -a "$getsources" = y ]
2007-03-12 17:55:02 +01:00
then
( cd $SRC || exit
$BUNZIP2 -dc $srcfile | tar xf - || exit
2006-03-26 18:46:37 +02:00
echo "Source $srcfile unpacked in $SRC."
)
fi
;;
esac
2007-03-12 17:55:02 +01:00
fi
else cont=n
fi
2007-03-12 17:55:02 +01:00
done # Iterate package range
done # Iterate package range list
done
2006-03-26 18:46:37 +02:00
rm -f $TMPDIR/.* # Remove any remaining .postinstall script or .list*