]> Zhao Yanbai Git Server - minix.git/commitdiff
Smarter packman that unifies cdrom and network packages.
authorBen Gras <ben@minix3.org>
Sun, 26 Mar 2006 15:48:55 +0000 (15:48 +0000)
committerBen Gras <ben@minix3.org>
Sun, 26 Mar 2006 15:48:55 +0000 (15:48 +0000)
commands/scripts/packman.sh

index 7c38406bec3f03dd9b98a39c2818a65c138f0481..00f84b26509ee1fe8cef6578a29b572e40e045e7 100644 (file)
@@ -2,9 +2,9 @@
 
 RC=/usr/etc/rc.package
 CDDIR=PACKAGES
-MP=/mnt
-CDPACK=${MP}/install/packages
-CDSRC=${MP}/install/package-sources
+CDMP=/mnt
+CDPACK=${CDMP}/install/packages
+CDSRC=${CDMP}/install/package-sources
 SRC=/usr/src/commands
 LISTFILE=/etc/packages
 LISTURL=http://www.minix3.org/packages/List
@@ -15,100 +15,132 @@ URL2=http://www.minix3.org/beta_packages
 SRCURL1=http://www.minix3.org/software
 SRCURL2=http://www.minix3.org/beta_software
 
+if id | fgrep "uid=0(" >/dev/null
+then   :
+else   echo "Please run $0 as root."
+       exit 1
+fi
+
 if [ -f "$RC" ]
 then   . "$RC"
 fi
 
 cd /
 
+cdpackages=""
 if [ -n "$cddrive" ]
 then   pack=${cddrive}p2
        umount $pack >/dev/null 2>&1 || true
-       if mount -r $pack $MP
-       then
-               cd $CDPACK
-               for package in `ls *.tar.bz2`
-               do      grep $package List
-                       echo -n "Install $package (y/N) ? "
-                       read y
-                       if [ "$y" = y -o "$y" = Y ]
-                       then    echo "Extracting $CDPACK/$package .."
-                               cat $package | packit -
-                               srcname="`echo $package | sed 's/.tar.bz2/-src.tar.bz2/'`"
-                               srcarc="$CDSRC/$srcname"
-                               if [ -f "$srcarc" ]
-                               then    echo -n "Install its source (y/N) ? "
-                                       read y
-                                       if [ "$y" = y -o "$y" = Y ]
-                                       then    echo "Installing $srcarc into $SRC."
-                                               smallbunzip2 -dc "$srcarc" | (cd $SRC && tar xf - )
-                                       fi
-                               else    :
-                               fi
-                       fi
-               done
-       else    echo "CD mount failed - skipping CD packages."
+       if mount -r $pack $CDMP
+       then    fn="$CDPACK/List"
+               cdpackages=$fn
+               if [ ! -f $cdpackages ]
+               then    cdpackages=""
+                       echo "No package list found on CD in $fn."
+               fi
+       else    echo "CD mount failed."
        fi
 else   echo "Don't know where the install CD is. You can set it in $RC."
 fi
 
+if [ "$cdpackages" = "" ]
+then   echo "Skipping CD packages."
+fi
+
 TMPF=/tmp/list.$$
 
+netpackages=""
 if </dev/tcp
 then   if [ -f $LISTFILE ]
        then    echo -n "Update package list from network? (y/N) "
                read y
-       else    y=y
+       else    echo "No package list found - retrieving initial version."
+               y=y
        fi
        if [ "$y" = y -o "$y" = Y ]
        then    echo "Fetching package list."
-               urlget $LISTURL >$TMPF && mv $TMPF $LISTFILE || echo Not done.
+               urlget $LISTURL >$TMPF && mv $TMPF $LISTFILE || echo "Update not successful."
        fi
