blob: aff4512e479a8bc5e5b577fe74ee6a2c487cad8e (
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
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
|
#!/bin/sh
# list all available packages
#
list () {
find ${PACKAGES_DIR} -type f | sed "s,${PACKAGES_DIR}/,,"
}
# list installed packages
#
installed () {
ls -1 ${INSTALLED_DIR}
}
# list all packages and lable installed ones
#
list_installed () {
list | while read -r line; do
[ -d ${INSTALLED_DIR}/$line ] \
&& echo $line "[installed]" \
|| echo $line
done
}
# search for a package based on a query
#
search () {
if [ $# = 0 ]; then
list_installed
else
list_installed | grep $(echo $@ | sed "s/ /\\|/g")
fi
}
# list the files that belong to a package
#
files () {
for package in $@; do
local file="${INSTALLED_DIR}/$package/files"
[ -f $file ] && cat $file || >&2 printf "${RED}Package ${LIGHT_RED}$package${RED} is not installed\n"
done
}
# figure out which package a file belongs to
#
file_info () {
for file in $@; do
[ ! -f ${SYSROOT}$file ] && file=$(realpath $file 2>/dev/null)
local found=false
for pkg in $(installed); do
for list in ${INSTALLED_DIR}/$pkg/files; do
[ -f $list ] && {
grep -q "^/usr${file}$" $list || grep -q "^${file}$" $list && {
${QUIET} && echo $pkg || printf "${LIGHT_BLUE}%s${BLUE} belongs to ${LIGHT_BLUE}%s${RESET}\n" $file $pkg
found=true
}
}
done
done
$found || {
printf "${RED}$file does not belong to any package!\n" > /dev/stderr
return 1
}
done
}
# extract a variable from a package info
#
# extract_info [file] [FIELD]
#
extract_info () {
grep -i "^$2=" $1 | cut -d'=' -f2-
}
# pretty print a xipkg info file
#
print_info () {
file=$1
line="${LIGHT_CYAN}%-15s ${LIGHT_BLUE}%s\n"
for field in Name Description Version; do
printf "$line" "$field" "$(extract_info $file $field)"
done
printf "$line" "Dependencies" "$(extract_info $file "DEPS")"
printf "$line" "Build Date" "$(extract_info $file "DATE")"
is_installed $(extract_info $file "NAME") && {
date=$(date -d @$(stat -t $file | cut -d' ' -f13))
printf "$line" "Install Date" "$date"
} || true
}
# print information about one or more packages
#
info () {
for package in $@; do
infofile=${INSTALLED_DIR}/$package/info
[ -f $infofile ] && {
print_info $infofile
} || {
printf "Package info for $package could not be found!"
}
done
}
|