-
Notifications
You must be signed in to change notification settings - Fork 2
/
portz_find_pkg
executable file
·96 lines (90 loc) · 2.44 KB
/
portz_find_pkg
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
#!/usr/bin/env bash
PNAME=portz_find_pkg
set -e
portz_libdir=${portz_libdir-`pwd`}
. ${portz_libdir}/scripts/runtime.sh
. ${portz_scripts}/functions.sh
log_quiet=1
. ${portz_scripts}/build_defs.sh
log_quiet=0
. ${portz_scripts}/package_defs.sh
abspath()
{
if test -z "$1"
then
return
fi
if [ -d "$1" ] ; then
(
cd $1
pwd
)
else
local dir="$(dirname "$1")"
local name="$(basename "$1")"
(
cd $dir
echo "`pwd`/$name"
)
fi
}
find_lib_portz()
{
local potential_prefix="$(dirname $1)"
while [ "$potential_prefix" != "/" ]
do
local potential_prefix_abs="$(abspath $potential_prefix)"
if [ -d "$potential_prefix_abs/lib/portz" ]
then
echo "$potential_prefix_abs"
fi
if [ "$potential_prefix_abs" = "/" ] ; then
break
fi
potential_prefix="$potential_prefix_abs/.."
done
}
shopt -s nullglob
for f in "$@" ; do
known=0
new_roots="$(find_lib_portz $f)"
fa="$(abspath $f)"
for root in $new_roots ; do
for manifest_file in $root/lib/portz/*.MANIFEST ; do
package_name="$(basename $manifest_file | sed -e 's/.MANIFEST$//')"
pkginfo="$(dirname $manifest_file)/${package_name}.PKGINFO"
package_version=""
# there are two formats of MANIFEST
# relative to ${prefix}
# bin/goo
# lib/libfoo.so
# ...
# absolute, starting with ./
# ./opt/foo/bin/goo
# ./opt/foo/lib/libfoo.so
if portz_list_files_from_manifest $manifest_file | egrep -q "^$fa"
then
echo "$fa $pkginfo"
known=1
fi
done
done
if [ $known = 0 ] ; then
echo "$fa -"
fi
done | while read file pkginfo ; do
if [ "$pkginfo" != - ] ; then
if [ -f "$pkginfo" ] ; then
package_name="$(cat $pkginfo | grep "^name=" | cut -d= -f2)"
package_version="$(cat $pkginfo | grep "^version=" | cut -d= -f2)"
package_version="${package_version--}"
else
package_name="$(basename $pkginfo | sed -e 's|.PKGINFO$||')"
package_version=-
fi
root="$(abspath $(dirname $pkginfo)/../../)"
echo "$file $package_name $package_version $root"
else
echo "$file - - -"
fi
done