-       cont=y
-       while [ "$cont" = y ]
-       do      cd $TMPDIR
-               echo "Package list:"
-               awk -F'|' <$LISTFILE '{ printf "%3s %-20s %s\n", $1, $2, $3 }' | more
-               echo -n "Package to install? [RETURN for none] "
-               read packno
-               if [ -n "$packno" ]
-               then    file="`grep "^$packno|" $LISTFILE | awk -F'|' '{ print $2 }'`"
-                       url=$file.tar.bz2
-                       srcfile=$file.tar.bz2
-                       if [ -n "$url" ]
-                       then    echo -n "Try to get source too? (y/N) "
-                               read src
-                               echo "Trying to fetch from $URL1/$url.."
-                               srcurl=$SRCURL1/$srcfile
-                               if urlget $URL1/$url >$url
-                               then    echo Installing.
-                                       packit $url
-                               else    echo "Trying to fetch from $URL2/$url.."
-                                       srcurl=$SRCURL2/$srcfile
-                                       if urlget $URL2/$url >$url
-                                       then    echo Installing Beta.
-                                               packit $url
-                                       else    echo "Retrieval failed."
-                                       fi
-                               fi
-                               if [ "$src" = y -o "$src" = Y ]
-                               then    cd $SRC
-                                       echo "Trying $srcurl"
-                                       if urlget $srcurl >$srcfile
-                                       then    echo "Extracting source into $SRC"
-                                               smallbunzip2 -dc $srcfile | tar xf -
-                                               echo "Done"
-                                       else    echo "$srcurl not retrieved."
-                                       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
+
+if [ "$netpackages" = "" ]
+then   echo "Skipping network packages."
+       if [ "$cdpackages" = "" ]
+       then    echo "No packages found."
+               exit 1
+       fi
+fi
+
+cont=y
+while [ "$cont" = y ]
+do     cd $TMPDIR
+       echo ""
+       echo "Showing you a list of packages using more. Press q when"
+       echo "you want to leave the list."
+       echo -n "Press RETURN to continue.."
+       read xyzzy
+       echo "Package list:"
+       (       echo "No.|Source|Package|Description"
+               (
+               if [ -f "$netpackages" ]
+               then    sed <$netpackages 's/^/net\|/'
+               fi
+               if [ -f "$cdpackages" ]
+               then    sed <$cdpackages 's/^/cdrom\|/'
+               fi
+               ) | sort -n -t'|' +2 | awk '{ n++; printf "%d|%s\n", n, $0 }'
+       ) >$TMPF
+       awk -F'|' <$TMPF '{ printf "%3s %-6s %-15s %s\n", $1, $2, $3, $4 }' | more
+       echo -n "Package to install? [RETURN for none] "
+       read packno
+       if [ -n "$packno" ]
+       then    source="`grep "^$packno|" $TMPF | awk -F'|' '{ print $2 }'`"
+               packagename="`grep "^$packno|" $TMPF | awk -F'|' '{ print $3 }'`"
+               file=$packagename.tar.bz2
+               echo -n "Get source of $packagename? (y/N) "
+               read src
+               case $source in
+               net*)   echo "Retrieving binary from primary location into $TMPDIR .."
+                       srcurl=""
+                       if urlget $URL1/$file >$file
+                       then    packit $file && echo Installed ok.
+                               srcurl=$SRCURL1/$file
+                       else    echo "Retrying from Beta binary location.."
+                               if urlget $URL2/$file >$file
+                               then    packit $file  && echo Installed ok.
+                                       srcurl=$SRCURL2/$file
+                               else echo "Retrieval failed."
                                fi
-                       else    echo "Package $packno not found."
                        fi
-                       echo "Press RETURN to continue .."
-                       read xyzzy
-               else    cont=n
-               fi
-       done
-else   echo "No working network detected.
-Please re-run this script with networking enabled to download
-packages."
-fi
+                       if [ "$src" = y -o "$src" = 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."
+                                       smallbunzip2 -dc $srcfile | tar xf - >/dev/null || exit
+                                       echo "Source unpacked in $SRC."
+                               )
+                       fi
+                       ;;
+               cdrom*)
+                       if -f [ $CDPACK/$file ]
+                       then    packit $CDPACK/$file
+                       fi
+                       if [ "$src" = y -o "$src" = Y ]
+                       then    (       cd $SRC || exit
+                                       srcfile=$CDSRC/${packagename}-src.tar.bz2
+                                       smallbunzip2 -dc $srcfile | tar xf - || exit
+                                       echo "Source $srcfile unpacked in $SRC."
+                               )
+                       fi
+                       ;;
+               esac
+       else    cont=n
+       fi
+done