Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Feb 2002 20:09:04 +0200
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        Jan Grant <Jan.Grant@bristol.ac.uk>
Cc:        GABEL JULIEN <Julien.GABEL@sgam.com>, "Scott M. Nolde" <scott@smnolde.com>, Joe & Fhe Barbish <barbish@a1poweruser.com>, questions@freebsd.org
Subject:   Re: Simple script ?
Message-ID:  <20020225180904.GB50692@hades.hell.gr>
In-Reply-To: <Pine.GSO.4.44.0202251511210.13403-100000@mail.ilrt.bris.ac.uk>
References:  <D7444C754148D411842E00902740F56D0395848B@MAILBOX2> <Pine.GSO.4.44.0202251511210.13403-100000@mail.ilrt.bris.ac.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2002-02-25 15:12, Jan Grant wrote:
> On Mon, 25 Feb 2002, GABEL JULIEN wrote:
> 
> > $ cat getpackage
> > #!/bin/sh
> > ftp -a -v
> > ftp5.FreeBSD.org:/pub/FreeBSD/releases/i386/4.4-RELEASE/packages/$1
> 
> Slap double-quotes around the $1; that way, if the command's invoked
> like this:
> 
> 	getpackage "a path containing a space"
> 
> the ftp command won't get mangled.

A nice alternative, using tools from the base system is a fetch(1) wrapper
in a shell script.  A simple script like this can be:

	#!/bin/sh
	fetch -r -a ftp5.FreeBSD.org:/pub/FreeBSD/releases/i386/4.4-RELEASE/packages/"$1"

If you want to get funky, you can even have a list of mirrors, in the
script, and allow overriding it with an environment variable.  Then try the
each mirror in turn, until one of them fetch'es the file correctly.

Also, hardcoding 4.4-RELEASE doesn't seem like a very nice idea.  Using
uname(1) you can `guess' the correct release and try fetching packages from
that part of the FTP mirror, if possible.  Similarly the architecture can
be something that is not "i386", so make sure you grab the correct value
from the hw.machine_arch sysctl value:

	#!/bin/sh

	# The default list of mirrors to try fetching from.
	default_freebsd_mirrors="ftp.FreeBSD.org \
		ftp1.FreeBSD.org \
		ftp2.FreeBSD.org"

	# By default try to fetch packages for the -RELEASE of the
	# currently installed version.
	default_freebsd_release="`uname -r | sed -e 's/-.*$/-RELEASE/'`"

	# Try to guess the correct architecture, to avoid installing i386
	# packages on an alpha machine, for instance.
	default_freebsd_arch="`sysctl -n hw.machine_arch`"

	freebsd_mirrors="${freebsd_mirrors:-$default_freebsd_mirrors}"
	freebsd_release="${freebsd_release:-$default_freebsd_release}"
	freebsd_arch="${freebsd_arch:-$default_freebsd_arch}"

	for mirror in ${freebsd_mirrors} ;do
		echo "Trying to fetch $1 from ${mirror} ..."
		fetch -a -r "${mirror}://pub/FreeBSD/releases/${freebsd_arch}/${freebsd_release}/packages/$1"
		if [ $? -eq 0 ]; then
			echo "Done."
			break
		fi
	done

But, I'll shuttup now, since the original poster asked for a `simple'
script, and this is probably starting to get too complicated.

Giorgos Keramidas                           FreeBSD Documentation Project
keramida@{freebsd.org,ceid.upatras.gr}      http://www.FreeBSD.org/docproj/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)

iD8DBQE8en2/1g+UGjGGA7YRAhz2AJ9WL3nWKY4oEMLIWrOmVkguz11l6QCgnyOB
70Py+sPnF216RThFeBXkLf0=
=o50v
-----END PGP SIGNATURE-----

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020225180904.GB50692>