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=/tmp/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"
|
---|
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 | printf "## %-${len}s -> $pkg\n" $package
|
---|
48 | PACKAGES="${PACKAGES} $pkg"
|
---|
49 | done
|
---|
50 |
|
---|
51 | mkdir -p $PKGDIR || exit 1
|
---|
52 |
|
---|
53 | PACKAGES_FETCHED=`ls $PKGDIR | sed 's/.tbz//g`
|
---|
54 | set $PACKAGES
|
---|
55 | while [ -n "$1" ]; do
|
---|
56 | package=$1; shift
|
---|
57 | printf "# Fetching %s ... " $package
|
---|
58 | $FETCH -o $PKGDIR $PKGURL/$package.tbz || err_failed && echo "OK"
|
---|
59 | PACKAGES_FETCHED="$PACKAGES_FETCHED $package"
|
---|
60 |
|
---|
61 | # Find dependencies and fetch them accordenly
|
---|
62 | dependencies=`tar -xjOf $PKGDIR/$package.tbz +CONTENTS |\
|
---|
63 | awk '/^@pkgdep / {print $2}' | tr '\n' ' '`
|
---|
64 | if [ -n "$dependencies" ]; then
|
---|
65 | echo "## Dependencies of $package:"
|
---|
66 | fi
|
---|
67 | len=`seq_length $dependencies`
|
---|
68 | for dependency in $dependencies; do
|
---|
69 | printf "### %-${len}s : " $dependency
|
---|
70 | echo "$PACKAGES_FETCHED" | grep -q $dependency
|
---|
71 | if [ $? -eq 1 ]; then
|
---|
72 | echo "Needs downloading"
|
---|
73 | set $* $dependency
|
---|
74 | else
|
---|
75 | echo "PRESENT"
|
---|
76 | fi
|
---|
77 | done
|
---|
78 | done
|
---|
79 |
|
---|
80 | rm -R $TMPDIR
|
---|
81 |
|
---|
82 | echo ""
|
---|
83 | echo "# For activation and install"
|
---|
84 | echo "setenv PKG_PATH $PKGDIR"
|
---|
85 | echo "pkg_add $PACKAGES"
|
---|