5 # Copyright (c) 2003,2009 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Alistair Crooks (agc@NetBSD.org)
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
44 if [ "x$_tmp" != "x" ]; then
45 # Variable is already set (by the user, for example)
49 for _d
in `echo $PATH | tr ':' ' '`; do
50 if [ -x "$_d/$_name" ]; then
52 eval $_var=\""$_d/$_name"\"
57 die
"$_name not found in path."
60 check_prog awkprog
awk
61 check_prog echoprog
echo
62 check_prog ftpprog
ftp
64 check_prog moreprog
more
65 check_prog pkg_addprog pkg_add
67 check_prog sedprog
sed
69 check_prog unameprog uname
71 # print version and exit
78 tmpcategories
=/tmp
/categories.$$
79 tmppackages
=/tmp
/packages.$$
81 # some base parameters
82 base
=ftp://ftp.NetBSD.org
/pub
/pkgsrc
/packages
83 release
=`${unameprog} -r | ${sedprog} -e 's/_STABLE//'`
84 machine
=`${unameprog} -m`
90 while [ $# -gt 0 ]; do
94 -h) ${echoprog} "$0 [-b BaseURL] [-h] [-m machine] [-n] [-r release] [-v] [-w secs]"; exit 0;;
95 -m) machine
=$2; shift ;;
97 -r) release
=$2; shift ;;
99 -w) sleepsecs
=$2; shift ;;
108 # if we don't have a packages file, then we need to choose a category
110 "") # get possible categories
111 if [ ! -f $tmpcategories ]; then
112 ${echoprog} "Downloading package categories from ${base}..."
113 ${echoprog} "** QUIT" > $tmpcategories
114 ${echoprog} ls | ${ftpprog} ${base}/${release}/${machine}/ 2>/dev
/null | \
115 ${awkprog} 'NF == 9 { if ($9 != "All") print $9 }' >> $tmpcategories
118 # check for bad release numbering
119 # - it usually shows with 0 categories being displayed
120 ${awkprog} 'END { if (NR == 1) { print "\n\n\n*** No categories found - is the OS release set properly? ***\n\n\n" } }' < $tmpcategories
122 # display possible categories
123 ${awkprog} '{ print NR ". " $0 }' < $tmpcategories |
${moreprog}
125 # read a category number from the user
126 ${echoprog} -n "Please type the category number: "
129 # validate user's choice
131 0|
1) ${rmprog} -f $tmpcategories $tmppackages; exit 0 ;;
132 [2-9]|
[0-9]*) category
=`${awkprog} 'NR == '$choice' { print }' < $tmpcategories` ;;
136 "") ${echoprog} "No such category \"$choice\""
142 # get possible packages
144 ${echoprog} "Downloading package names from ${base}/${category}...
"
145 ${echoprog} "** QUIT
" > $tmppackages
146 ${echoprog} "** Change category
" >> $tmppackages
147 ${echoprog} ls | ${ftpprog} ${base}/${release}/${machine}/${category}/ 2>/dev/null \
148 | ${awkprog} 'NF == 11 { print $9 }' >> $tmppackages
152 # display possible packages
153 ${awkprog} '{ print NR ".
" $0 }' < $tmppackages | ${moreprog}
155 # read a package number from the user
156 ${echoprog} -n "Please
type the package number
: "
159 # validate user's choice
161 1) ${rmprog} -f $tmppackages $tmpcategories; exit 0 ;;
162 2) category=""; continue ;; # no package to install - choose new category
163 [3-9]|[0-9]*) package=`${awkprog} 'NR == '$choice' { print }' < $tmppackages` ;;
167 "") ${echoprog} "No such package
\"$choice\""
173 # check it's not already installed
174 pkgbase=`${echoprog} ${package} | ${sedprog} -e 's|-[0-9].*||'`
175 installed=`pkg_info -e $pkgbase`
178 *) ${echoprog} "$package selected
, but
$installed already installed
"
184 # Tell people what we're doing
186 ${echoprog} "Adding package ${base}/${release}/${machine}/${category}/${package}"
188 cmd
="env PKG_PATH=${base}/${release}/${machine}/All ${pkg_addprog} ${package}"
190 # check if we need to become root for this
191 if [ `${idprog} -u` != 0 ]; then
192 ${echoprog} "Becoming root@`/bin/hostname` to add a binary package"
193 ${echoprog} -n "`${echoprog} ${suprog} | $awkprog '{ print $1 }'` "
194 $doit ${suprog} root -c "$cmd"
201 # give feedback after adding the package
203 0) ${echoprog} "$package successfully installed" ;;
204 *) ${echoprog} "Problems when installing $package - please try again" ;;
208 ${echoprog} -n "[Q]uit, [C]hange category, [I]nstall another package: "
218 ${rmprog} -f $tmpcategories $tmppackages