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,58 +382,62 @@ func_defined clean_all || clean_all() {
done done
} }
addtodb() { addtodb() {
if [ -n "$(package_install_state $port $version)" ]; then
echo "Note: $port $version already installed."
return
fi
echo "Adding $port $version to database of installed ports..."
if [ "${1:-}" = "--auto" ]; then
echo "auto $port $version" >> "$packagesdb"
else
echo "manual $port $version" >> "$packagesdb"
fi
if [ "${#depends[@]}" -gt 0 ]; then
echo "dependency $port ${depends[@]}" >> "$packagesdb"
fi
echo "Successfully installed $port $version."
}
ensure_packagesdb() {
if [ ! -f "$packagesdb" ]; then if [ ! -f "$packagesdb" ]; then
echo "Note: $packagesdb does not exist. Creating." mkdir -p "$(dirname $packagesdb)"
mkdir -p "${DESTDIR}/usr/Ports/"
touch "$packagesdb" touch "$packagesdb"
fi fi
if ! grep -E "^(auto|manual) $port $version" "$packagesdb" > /dev/null; then }
echo "Adding $port $version to database of installed ports..." package_install_state() {
if [ "${1:-}" = "--auto" ]; then local port=$1
echo "auto $port $version" >> "$packagesdb" local version=${2:-}
else
echo "manual $port $version" >> "$packagesdb" ensure_packagesdb
if [ ! -z "${dependlist:-}" ]; then grep -E "^(auto|manual) $port $version" "$packagesdb" | cut -d' ' -f1
echo "dependency $port$dependlist" >> "$packagesdb"
fi
fi
echo "Successfully installed $port $version."
else
>&2 echo "Warning: $port $version already installed. Not adding to database of installed ports!"
fi
} }
installdepends() { installdepends() {
for depend in "${depends[@]}"; do for depend in "${depends[@]}"; do
dependlist="${dependlist:-} $depend" if [ -z "$(package_install_state $depend)" ]; then
done
for depend in "${depends[@]}"; do
if ! grep "$depend" "$packagesdb" > /dev/null; then
(cd "../$depend" && ./package.sh --auto) (cd "../$depend" && ./package.sh --auto)
fi fi
done done
} }
uninstall() { uninstall() {
if grep "^manual $port " "$packagesdb" > /dev/null; then if [ "$(package_install_state $port)" != "manual" ]; then
if [ -f plist ]; then
for f in `cat plist`; do
case $f in
*/)
run rmdir "${DESTDIR}/$f" || true
;;
*)
run rm -rf "${DESTDIR}/$f"
;;
esac
done
# 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." >&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 fi
for f in `cat plist`; do
case $f in
*/)
run rmdir "${DESTDIR}/$f" || true
;;
*)
run rm -rf "${DESTDIR}/$f"
;;
esac
done
# 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"
} }
do_installdepends() { do_installdepends() {
echo "Installing dependencies of $port..." echo "Installing dependencies of $port..."