Ports: Register all dependencies of ports

Previously, only `manual` installs would register dependencies of an
installed port package. Since in the future we might want to check all
dependents, not only those for manually installed packages, we should
take care to register dependencies for `auto` installs as well.

Additionally, this surpresses some unnecessary verbose output from the
package management and fixes warnings when the package DB directory did
not yet exist.
This commit is contained in:
Jelle Raaijmakers 2021-10-20 00:14:54 +02:00 committed by Linus Groh
parent 7ff99cb516
commit 28e0aa59a8
Notes: sideshowbarker 2024-07-18 02:06:02 +09:00

View file

@ -382,39 +382,49 @@ func_defined clean_all || clean_all() {
done
}
addtodb() {
if [ ! -f "$packagesdb" ]; then
echo "Note: $packagesdb does not exist. Creating."
mkdir -p "${DESTDIR}/usr/Ports/"
touch "$packagesdb"
if [ -n "$(package_install_state $port $version)" ]; then
echo "Note: $port $version already installed."
return
fi
if ! grep -E "^(auto|manual) $port $version" "$packagesdb" > /dev/null; then
echo "Adding $port $version to database of installed ports..."
if [ "${1:-}" = "--auto" ]; then
echo "auto $port $version" >> "$packagesdb"
else
echo "manual $port $version" >> "$packagesdb"
if [ ! -z "${dependlist:-}" ]; then
echo "dependency $port$dependlist" >> "$packagesdb"
fi
if [ "${#depends[@]}" -gt 0 ]; then
echo "dependency $port ${depends[@]}" >> "$packagesdb"
fi
echo "Successfully installed $port $version."
else
>&2 echo "Warning: $port $version already installed. Not adding to database of installed ports!"
}
ensure_packagesdb() {
if [ ! -f "$packagesdb" ]; then
mkdir -p "$(dirname $packagesdb)"
touch "$packagesdb"
fi
}
package_install_state() {
local port=$1
local version=${2:-}
ensure_packagesdb
grep -E "^(auto|manual) $port $version" "$packagesdb" | cut -d' ' -f1
}
installdepends() {
for depend in "${depends[@]}"; do
dependlist="${dependlist:-} $depend"
done
for depend in "${depends[@]}"; do
if ! grep "$depend" "$packagesdb" > /dev/null; then
if [ -z "$(package_install_state $depend)" ]; then
(cd "../$depend" && ./package.sh --auto)
fi
done
}
uninstall() {
if grep "^manual $port " "$packagesdb" > /dev/null; then
if [ -f plist ]; then
if [ "$(package_install_state $port)" != "manual" ]; then
>&2 echo "Error: $port is not installed. Cannot uninstall."
return
elif [ ! -f plist ]; then
>&2 echo "Error: This port does not have a plist yet. Cannot uninstall."
return
fi
for f in `cat plist`; do
case $f in
*/)
@ -428,12 +438,6 @@ uninstall() {
# Without || true, mv will not be executed if you are uninstalling your only remaining port.
grep -v "^manual $port " "$packagesdb" > packages.db.tmp || true
mv packages.db.tmp "$packagesdb"
else
>&2 echo "Error: This port does not have a plist yet. Cannot uninstall."
fi
else
>&2 echo "Error: $port is not installed. Cannot uninstall."
fi
}
do_installdepends() {
echo "Installing dependencies of $port..."