-
Notifications
You must be signed in to change notification settings - Fork 60
/
xdeptree
executable file
·90 lines (73 loc) · 1.74 KB
/
xdeptree
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
#!/bin/bash
get_deps() {
local parents="$1" pkg="$2"
local -i lvl="$3"
local -a deps
parents="${parents:+$parents/}$pkg"
if (( MAXLVL > 0 && lvl >= MAXLVL )); then
echo "${parents}"
return
fi
if [ "${cache[$pkg]+_}" ]; then
read -r -a deps <<< "${cache[$pkg]}"
else
mapfile -t deps < <( xbps-query ${REPO:+$ADDREPO} -x "$pkg" | xargs -rn1 xbps-uhelper getpkgdepname )
cache[$pkg]="${deps[*]}"
fi
if [ "${#deps[@]}" -eq 0 ]; then
echo "${parents}"
fi
lvl=$(( lvl + 1 ))
for dep in "${deps[@]}"; do
get_deps "$parents" "$dep" "$lvl"
done
}
usage() {
echo "Usage: xdeptree [-L level] [-R] <pkgname>" >&2
}
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
ADDREPO="
--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
--repository=$XBPS_BINPKGS/nonfree
--repository=$XBPS_BINPKGS/multilib
--repository=$XBPS_BINPKGS/multilib/nonfree
--repository=$XBPS_BINPKGS/debug
"
declare -i MAXLVL=0
REPO=''
while getopts L:Rh flag; do
case "$flag" in
L)
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
usage; exit 1
fi
MAXLVL="$OPTARG"
;;
R) REPO=1 ;;
h) usage; exit 0 ;;
?) usage; exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
PKG="$1"
if [ -z "$PKG" ]; then
usage
exit 1
fi
if ! command -v tree >/dev/null 2>&1; then
echo "missing tree(1) command"
exit 1
fi
declare -A cache=()
get_deps '' "$PKG" 0 | sort -u | tree -n --noreport --fromfile .