summaryrefslogtreecommitdiff
path: root/bin/clean-dependencies
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-01-21 12:31:15 +0100
committerErich Eckner <git@eckner.net>2019-01-21 12:31:15 +0100
commit93bb4be796e1daa43721121b1d08eb1aaad698ed (patch)
tree2d078d63705f2634ffa803491cf77fe35f443ddf /bin/clean-dependencies
parent23e12786bf89a2bd3684f04d0ac4586df06b1edc (diff)
downloadbuilder-93bb4be796e1daa43721121b1d08eb1aaad698ed.tar.xz
bin/clean-dependencies new
Diffstat (limited to 'bin/clean-dependencies')
-rwxr-xr-xbin/clean-dependencies85
1 files changed, 85 insertions, 0 deletions
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