Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/clean-dependencies
blob: 63e9a9a41840faa740dcba8b12e022b74575f354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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 | \
  while read -r id path; do
    >&2 printf '.'
    infos=$(
      curl -Ss "https://pkgapi.archlinux32.org/$path"
    ) || \
      continue
    printf '%s\n' "${infos}" | \
      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 ] && [ "$1" = '-f' ]; then
    printf 'DELETE `dependencies`'
  else
    printf 'SELECT *'
  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