source: banobsd/trunk/pkg_download.sh@ 5

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

Fix the package download hell, without using any external program

  • Property svn:executable set to *
File size: 2.0 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=/tmp/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"
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 printf "## %-${len}s -> $pkg\n" $package
48 PACKAGES="${PACKAGES} $pkg"
49done
50
51mkdir -p $PKGDIR || exit 1
52
53PACKAGES_FETCHED=`ls $PKGDIR | sed 's/.tbz//g`
54set $PACKAGES
55while [ -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
78done
79
80rm -R $TMPDIR
81
82echo ""
83echo "# For activation and install"
84echo "setenv PKG_PATH $PKGDIR"
85echo "pkg_add $PACKAGES"
Note: See TracBrowser for help on using the repository browser.