source: banobsd/trunk/pkg_download.sh@ 300

Last change on this file since 300 was 6, checked in by Rick van der Zwet, 15 years ago

Somehow more error,checky

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/sh
2# Recursive port fetching utility
3# Rick van der Zwet <info@rickvanderzwet.nl>
4
5if [ -z "$1" ]; then
6 echo "Usage: $0 <packages>" 1>&2
7 exit 64
8else
9 PACKAGELIST=$*
10fi
11
12#XXX: Make me choose the best mirror automatically
13OS_RELEASE=`sysctl -n kern.osrelease | awk -F- '{print $1}'`
14PKGURL=ftp://ftp.nl.freebsd.org/pub/FreeBSD/ports/i386/packages-${OS_RELEASE}-release/All
15PKGDIR=$(cd `dirname $0`; pwd -P)/packages
16
17echo "# Using PKGURL $PKGURL"
18echo "# Packages get downloaded to $PKGDIR"
19
20TMPDIR=`mktemp -d -t $(basename $0 .sh)`
21
22FETCH='fetch -p -q -m'
23
24err_failed() {
25 echo "$*FAILED" 1>&2
26 rm -R $TMPDIR
27 exit 1
28}
29
30# Find longest word in string
31seq_length() {
32 len=`echo $* | tr ' ' '\n' | sed 's/./x/g' | sort | tail -1 | wc -c`
33 expr $len - 1
34}
35
36trap err_failed 1 2 15
37
38
39# Find full release version aka long route to Latest
40echo "# Finding the latest version numbers using INDEX"
41$FETCH $PKGURL/../INDEX.bz2
42rm -f INDEX; bunzip2 -k INDEX.bz2
43
44len=`seq_length $PACKAGELIST`
45for 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"
52done
53
54mkdir -p $PKGDIR || exit 1
55
56PACKAGES_FETCHED=`ls $PKGDIR | sed 's/.tbz//g`
57set $PACKAGES
58while [ -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
81done
82
83rm -R $TMPDIR
84
85echo ""
86echo "# For activation and install"
87echo "setenv PKG_PATH $PKGDIR"
88echo "pkg_add $PACKAGES"
Note: See TracBrowser for help on using the repository browser.