This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rpg-dependencies.sh
99 lines (88 loc) · 2.35 KB
/
rpg-dependencies.sh
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
#!/bin/sh
set -e
. rpg-sh-setup
test "$*" || set -- --help; ARGV="$@"
USAGE '${PROGNAME} [-r] [-t] [-p] <package> [<version>]
${PROGNAME} -a
Show package dependency information.
Options
-a Write dependency information for all installed packages
-r List dependencies recursively
-t List dependencies recursively in a tree
-p Include <package> name in output (default with -a)'
showall=false;recursive=false;tree=false;prefix=false
while getopts arpt opt
do
case $opt in
a) showall=true;;
r) recursive=true;;
p) prefix=true;;
t) tree=true;;
?) helpthem
exit 2;;
esac
done
shift $(( $OPTIND - 1 ))
# With -t and no package argument, show a tree of dependencies for all packages,
# rooted at packages no other package depends.
$tree && test -z "$*" && {
rpg leaves | xargs -n 1 -- "$0" $ARGV
exit
}
# With the `-a` argument, write all dependencies for all packages in the
# following format:
#
# <source> <package> <verspec> <version>
#
# Where `<source>` is the name of the package that has a dependency
# on `<package>`. The `<verspec>` may be any valid version expression:
# `<`, `<=`, `=`, `>=`, `>`, or `~>`.
$showall && {
test "$*" && { helpthem; exit 2; }
grep '^runtime ' "$RPGDB"/*/active/dependencies 2>/dev/null |
sed -e 's|^.*/\(.*\)/active/dependencies:runtime |\1 |'
exit 0
}
# Find the package and write its dependencies in this format:
#
# <package> <verspec> <version>
#
# Exit with failure if the package or package version is not found in the
# database.
package="$1"
version="${2:-active}"
packagedir="$RPGDB/$package"
test -d "$packagedir" || {
warn "package not found: $package"
exit 1
}
test -d "$packagedir/$version" || {
warn "package version not found: $package $version"
exit 1
}
sed -n 's|^runtime ||p' <"$packagedir/$version/dependencies" |
if $tree
then
while read pack spec vers
do
echo "$pack $spec $vers"
"$0" -r -t $pack |sed '
s/^/|-- /
s/-- |/ |/
'
done
else
if $recursive
then recurse="$0 -r"
$prefix && recurse="$recurse -p"
else recurse=true
fi
while read pack spec vers
do
output="$pack $spec $vers"
$prefix && output="$package $output"
echo "$output"
$recurse "$pack"
done |
sort -u
fi