Calomel.org Home Page RSS Feed
OpenBSD has a decent set of tools to install packages from the web site
or ftp site of your choice. The problem is, none of them are as quick
and easy to use to query for a package name or perhaps a partial string
of a name.
pkg_find allows you to setup the repository or your choice and then search that repository by package name. The script then compiles a list of all the packages it found and outputs the result of your search. You then have the option to copy and paste the result into pkg_add or your favorite package manager. This makes setting up a new box or adding packages to an existing box incredibly fast.
The following is an example of what pkg_find shows if we ask to install postfix on an OpenBSD v5.1 machine. Note, we did _not_ have to specify the version number or any other information. And, unlike "pkg_add -i", pkg_find will also list files that are close to your query term. This way you can still get a package listing even if you do not quite know how to spell the package name or if the name has capitalization. All packages with postfix in the name are displayed in alphabetical order.
root@machine: pkg_find postfix Packages matching your query: postfix mailman-2.1.14p8-postfix.tgz postfix-2.7.2p0-ldap.tgz postfix-2.7.2p0-mysql.tgz postfix-2.7.2p0-pgsql.tgz postfix-2.7.2p0-sasl2.tgz postfix-2.7.2p0.tgz postfix-2.8.20110113-ldap.tgz postfix-2.8.20110113-mysql.tgz postfix-2.8.20110113-pgsql.tgz postfix-2.8.20110113-sasl2.tgz postfix-2.8.20110113-sqlite.tgz postfix-2.8.20110113.tgz
Lets say we wanted to install the postfix package with sasl support. We would copy the package name display above and use "pkg_add -i postfix-2.8.20110113-sasl2.tgz" to install the package and pkg_add will take care of the dependencies. The package chosen and its dependencies will painlessly be installed from the remote repository. This makes compatibility between platforms a non-issue.
Below is the simple pkg_find script and it works on i386 and amd64 systems without issue. Make a new file called pkg_find and put the code into it. Then make sure the script is executable using "chmod 755 pkg_find". You can just copy and paste the shell script from the following text box.
#!/usr/local/bin/bash # ## Calomel.org .:. pkg_find v0.07 # ## location of the local package listing file packages=~/pkg_find_package_listing.html if [ $# -eq 0 ] then echo "" echo " Calomel.org .:. pkg_find" echo "-------------------------------------" echo "-u = update the local package listing." echo "'string' = the package name or partial string of the package name you are looking for." echo "" exit fi if [ $1 = "-u" ] then echo " " echo -e "\033[32m Download the package listing to $packages\033[0m" echo " " wget -O $packages $PKG_PATH echo " " exit fi if [ $1 = "$@" ] then if [ -e $packages ] then echo " " echo -e "\033[32m Packages matching your query: $@\033[0m" echo " " cat $packages | grep -i $@ | cut -d\" -f6 echo " " else echo " " echo -e "\033[32m $packages file does not exist. Run 'pkg_find -u' to update\033[0m" echo " " fi exit fi
First, you will need to download a local copy of the package listings. In the script we are collecting the package names from the site assigned to the $PKG_PATH environmental variable. We define the PKG_PATH in our .profile since this same variable is used by pkg_add to install the packages.
export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`arch -s`/
In our case this is from OpenBSD's main site in Canada at "PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/5.1/packages/amd64/". The path says we are getting the contents of OpenBSD v5.1 amd64 packages.
The package listing will be placed into the home directory of the user running the script in a file called pkg_find_package_listing.html.
To collect the package names run the script with the argument "-u" like so:
root@machine: ./pkg_find -u Download the package listing to /root/pkg_find_package_listing.html --2011-01-01 10:10:10-- http://ftp.openbsd.org/pub/OpenBSD/5.1/packages/amd64/ Resolving ftp.openbsd.org (ftp.openbsd.org)... 129.128.5.191 Connecting to ftp.openbsd.org (ftp.openbsd.org)|129.128.5.191|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: `/root/pkg_find_package_listing.html' [=======================================] 892,834 278K/s in 3.1s 2011-01-01 10:10:10 (278 KB/s) - `/root/pkg_find_package_listing.html' saved [892834]
Now that we have a local copy of the package listings just execute the script with the name of the package or partial string you are looking for. Lets look for packages which contain the name "tidy". Notice the query will find those packages no matter if the name has capitalization or not.
root@machine: ./pkg_find tidy Packages matching your query: tidy p5-Exporter-Tidy-0.06p1.tgz p5-HTML-Tidy-1.08p2.tgz p5-Test-HTML-Tidy-1.00p0.tgz perltidy-20090616.tgz php5-tidy-5.2.17.tgz tidy-051026.tgz
Thats about it. Whenever you are looking for a package just make sure to update the local package listing, with "-u", if it has been a few days. OpenBSD does not update their package listings that often, but you probably want to make sure you have at least the latest daily copy of the available package names.
Can pkg_find use a PKG_PATH listing multiple repositories?
No, it can not. If you want to use multiple ftp/ http servers in your PKG_PATH then you must stick to using the default pkg_add tool instead of pkg_find.
Questions, comments, or suggestions? Contact Calomel.org or Google+