| 1 | #!/bin/sh
|
---|
| 2 | # Recursive port fetching utility
|
---|
| 3 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 4 |
|
---|
| 5 | if [ -z "$1" ]; then
|
---|
| 6 | echo "Usage: $0 <packages>" 1>&2
|
---|
| 7 | exit 64
|
---|
| 8 | else
|
---|
| 9 | PACKAGELIST=$*
|
---|
| 10 | fi
|
---|
| 11 |
|
---|
| 12 | #XXX: Make me choose the best mirror automatically
|
---|
| 13 | OS_RELEASE=`sysctl -n kern.osrelease | awk -F- '{print $1}'`
|
---|
| 14 | PKGURL=ftp://ftp.nl.freebsd.org/pub/FreeBSD/ports/i386/packages-${OS_RELEASE}-release/All
|
---|
| 15 | PKGDIR=$(cd `dirname $0`; pwd -P)/packages
|
---|
| 16 |
|
---|
| 17 | echo "# Using PKGURL $PKGURL"
|
---|
| 18 | echo "# Packages get downloaded to $PKGDIR"
|
---|
| 19 |
|
---|
| 20 | TMPDIR=`mktemp -d -t $(basename $0 .sh)`
|
---|
| 21 |
|
---|
| 22 | FETCH='fetch -p -q -m'
|
---|
| 23 |
|
---|
| 24 | err_failed() {
|
---|
| 25 | echo "$*FAILED" 1>&2
|
---|
| 26 | rm -R $TMPDIR
|
---|
| 27 | exit 1
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | # Find longest word in string
|
---|
| 31 | seq_length() {
|
---|
| 32 | len=`echo $* | tr ' ' '\n' | sed 's/./x/g' | sort | tail -1 | wc -c`
|
---|
| 33 | expr $len - 1
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | trap err_failed 1 2 15
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | # Find full release version aka long route to Latest
|
---|
| 40 | echo "# Finding the latest version numbers using INDEX"
|
---|
| 41 | $FETCH $PKGURL/../INDEX.bz2
|
---|
| 42 | rm -f INDEX; bunzip2 -k INDEX.bz2
|
---|
| 43 |
|
---|
| 44 | len=`seq_length $PACKAGELIST`
|
---|
| 45 | for package in $PACKAGELIST; do
|
---|
| 46 | pkg=`awk -F\| "/\/$package\|/ {print \\$1}" INDEX`
|
---|
| 47 | if [ -z "$pkg" ]; then
|
---|
| 48 | err_failed "# Finding version of $package "
|
---|
| 49 | fi
|
---|
| 50 | printf "## %-${len}s -> $pkg\n" $package
|
---|
| 51 | PACKAGES="${PACKAGES} $pkg"
|
---|
| 52 | done
|
---|
| 53 |
|
---|
| 54 | mkdir -p $PKGDIR || exit 1
|
---|
| 55 |
|
---|
| 56 | PACKAGES_FETCHED=`ls $PKGDIR | sed 's/.tbz//g`
|
---|
| 57 | set $PACKAGES
|
---|
| 58 | while [ -n "$1" ]; do
|
---|
| 59 | package=$1; shift
|
---|
| 60 | printf "# Fetching %s ... " $package
|
---|
| 61 | $FETCH -o $PKGDIR $PKGURL/$package.tbz || err_failed && echo "OK"
|
---|
| 62 | PACKAGES_FETCHED="$PACKAGES_FETCHED $package"
|
---|
| 63 |
|
---|
| 64 | # Find dependencies and fetch them accordenly
|
---|
| 65 | dependencies=`tar -xjOf $PKGDIR/$package.tbz +CONTENTS |\
|
---|
| 66 | awk '/^@pkgdep / {print $2}' | tr '\n' ' '`
|
---|
| 67 | if [ -n "$dependencies" ]; then
|
---|
| 68 | echo "## Dependencies of $package:"
|
---|
| 69 | fi
|
---|
| 70 | len=`seq_length $dependencies`
|
---|
| 71 | for dependency in $dependencies; do
|
---|
| 72 | printf "### %-${len}s : " $dependency
|
---|
| 73 | echo "$PACKAGES_FETCHED" | grep -q $dependency
|
---|
| 74 | if [ $? -eq 1 ]; then
|
---|
| 75 | echo "Needs downloading"
|
---|
| 76 | set $* $dependency
|
---|
| 77 | else
|
---|
| 78 | echo "PRESENT"
|
---|
| 79 | fi
|
---|
| 80 | done
|
---|
| 81 | done
|
---|
| 82 |
|
---|
| 83 | rm -R $TMPDIR
|
---|
| 84 |
|
---|
| 85 | echo ""
|
---|
| 86 | echo "# For activation and install"
|
---|
| 87 | echo "setenv PKG_PATH $PKGDIR"
|
---|
| 88 | echo "pkg_add $PACKAGES"
|
---|