From 93bb4be796e1daa43721121b1d08eb1aaad698ed Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 21 Jan 2019 12:31:15 +0100 Subject: bin/clean-dependencies new --- bin/clean-dependencies | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 bin/clean-dependencies (limited to 'bin') diff --git a/bin/clean-dependencies b/bin/clean-dependencies new file mode 100755 index 0000000..a9105fb --- /dev/null +++ b/bin/clean-dependencies @@ -0,0 +1,85 @@ +#!/bin/bash + +# remove run-time dependencies from the database which are not recorded +# in the package itself + +# This should only be run manually, as it cleans something, that should +# never get dirty in the first place! + +# It only shows what is superfluid - unless "-f" is provided. + +# shellcheck source=../lib/load-configuration +. "${0%/*}/../lib/load-configuration" + +deps_file=$(mktemp 'tmp.clean-dependencies.XXXXXXXXXX' --tmpdir) +trap 'rm "${deps_file}"' EXIT + +# shellcheck disable=2016 +{ + printf 'SELECT DISTINCT `binary_packages`.`id`,' + printf 'CONCAT(' + printf '`architectures`.`name`,"/",' + printf '`repositories`.`name`,"/",' + printf '`binary_packages`.`pkgname`)' + printf ' FROM `binary_packages`' + mysql_join_binary_packages_binary_packages_in_repositories + mysql_join_binary_packages_in_repositories_repositories + printf ' AND `repositories`.`is_on_master_mirror`' + mysql_join_repositories_architectures + mysql_join_binary_packages_dependencies + mysql_join_dependencies_dependency_types + printf ' AND `dependency_types`.`relevant_for_binary_packages`' + printf ' AND `dependency_types`.`relevant_for_building`' + mysql_join_dependencies_install_targets + printf ' AND `install_targets`.`name` NOT IN ("base","base-devel");\n' +} | \ + mysql_run_query | \ + pv --line-mode | \ + while read -r id path; do + curl -Ss "https://pkgapi.archlinux32.org/$path" | \ + sed ' + s/^.*"Requires":\("[^"]\+"\|\[[^[]]\+\]\).*$/\1/ + t + d + ' | \ + tr '"[],' '\n' | \ + grep -vxF '' | \ + sed 's/^/'"${id}"'\t/' + printf '%s\tbase\n' "${id}" + done > \ + "${deps_file}" + +# shellcheck disable=2016 +{ + printf 'CREATE TEMPORARY TABLE `deps`(' + printf '`bp` BIGINT,' + printf '`dep` VARCHAR(128),' + printf 'UNIQUE KEY `content`(`bp`,`dep`));\n' + printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `deps`(`bp`,`dep`);\n' \ + "${deps_file}" + printf 'CREATE TEMPORARY TABLE `bps`(' + printf '`bp` BIGINT,' + printf 'UNIQUE KEY `bp`(`bp`));\n' + printf 'INSERT IGNORE INTO `bps`(`bp`)' + printf ' SELECT `deps`.`bp`' + printf ' FROM `deps`;\n' + if [ $# -eq 1 ] && [ "x$1" = 'x-f' ]; then + printf 'DELETE `dependencies`' + else + printf 'SELECT *' + printf ' FROM `dependencies`' + fi + printf ' FROM `bps`' + printf ' JOIN `dependencies`' + printf ' ON `dependencies`.`dependent`=`bps`.`bp`' + mysql_join_dependencies_dependency_types + printf ' AND `dependency_types`.`relevant_for_binary_packages`' + printf ' AND `dependency_types`.`relevant_for_building`' + mysql_join_dependencies_install_targets + printf ' AND `install_targets`.`name` NOT IN ("base","base-devel")' + printf ' LEFT JOIN `deps`' + printf ' ON `deps`.`dep`=`install_targets`.`name`' + printf ' AND `deps`.`bp`=`dependencies`.`dependent`' + printf ' WHERE `deps`.`dep` IS NULL;\n' +} | \ + mysql_run_query -- cgit v1.2.3-70-g09d2