Update 2024-12-31 12:24 OpenBSD/amd64-t14

This commit is contained in:
c0dev0id 2024-12-31 12:24:23 +01:00
parent 9f55042b33
commit 6db769365d

View File

@ -4,12 +4,13 @@
_sqlports="/usr/local/share/sqlports"
_pkgpath="$(head -1 /etc/installurl)/$(uname -r)/packages/$(uname -m)"
# parameters can be freely combined
_usage() {
echo "usage: pkg-depends [options] <pkgpath>"
echo "options: -r - include run dependencies (default)"
echo " -l - include lib dependencies (default)"
echo " -b - include build dependencies"
echo " -t - include test dependencies"
echo "options: -r - list run dependencies (default)"
echo " -l - list lib dependencies (default)"
echo " -b - list build dependencies"
echo " -t - list test dependencies"
echo " -p - show packges names (default)"
echo " -P - show port paths"
echo " -d <dir> - download packages"
@ -37,7 +38,7 @@ shift $(($OPTIND - 1))
[ -z "$1" ] \
&& _usage
if [ ! -f $_sqlports ]
if [ ! -f "$_sqlports" ]
then
echo "$_sqlports not found. Install \"sqlports\" to use this script."
exit 1
@ -45,6 +46,7 @@ fi
### FUNCTIONS
# a little helper in case no pkgpath is provided
_do_pkg() {
echo "pkg-depends needs pkgpath(7) as argument, pkg_info -P can help."
echo "Here, I'm calling it for you:"
@ -55,20 +57,32 @@ _do_pkg() {
}
_do_sql() {
_query="
WITH RECURSIVE pkg(x) AS (
SELECT \"$1\"
UNION
SELECT distinct fulldepends FROM depends
JOIN pkg ON fullpkgpath=x WHERE type in ($2)
) SELECT x, fullpkgname FROM pkg
JOIN ports ON fullpkgpath=x;
"
# XXX: This lists all dependencies for the dependencies for the
# dependencies. I haven't encountert an endless loop here (yet?).
# I guess sqlite takes care or that?
# I'm sure the performance can be improved by not using the big
# ports view to grab the pkgname. But it's late and it works and
# this is a problem for another day.
_query="
WITH RECURSIVE pkg(x) AS (
SELECT \"$1\"
UNION
SELECT distinct fulldepends FROM depends
JOIN pkg ON fullpkgpath=x WHERE type in ($2)
) SELECT x, fullpkgname FROM pkg
JOIN ports ON fullpkgpath=x;
"
# call sqliste and remove the STEM entries from the result
sqlite3 "$_sqlports" "$_query" \
| cut -d: -f2
}
_handle_list() {
# build the comma sparated list that descibes the types
# to include in the list. Used in the sql query.
# _deps are set in getops, with a leading space when 0
# is not set. FIXME: I'm sure there's a better way to do this.
if [ -z "$_deps" ]
then
_deps="0,1"
@ -78,50 +92,73 @@ _handle_list() {
| sed 's/^ //g' \
| tr ' ' ',')"
fi
_list=$(_do_sql "$1" "$_deps")
_firstname=$(echo "$_list" | head -1 | cut -d"|" -f2)
echo "$_list" | sort -u | while read line
do
_portpath=$(echo "$line" | cut -d"|" -f1)
_pkgname=$(echo "$line" | cut -d"|" -f2)
if [ -n "$_dldir" ]
then
_extra="(downloading)"
fi
# default || both on
if [ -z "$_showmode" ] || [ "$_showmode" == "3" ]
then
echo "$_portpath ($_pkgname) $_extra"
fi
# pkgname only
if [ "$_showmode" == "1" ]
then
echo "$_pkgname $_extra"
fi
# portpath only
if [ "$_showmode" == "2" ]
then
echo "$_portpath $_extra"
fi
# download mode: create directory provided in -d <dir>
if [ -n "$_dldir" ]
then
mkdir -p "$_dldir"
fi
if [ -n "$_dldir" ]
then
mkdir -p "$_dldir"
ftp -MV -C -o $_dldir/$_pkgname.tgz $_pkgpath/$_pkgname.tgz
fi
done
echo "Figuring out recursive dependencies, this may take some time..."
_do_sql "$1" "$_deps" | sort -u | while read line
do
_portpath=$(echo "$line" | cut -d"|" -f1)
_pkgname=$(echo "$line" | cut -d"|" -f2)
# download mode: -d <dir>
if [ -n "$_dldir" ]
then
echo "Set the following environmane variables to enable offline installation:"
echo "export TRUSTED_PKG_PATH=\"$(readlink -f "$_dldir")\""
echo "export PKG_PATH=\"$(readlink -f "$_dldir")\""
echo "pkg_add $_firstname"
_extra="(downloading)"
fi
# showmode:
# unset: shows pkgpath and pkgname
# 1: shows pkgname only
# 2: shows pkgpath only
# 3: equals unset # FIXME: set 3 as default and don't handle unset.
# default || both on
if [ -z "$_showmode" ] || [ "$_showmode" == "3" ]
then
echo "$_portpath ($_pkgname) $_extra"
fi
# pkgname only
if [ "$_showmode" == "1" ]
then
echo "$_pkgname $_extra"
fi
# portpath only
if [ "$_showmode" == "2" ]
then
echo "$_portpath $_extra"
fi
# download mode: download file from mirror
# note: this needs sqlports information and the mirror to be
# in sync, which only the case on -release.
# FIXME: figure out a way to do this in snaps.
# Naive idea: cut off the version, get index list from mirror with
# match agains the non-version name and download everything found.
if [ -n "$_dldir" ]
then
ftp -MV -C -o $_dldir/$_pkgname.tgz $_pkgpath/$_pkgname.tgz
fi
done
# XXX: Are both variables needed?
if [ -n "$_dldir" ]
then
echo "Set the following environmane variables to enable offline installation:"
echo "$ export TRUSTED_PKG_PATH=\"$(readlink -f "$_dldir")\""
echo "$ export PKG_PATH=\"$(readlink -f "$_dldir")\""
# FIXME: name the package that has been downloaded. But to translate the
# pkgpath to the package name, another sqlports db call would be necessary.
# There is also pkg_info -e ..., but that only works for alread installed
# packages.
echo "$ pkg_add <package>"
fi
}
### MAIN PROGRAM
### MAIN PROGRAM :)
case "$1" in
*/*) _handle_list "$1" ;;
*) _do_pkg "$1" ;;