xref: /freebsd/usr.sbin/bsdconfig/examples/browse_packages_http.sh (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1#!/bin/sh
2#
3# This sample downloads the package digests.txz and packagesite.txz files from
4# HTTP to /tmp (if they don't already exist) and then displays the package
5# configuration/management screen using the local files (resulting in faster
6# browsing of packages from-start since digests.txz/packagesite.txz can be
7# loaded from local media).
8#
9# NOTE: Packages cannot be installed unless staged to
10#       /tmp/packages/$PKG_ABI/All
11#
12[ "$_SCRIPT_SUBR" ] || . /usr/share/bsdconfig/script.subr || exit 1
13nonInteractive=1
14f_musthavepkg_init # Make sure we have a usable pkg(8) with $PKG_ABI
15TMPDIR=/tmp
16PKGDIR=$TMPDIR/packages/$PKG_ABI
17[ -d "$PKGDIR" ] || mkdir -p "$PKGDIR" || exit 1
18for file in digests.txz packagesite.txz; do
19	[ -s "$PKGDIR/$file" ] && continue
20	if [ ! "$HTTP_INITIALIZED" ]; then
21		_httpPath=http://pkg.freebsd.org
22		mediaSetHTTP
23		mediaOpen
24	fi
25	f_show_info "Downloading %s from\n %s" "$file" "$_httpPath"
26	f_device_get device_media "/$PKG_ABI/latest/$file" > $PKGDIR/$file ||
27		exit 1
28done
29_directoryPath=$TMPDIR
30mediaSetDirectory
31configPackages
32