spk view spk-ls @ rev 88

spk-ls: warm if missing receipt
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 25 02:41:36 2012 +0200 (2012-05-25)
parents a75380e9a681
children 50cd05f3fa15
line source
1 #!/bin/sh
2 #
3 # Spk-ls - List SliTaz packages and files. Read the README before adding or
4 # modifing any code in spk!
5 #
6 # Copyright (C) SliTaz GNU/Linux - BSD License
7 # Author: See AUTHORS files
8 #
9 . /usr/lib/slitaz/libspk.sh
11 #
12 # Functions
13 #
15 # Help and usage
16 usage() {
17 name=$(basename $0)
18 cat << EOT
20 $(boldify $(gettext "Usage:")) $name [packages|--options]
22 $(gettext "List packages or installed files by packages")
24 $(boldify $(gettext "Options:"))
25 --count $(gettext "Display the number of installed packages")
26 --mirror $(gettext "List all the packages on mirror")
27 --extra $(gettext "List packages on extra mirrors ")
28 --blocked $(gettext "List all blocked packages")
29 --short $(gettext "Short packages list format")
30 --modifiers $(gettext "List package modifiers")
31 --root= $(gettext "Set the root file system path")
32 --color=NB $(gettext "Set package name color in list")
33 --debug $(gettext "Display some useful debug information")
35 $(boldify $(gettext "Examples:"))
36 $name package1 package2 packageN
37 $name --short --color=33
39 EOT
40 exit 0
41 }
43 # Source a package receipt
44 source_receipt() {
45 local receipt=$1
46 if [ ! -f $receipt ]; then
47 echo -n $(colorize 31 "$pkg")
48 indent 28 $(gettext "missing receipt")
49 continue
50 else
51 . $receipt
52 fi
53 }
55 #
56 # Handle --options
57 #
59 for opt in $@
60 do
61 case "$opt" in
62 *usage|*help) usage ;;
63 --count)
64 count_installed
65 count_mirrored
66 exit 0 ;;
67 --mirror)
68 newline
69 boldify $(gettext "Mirror") $(cat $mirrorurl)
70 read_pkgsdesc $pkgsdesc
71 separator
72 boldify $(count_mirrored)
73 newline && exit 0 ;;
74 --extra)
75 [ -d "$extradb" ] || exit 1
76 for extra in $extradb/*
77 do
78 newline
79 boldify $(gettext "Extra mirror")
80 if [ ! -f "$extra/packages.desc" ]; then
81 echo "URL: $(cat $extra/mirror)"
82 gettext "Missing:"; colorize 31" packages.desc"
83 continue
84 fi
85 separator
86 read_pkgsdesc $extra/packages.desc
87 separator
88 boldify $(echo -n $(cat $extra/packages.$SUM | wc -l))
89 gettext "packages in:"; echo " $(basename $extra)"
90 newline
91 done
92 exit 0 ;;
93 --blocked)
94 if [ -s "$blocked" ]; then
95 cat $blocked
96 else
97 gettext "No blocked packages"; newline
98 fi
99 exit 0 ;;
100 --short)
101 newline
102 echo -n $(boldify $(gettext "Package"))
103 indent 28 $(boldify $(gettext "Version"))
104 separator
105 for pkg in $(ls -1 $installed)
106 do
107 source_receipt $installed/$pkg/receipt
108 echo -n "$(colorize 32 $pkg)"; indent 28 "$VERSION"
109 done
110 separator
111 boldify $(count_installed)
112 newline
113 exit 0 ;;
114 --*) continue ;;
115 *)
116 # List installed files by the package.
117 count=0
118 for pkg in $@
119 do
120 [ -f "$installed/$pkg/files.list" ] || continue
121 nb=$(cat $installed/$pkg/files.list | wc -l)
122 count=$(($count + 1))
123 [ "$count" == 1 ] && newline
124 # List modifiers
125 if [ "$modifiers" ]; then
126 modifiers=$installed/$pkg/modifiers
127 if [ -f "$modifiers" ]; then
128 boldify $(gettext "Modifiers for") $pkg
129 separator
130 cat $modifiers
131 separator && newline
132 else
133 echo $(boldify $pkg) $(gettext "package was not modified")
134 fi
135 continue
136 fi
137 boldify $(gettext "Installed files by") $pkg
138 separator
139 cat $installed/$pkg/files.list
140 separator
141 echo $(gettext "Installed files by") $pkg:
142 colorize 32 $nb && newline
143 done
144 exit 0 ;;
145 esac
146 done
148 #
149 # Parse all installed pkgs receipt.
150 #
152 count=0
154 newline
155 boldify $(gettext "Installed packages")
156 separator
157 for pkg in $installed/*
158 do
159 unset_receipt
160 . $pkg/receipt
161 count=$(($count + 1))
162 [ "$count" != 1 ] && newline
163 gettext "Package :"; colorize 32 " $PACKAGE"
164 receipt_info
165 done
166 separator
167 boldify $(count_installed) && newline
168 exit 0