Update 2024-12-31 12:24 OpenBSD/amd64-t14
This commit is contained in:
parent
9f55042b33
commit
6db769365d
139
.bin/pkg-depends
139
.bin/pkg-depends
@ -4,12 +4,13 @@
|
|||||||
_sqlports="/usr/local/share/sqlports"
|
_sqlports="/usr/local/share/sqlports"
|
||||||
_pkgpath="$(head -1 /etc/installurl)/$(uname -r)/packages/$(uname -m)"
|
_pkgpath="$(head -1 /etc/installurl)/$(uname -r)/packages/$(uname -m)"
|
||||||
|
|
||||||
|
# parameters can be freely combined
|
||||||
_usage() {
|
_usage() {
|
||||||
echo "usage: pkg-depends [options] <pkgpath>"
|
echo "usage: pkg-depends [options] <pkgpath>"
|
||||||
echo "options: -r - include run dependencies (default)"
|
echo "options: -r - list run dependencies (default)"
|
||||||
echo " -l - include lib dependencies (default)"
|
echo " -l - list lib dependencies (default)"
|
||||||
echo " -b - include build dependencies"
|
echo " -b - list build dependencies"
|
||||||
echo " -t - include test dependencies"
|
echo " -t - list test dependencies"
|
||||||
echo " -p - show packges names (default)"
|
echo " -p - show packges names (default)"
|
||||||
echo " -P - show port paths"
|
echo " -P - show port paths"
|
||||||
echo " -d <dir> - download packages"
|
echo " -d <dir> - download packages"
|
||||||
@ -37,7 +38,7 @@ shift $(($OPTIND - 1))
|
|||||||
[ -z "$1" ] \
|
[ -z "$1" ] \
|
||||||
&& _usage
|
&& _usage
|
||||||
|
|
||||||
if [ ! -f $_sqlports ]
|
if [ ! -f "$_sqlports" ]
|
||||||
then
|
then
|
||||||
echo "$_sqlports not found. Install \"sqlports\" to use this script."
|
echo "$_sqlports not found. Install \"sqlports\" to use this script."
|
||||||
exit 1
|
exit 1
|
||||||
@ -45,6 +46,7 @@ fi
|
|||||||
|
|
||||||
### FUNCTIONS
|
### FUNCTIONS
|
||||||
|
|
||||||
|
# a little helper in case no pkgpath is provided
|
||||||
_do_pkg() {
|
_do_pkg() {
|
||||||
echo "pkg-depends needs pkgpath(7) as argument, pkg_info -P can help."
|
echo "pkg-depends needs pkgpath(7) as argument, pkg_info -P can help."
|
||||||
echo "Here, I'm calling it for you:"
|
echo "Here, I'm calling it for you:"
|
||||||
@ -55,20 +57,32 @@ _do_pkg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_do_sql() {
|
_do_sql() {
|
||||||
_query="
|
|
||||||
WITH RECURSIVE pkg(x) AS (
|
# XXX: This lists all dependencies for the dependencies for the
|
||||||
SELECT \"$1\"
|
# dependencies. I haven't encountert an endless loop here (yet?).
|
||||||
UNION
|
# I guess sqlite takes care or that?
|
||||||
SELECT distinct fulldepends FROM depends
|
# I'm sure the performance can be improved by not using the big
|
||||||
JOIN pkg ON fullpkgpath=x WHERE type in ($2)
|
# ports view to grab the pkgname. But it's late and it works and
|
||||||
) SELECT x, fullpkgname FROM pkg
|
# this is a problem for another day.
|
||||||
JOIN ports ON fullpkgpath=x;
|
_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" \
|
sqlite3 "$_sqlports" "$_query" \
|
||||||
| cut -d: -f2
|
| cut -d: -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
_handle_list() {
|
_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" ]
|
if [ -z "$_deps" ]
|
||||||
then
|
then
|
||||||
_deps="0,1"
|
_deps="0,1"
|
||||||
@ -78,50 +92,73 @@ _handle_list() {
|
|||||||
| sed 's/^ //g' \
|
| sed 's/^ //g' \
|
||||||
| tr ' ' ',')"
|
| tr ' ' ',')"
|
||||||
fi
|
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
|
# download mode: create directory provided in -d <dir>
|
||||||
if [ -z "$_showmode" ] || [ "$_showmode" == "3" ]
|
if [ -n "$_dldir" ]
|
||||||
then
|
then
|
||||||
echo "$_portpath ($_pkgname) $_extra"
|
mkdir -p "$_dldir"
|
||||||
fi
|
fi
|
||||||
# pkgname only
|
|
||||||
if [ "$_showmode" == "1" ]
|
|
||||||
then
|
|
||||||
echo "$_pkgname $_extra"
|
|
||||||
fi
|
|
||||||
# portpath only
|
|
||||||
if [ "$_showmode" == "2" ]
|
|
||||||
then
|
|
||||||
echo "$_portpath $_extra"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$_dldir" ]
|
echo "Figuring out recursive dependencies, this may take some time..."
|
||||||
then
|
_do_sql "$1" "$_deps" | sort -u | while read line
|
||||||
mkdir -p "$_dldir"
|
do
|
||||||
ftp -MV -C -o $_dldir/$_pkgname.tgz $_pkgpath/$_pkgname.tgz
|
_portpath=$(echo "$line" | cut -d"|" -f1)
|
||||||
fi
|
_pkgname=$(echo "$line" | cut -d"|" -f2)
|
||||||
done
|
|
||||||
|
# download mode: -d <dir>
|
||||||
if [ -n "$_dldir" ]
|
if [ -n "$_dldir" ]
|
||||||
then
|
then
|
||||||
echo "Set the following environmane variables to enable offline installation:"
|
_extra="(downloading)"
|
||||||
echo "export TRUSTED_PKG_PATH=\"$(readlink -f "$_dldir")\""
|
|
||||||
echo "export PKG_PATH=\"$(readlink -f "$_dldir")\""
|
|
||||||
echo "pkg_add $_firstname"
|
|
||||||
fi
|
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
|
case "$1" in
|
||||||
*/*) _handle_list "$1" ;;
|
*/*) _handle_list "$1" ;;
|
||||||
*) _do_pkg "$1" ;;
|
*) _do_pkg "$1" ;;
|
||||||
|
Loading…
Reference in New Issue
Block a user