Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/wtf
blob: 247b3e34aece0d2c018ee0a6263957684483feaa (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
#!/bin/sh

# usage: wtf $file

# Find out what package provides the given file.
# $file may be a single file name or an absolute path.

# shellcheck source=../conf/default.conf
. "${0%/*}/../conf/default.conf"

hash=$(
  printf '%d' "0x$(
    printf '%s' "$*" | \
      sed '
        s,/$,,
        s,.*/,,
      ' | \
      sha224sum | \
      awk '{print $1}' | \
      cut -c 1-4
  )"
)

result=$(
  # shellcheck disable=SC2016
  {
    printf 'SELECT DISTINCT CONCAT(`repositories`.`name`,"/",'
    mysql_package_name_query
    printf ')'
    printf ' FROM `binary_packages`'
    mysql_join_binary_packages_architectures
    mysql_join_binary_packages_repositories
    mysql_join_binary_packages_file_providers
    mysql_join_file_providers_files
    printf ' WHERE `files`.`name_hash`=%s' \
      "${hash}"
    printf ' AND (`files`.`name`=from_base64("%s")' \
      "$(
        printf '%s' "$*" | \
          base64 -w0
      )"
    printf ' OR CONCAT(`files`.`path`,`files`.`name`)=from_base64("%s"))' \
      "$(
        printf '%s' "$*" | \
          base64 -w0
      )"
  } | \
    mysql_run_query
)

if [ -z "${result}" ]; then
  printf 'Huh, I don'"'"'t know that one.\n'
else
  printf '%s\n' "${result}"
fi