summaryrefslogtreecommitdiff
path: root/find-package-differences
blob: fb5a48f84d6ddc8b9927b6091f1019d1af760d02 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash

if [ $# -eq 2 ]; then
  cd "${1}"
  if [ ! -f '.SRCINFO' ] ||
    [ "$(stat -c%Y PKGBUILD)" -gt "$(stat -c%Y .SRCINFO)" ]; then
    makepkg --printsrcinfo > .SRCINFO
  fi
  sed '
    /^\S/ b
    /^\s\+\(arch\|epoch\|pkgver\|pkgrel\) = \S/ b
    /^$/ b
    d
  ' '.SRCINFO' \
  > "${2}"
  all=$(
    sed -n '
      /^pkgbase = /,/^$/ {
        /^\s/ p
      }
    ' "${2}" \
    | sed '
      $! s/$/\\/
    '
  )
  all_noarch=$(
    printf '%s\n' "${all}" \
    | grep -v '^\sarch = ' \
    | sed '
      $ s/\\$//
    '
  )
  sed -i '
    /^pkgbase = /,/^$/ d
    /^pkgname = / {
      :a
        N
        /\n$/ ! ba
      /\n\sarch = / {
        a\
'"${all_noarch}"'
        b
      }
      a\
'"${all}"'
    }
  ' "${2}"
  sed -i '
    /^\s*$/d
  ' "${2}"
  exit
fi

if [ $# -ne 0 ]; then
  >&2 echo 'usage error'
  >&2 printf '"%s" ' "$@"
  >&2 printf '\n'
  exit 1
fi

if ! mountpoint -q /mnt/archlinuxewe \
&& ! ls /mnt/archlinuxewe | grep -qF ''; then
  >&2 printf '/mnt/archlinuxewe is empty\n'
  exit 1
fi

tmp_dir=$(mktemp -d)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

find "$(pwd)" -maxdepth 2 -mindepth 2 -name 'PKGBUILD' -type f \
| sed -n '
  s@/[^/]\+$@@
  T
  s@/[^/]\+$@\0\n'"${tmp_dir%/}"'\0.srcinfo@
  T
  p
' \
| parallel -j0 -L2 "$0"

print_names() {
  if [ -z "${pkgname}" ] \
  || [ -z "${pkgver}" ] \
  || [ -z "${pkgrel}" ]; then
    >&2 echo 'error: some variable is missing'
    exit 1
  fi
  for arch in "${archs[@]}"; do
    printf '%s-%s%s-%s-%s.pkg.tar.xz\n' \
      "${pkgname}" \
      "${epoch:+${epoch}:}" \
      "${pkgver}" \
      "${pkgrel}" \
      "${arch}"
  done
}

diff -u --color <(
  find /mnt/archlinuxewe -type f -name '*.pkg.tar.xz' -printf '%f\n' \
  | sort -u
) <(
  find "$tmp_dir" -name '*.srcinfo' -exec cat {} + \
  | {
    while read key eq value; do
      if [ "x${eq}" != 'x=' ]; then
        >&2 echo "syntax error"
        exit 1
      fi
      case "${key}" in
        'pkgname')
          if [ -n "${pkgname}" ]; then
            print_names
          fi
          archs=()
          pkgname="${value}"
          unset epoch
          unset pkgver
          unset pkgrel
        ;;
        'arch')
          archs+=("${value}")
        ;;
        'epoch')
          epoch="${value}"
        ;;
        'pkgver')
          pkgver="${value}"
        ;;
        'pkgrel')
          pkgrel="${value}"
        ;;
        *)
          >&2 printf 'unknown key "%s"\n' "${key}"
          exit 1
        ;;
      esac
    done
    if [ -n "${pkgname}" ]; then
      print_names
    fi
  } \
  | sort -u
)