spk view spk-ls @ rev 95
spk-up: improve extra local package
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 25 16:42:10 2012 +0200 (2012-05-25) |
parents | b84e0d36c9e0 |
children | f017035fd1f5 |
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 separator
71 read_pkgsdesc $pkgsdesc
72 separator
73 boldify $(count_mirrored)
74 newline && exit 0 ;;
75 --extra)
76 [ -d "$extradb" ] || exit 1
77 for extra in $extradb/*
78 do
79 newline
80 boldify $(gettext "Extra mirror")
81 if [ ! -f "$extra/packages.desc" ]; then
82 echo "URL: $(cat $extra/mirror)"
83 gettext "Missing:"; colorize 31" packages.desc"
84 continue
85 fi
86 separator
87 read_pkgsdesc $extra/packages.desc
88 separator
89 boldify $(echo -n $(cat $extra/packages.$SUM | wc -l))
90 gettext "packages in:"; echo " $(basename $extra)"
91 newline
92 done
93 exit 0 ;;
94 --blocked)
95 if [ -s "$blocked" ]; then
96 cat $blocked
97 else
98 gettext "No blocked packages"; newline
99 fi
100 exit 0 ;;
101 --short)
102 newline
103 echo -n $(boldify $(gettext "Package"))
104 indent 28 $(boldify $(gettext "Version"))
105 separator
106 for pkg in $(ls -1 $installed)
107 do
108 source_receipt $installed/$pkg/receipt
109 echo -n "$(colorize 32 $pkg)"; indent 28 "$VERSION"
110 done
111 separator
112 boldify $(count_installed)
113 newline
114 exit 0 ;;
115 --*) continue ;;
116 *)
117 # List installed files by the package.
118 count=0
119 for pkg in $@
120 do
121 [ -f "$installed/$pkg/files.list" ] || continue
122 nb=$(cat $installed/$pkg/files.list | wc -l)
123 count=$(($count + 1))
124 [ "$count" == 1 ] && newline
125 # List modifiers
126 if [ "$modifiers" ]; then
127 modifiers=$installed/$pkg/modifiers
128 if [ -f "$modifiers" ]; then
129 boldify $(gettext "Modifiers for") $pkg
130 separator
131 cat $modifiers
132 separator && newline
133 else
134 echo $(boldify $pkg) $(gettext "package was not modified")
135 fi
136 continue
137 fi
138 boldify $(gettext "Installed files by") $pkg
139 separator
140 cat $installed/$pkg/files.list
141 separator
142 echo -n "$(gettext "Installed files by") $pkg: "
143 colorize 32 "$nb" && newline
144 done
145 exit 0 ;;
146 esac
147 done
149 #
150 # Parse all installed pkgs receipt.
151 #
153 count=0
155 newline
156 boldify $(gettext "Installed packages")
157 separator
158 for pkg in $installed/*
159 do
160 unset_receipt
161 . $pkg/receipt
162 count=$(($count + 1))
163 [ "$count" != 1 ] && newline
164 gettext "Package :"; colorize 32 " $PACKAGE"
165 receipt_info
166 done
167 separator
168 boldify $(count_installed) && newline
169 exit 0