#!/bin/sh # $NetBSD: pkg_setup,v 1.4 2012/09/13 20:09:03 cheusov Exp $ # # Copyright (c) 2011 Aleksey Cheusov # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # Variables changable by user : ${OPSYS:=`uname -s`} : ${OSVER:=`uname -r | sed 's/[_-]*$//'`} : ${ARCH:=`uname -m`} : ${MIRROR:='http://ftp.NetBSD.org'} : ${URL:="$MIRROR/pub/pkgsrc/packages/$OPSYS/$ARCH/$OSVER"} : ${FTP_CMD:=ftp -V} ###################################################################### set -e usage (){ cat < url to binary repository, the default is http://ftp.netbsd.org/pub/pkgsrc/packages/\$OPSYS/\$ARCH/\$OSVER -p install specified packages in addition to pkg_install Examples: pkg_setup pkg_setup -v -d http://example.org/pkgsrc/linux/repo -p nih env FTP_CMD='ftp -4V' ./pkg_setup -v \ -d http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/5.0 -- -P /tmp EOF } vecho (){ if test -n "$verbose"; then echo "$@" fi } download (){ # $1 - URL file=`echo "$1" | sed -n 's,file://,,p'` if test -z "$file"; then $FTP_CMD "$1" else cp "$file" . fi } while getopts hvd:p: f; do case $f in h) usage exit 0;; v) verbose=1;; d) URL="$OPTARG";; p) packages="$OPTARG";; \?) exit 1;; esac done shift $(expr $OPTIND - 1) tmpdir=`mktemp -d /tmp/pkg_setup.XXXXXX` trap "rm -rf $tmpdir" 0 test -n "$tmpdir" || exit 1 cd "$tmpdir" vecho 'Downloading pkg_summary.gz...' download "$URL/All/pkg_summary.gz" pkgname=`gzip -dc pkg_summary.gz | awk -F= '/^PKGNAME=pkg_install-[0-9]/ {print $2; exit}'` if test -z "$pkgname"; then echo 'Cannot find package pkg_install in pkg_summary(5)' 1>&2 exit 1 fi vecho "Downloading $pkgname.tgz..." download "$URL/All/$pkgname.tgz" gzip -dc "$pkgname.tgz" | tar -xf - vecho "Installing pkg_install..." ./sbin/pkg_add "$@" ./"$pkgname.tgz" if test -n "$packages"; then vecho "Installing $packages..." PKG_PATH="$URL/All" export PKG_PATH ./sbin/pkg_add "$@" $packages fi vecho "done"