Open vermaden opened 1 year ago
This is the closest I was able to reach with some simple scripting:
echo
(
echo "REPO PRIORITY"
for REPO in /etc/pkg/* /usr/local/etc/pkg/repos/*
do
if grep -q -E 'enabled:[\ \t]*yes' "${REPO}"
then
awk -F ':' '/\{[\ \t]*$/ {printf("%s ",$1)}' "${REPO}"
if grep -q priority "${REPO}"
then
awk '/priority:/ {print $NF}' "${REPO}"
else
echo 'DEFAULT'
fi
fi
done
) | column -t
REPO PRIORITY
FreeBSD DEFAULT
Custom 100
Not sure this is the way this information should be gained ...
Regards, vermaden
The libpkg
API does support this:
pkg_repo* repo = NULL;
while (pkg_repos(&repo) == EPKG_OK) {
const char* id = pkg_repo_name (repo);
const char* descr = pkg_repo_url (repo);
bool enabled = pkg_repo_enabled (repo);
but I don't know if any of pkg
subcommands reports these.
Thank You for suggestion. My C is basic to say the least so I came up with what I know best - POSIX /bin/sh scripts - can be also used as functions if someone prefers them that way. I have made two variants.
SHOW ALL pkg(8) REPOS WITH STATUS
% ./pkg-repo-var-en.sh
REPO ENABLED PRIO URL
FreeBSD yes 0 pkg+http://pkg.FreeBSD.org/${ABI}/latest
Custom no 10 http://10.0.0.9/packages/Custom
pkg-repo-var-en.sh
#! /bin/sh
( # HEADER
echo -e "\nREPO ENABLED PRIO URL"
for REPO in /etc/pkg/* /usr/local/etc/pkg/repos/*
do
REPOCUR=$( grep '^[^#]' "${REPO}" )
# REPO
echo "${REPOCUR}" | awk -F ':' '/\{[\ \t]*$/ {printf(" %s ",$1)}'
# ENABLED
echo "${REPOCUR}" | awk '/enabled:/ {printf(" %s ",$NF)}' | tr -cd '[a-zA-Z ]'
# PRIO
if echo "${REPOCUR}" | grep -q priority
then
echo "${REPOCUR}" | awk '/priority:/ {printf(" %s ",$NF)}' | tr -cd '[0-9 ]'
else
echo -n " 0 "
fi
# URL
echo "${REPOCUR}" | grep '^[^#]' | awk -F'"' '/url:/ {print $2}' | tr -d ','
done 2> /dev/null
) | column -t 2> /dev/null
SHOW ONLY ENABLED pkg(8) REPOS
% ./pkg-repo-var.sh
REPO PRIO URL
FreeBSD 0 pkg+http://pkg.FreeBSD.org/${ABI}/latest
pkg-repo-var.sh
#! /bin/sh
( # HEADER
echo -e "\nREPO PRIO URL"
for REPO in /etc/pkg/* /usr/local/etc/pkg/repos/*
do
REPOCUR=$( grep '^[^#]' "${REPO}" )
# CHECK IF ENABLED
if echo "${REPOCUR}" | grep -q -E 'enabled:[\ \t]*yes'
then
# REPO
echo "${REPOCUR}" | awk -F ':' '/\{[\ \t]*$/ {printf(" %s ",$1)}'
# PRIO
if echo "${REPOCUR}" | grep -q priority
then
echo "${REPOCUR}" | awk '/priority:/ {printf(" %s ",$NF)}'
else
echo -n " 0 "
fi
# URL
echo "${REPOCUR}" | grep '^[^#]' | awk -F'"' '/url:/ {print $2}'
fi
done 2> /dev/null
) | column -t 2> /dev/null
Hope that helps someone.
Regards, vermaden
pkg -vv | sed '1, /^Repositories/d'
will at least crudely dump the repos pkg knows about without having to duplicate pkg's search logic.
But yes, introspection into pkg's configured state could be improved, I've run into problems in this general area before.
pkg -vv | sed '1, /^Repositories/d'
That's neat.
For support purposes I'm more lazy, I typically ask end users to run:
pkg -vv | grep -e url -e enabled -e priority
This one seems simpler/shorted to type:
% pkg -vv | grep -A 55 '^Repo'
Regards, vermaden
Hi.
I have added some additional repository to FreeBSD system.
What is the
pkg(8)
command to list repositories with their priorities?Something like
yum reposlist
on a Linux system as an example for what I am looking inpkg(8)
command.Thanks in advance.
Regards, vermaden