-
Notifications
You must be signed in to change notification settings - Fork 60
/
xpkgdiff
executable file
·121 lines (104 loc) · 3.15 KB
/
xpkgdiff
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
#!/bin/sh
# xpkgdiff [-r] [-R URL] [-a ARCH] [-f|-x [-t]|-S|-c FILE|-p PROP[,...]] PKG - compare PKG between remote to local repositories
usage() {
echo "Usage: xpkgdiff [-r] [-R URL] [-a ARCH] [-f|-x [-t]|-S|-c FILE|-p PROP[,...]] PKG"
exit 1
}
cleanup() {
rm -rf $TMPDIR
exit 0
}
: ${DIFF:="diff -u --color"}
: ${ARCH:=$XBPS_TARGET_ARCH}
# by default, don't sort
SORT='cat'
while getopts Sc:fhp:rtxa:R: flag; do
case $flag in
S) QUERY='--show' ;;
c) QUERY="--cat=$OPTARG" ;;
f) QUERY='--files'; SORT='sort' ;;
p) QUERY="--property $OPTARG" ;;
r) REVERSE=1 ;;
t) FULLTREE=1 ;;
x) QUERY='--deps'; SORT='sort' ;;
a) ARCH="$OPTARG" ;;
R) REMOTE_BASEURL="$OPTARG" ;;
h|?) usage ;;
esac
done
shift $(($OPTIND - 1))
[ "$#" -eq 0 ] && usage
[ -z "$QUERY" ] && usage
if [ -z "$ARCH" ]; then
# if arch is not set, just add the value of -R to the list
REMOTE_REPOS=" --repository=$REMOTE_BASEURL "
else
[ "$ARCH" != "$XBPS_TARGET_ARCH" ] && export XBPS_TARGET_ARCH="$ARCH"
: ${REMOTE_BASEURL:="https://repo-default.voidlinux.org/current"}
case "$ARCH" in
aarch64*)
REMOTE_BASEURL=${REMOTE_BASEURL%/}/aarch64;;
*-musl)
REMOTE_BASEURL=${REMOTE_BASEURL%/}/musl;;
*)
REMOTE_BASEURL=${REMOTE_BASEURL%/};;
esac
# if arch is set, add all the standard repos for that arch, and ignore conf repos
REMOTE_REPOS="
-i
--repository=$REMOTE_BASEURL/bootstrap
--repository=$REMOTE_BASEURL
--repository=$REMOTE_BASEURL/nonfree
--repository=$REMOTE_BASEURL/multilib
--repository=$REMOTE_BASEURL/multilib/nonfree
--repository=$REMOTE_BASEURL/debug
"
fi
TMPDIR=$(mktemp --tmpdir -d "xpkgdiff.XXXXX")
trap cleanup EXIT INT TERM
if [ "$QUERY" = '--deps' ] && [ -n "$FULLTREE" ]; then
QUERY='--fulldeptree --deps'
fi
BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null)
if [ -n "$XBPS_HOSTDIR" ]; then
XBPS_BINPKGS="$XBPS_HOSTDIR/binpkgs"
else
XBPS_DISTDIR="$(xdistdir 2>/dev/null)" || XBPS_DISTDIR=.
XBPS_BINPKGS="$XBPS_DISTDIR/hostdir/binpkgs"
fi
REPO="
--repository=$XBPS_BINPKGS/$BRANCH/bootstrap
--repository=$XBPS_BINPKGS/$BRANCH
--repository=$XBPS_BINPKGS/$BRANCH/nonfree
--repository=$XBPS_BINPKGS/$BRANCH/multilib
--repository=$XBPS_BINPKGS/$BRANCH/multilib/nonfree
--repository=$XBPS_BINPKGS/$BRANCH/debug
--repository=$XBPS_BINPKGS/bootstrap
--repository=$XBPS_BINPKGS
--repository=$XBPS_BINPKGS/nonfree
--repository=$XBPS_BINPKGS/multilib
--repository=$XBPS_BINPKGS/multilib/nonfree
--repository=$XBPS_BINPKGS/debug
"
pkg="$1"
if xbps-query -MR $REMOTE_REPOS $pkg >/dev/null; then
xbps-query -MR $REMOTE_REPOS $QUERY $pkg | $SORT > "$TMPDIR/${pkg}.repo"
else
echo "Package '$pkg' not found in repositories" > "$TMPDIR/${pkg}.repo"
fi
# ignore-conf-repos here and not in the actual query
# because --fulldeptree will probably fail without
# being able to read from other repos
if xbps-query --ignore-conf-repos $REPO $pkg >/dev/null; then
xbps-query $REPO $QUERY $pkg | $SORT > "$TMPDIR/${pkg}.local"
else
echo "Package '$pkg' not found in local repositories" > "$TMPDIR/${pkg}.local"
fi
if [ -z "$REVERSE" ]; then
FILE1="${pkg}.repo"
FILE2="${pkg}.local"
else
FILE1="${pkg}.local"
FILE2="${pkg}.repo"
fi
$DIFF $TMPDIR/$FILE1 $TMPDIR/$FILE2