spk view spk-ls @ rev 161

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 12:27:19 2019 +0100 (2019-02-26)
parents 9378152c7e2c
children
line source
1 #!/bin/sh
2 #
3 # Spk-ls - List SliTaz packages and files. Read the README before adding or
4 # modifying 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 #
44 # Handle --options
45 #
47 for opt in $@
48 do
49 case "$opt" in
50 *usage|*help) usage ;;
51 --count)
52 count_installed
53 count_mirrored
54 exit 0 ;;
55 --mirror)
56 newline
57 boldify $(gettext "Mirror") $(cat $mirrorurl)
58 separator
59 read_pkgsdesc $pkgsdesc
60 separator
61 boldify $(count_mirrored)
62 newline && exit 0 ;;
63 --extra)
64 [ -d "$extradb" ] || exit 1
65 for extra in $extradb/*
66 do
67 newline
68 boldify $(gettext "Extra mirror")
69 if [ ! -f "$extra/packages.desc" ]; then
70 echo "URL: $(cat $extra/mirror)"
71 gettext "Missing:"; colorize 31 " packages.desc"
72 continue
73 fi
74 separator
75 read_pkgsdesc $extra/packages.desc
76 separator
77 boldify $(echo -n $(cat $extra/packages.$SUM | wc -l))
78 gettext "packages in:"; echo " $(basename $extra)"
79 newline
80 done
81 exit 0 ;;
82 --blocked)
83 if [ -s "$blocked" ]; then
84 cat $blocked
85 else
86 gettext "No blocked packages"; newline
87 fi
88 exit 0 ;;
89 --short)
90 newline
91 echo -n $(boldify $(gettext "Package"))
92 indent 28 $(boldify $(gettext "Version"))
93 separator
94 for pkg in $(ls -1 $installed)
95 do
96 source_receipt $installed/$pkg/receipt
97 echo $(colorize 32 $pkg) $(indent 28 "$VERSION")
98 done
99 separator
100 boldify $(count_installed)
101 newline
102 exit 0 ;;
103 --*) continue ;;
104 *)
105 # List installed files by the package.
106 count=0
107 for pkg in $@
108 do
109 [ -f "$installed/$pkg/files.list" ] || continue
110 nb=$(cat $installed/$pkg/files.list | wc -l)
111 count=$(($count + 1))
112 [ "$count" = 1 ] && newline
113 # List modifiers
114 if [ "$modifiers" ]; then
115 modifiers=$installed/$pkg/modifiers
116 if [ -f "$modifiers" ]; then
117 boldify $(gettext "Modifiers for") $pkg
118 separator
119 cat $modifiers
120 separator && newline
121 else
122 echo $(boldify $pkg) $(gettext "package was not modified")
123 fi
124 continue
125 fi
126 boldify $(gettext "Installed files by") $pkg
127 separator
128 cat $installed/$pkg/files.list
129 separator
130 gettext "Installed files by"; echo -n " $pkg: "
131 colorize 32 "$nb" && newline
132 done
133 exit 0 ;;
134 esac
135 done
137 #
138 # Parse all installed pkgs receipt.
139 #
141 count=0
143 newline
144 boldify $(gettext "Installed packages")
145 separator
146 for pkg in $installed/*
147 do
148 unset_receipt
149 source_receipt $pkg/receipt
150 count=$(($count + 1))
151 [ "$count" != 1 ] && newline
152 gettext "Package :"; colorize 32 " $PACKAGE"
153 receipt_info
154 done
155 separator
156 boldify $(count_installed) && newline
157 exit 0