summaryrefslogtreecommitdiff
path: root/bin/find-double-packages
blob: 1732b5bedadceae9ed6847657b9c8ab0888450ab (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
#!/bin/sh

# shellcheck disable=SC2119,SC2120

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

usage() {
  >&2 echo ''
  >&2 echo 'find-double-packages: find packages which are double on the mirror.'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -h|--help:'
  >&2 echo '    Show this help and exit.'
  >&2 echo '  -m|--mirror-dir location of the mirror files'
  [ -z "$1" ] && exit 1 || exit "$1"
}

eval set -- "$(
  getopt -o hm: \
    --long help \
    --long mirror: \
    -n "$(basename "$0")" -- "$@" || \
  echo usage
)"

mirror=''
no_action=false
wait_for_lock='-n'

while true
do
  case "$1" in
    -h|--help)
      usage 0
    ;;
    -m|--mirror)
      if [ -n "${mirror}" ]; then
        >&2 echo 'Already have one -m flag.'
        usage
      fi
      shift
      mirror="$1"
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 0 ]; then
  >&2 echo 'Too many arguments.'
  usage
fi

if [ -z "${mirror}" ]; then
  >&2 echo 'Flag -m missing'
  usage
fi

pooldir="${mirror}/pool"
poolfiles="/tmp/files_in_pool"
find "${pooldir}" -type f -name '*pkg.tar.xz' | \
	rev | cut -f 1 -d / | rev | sort >"${poolfiles}"

for arch in i486 i686 pentium4; do
  for repo in core extra community; do
    packagedir=${mirror}/${arch}/${repo}/
    find "$packagedir" -type l -name '*pkg.tar.xz' >"/tmp/files_in_repo_${arch}_${repo}"
  done
done