tazpkg view modules/list @ rev 828

Add modules "info", "list" with extended functions; update documentations and translations
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Aug 11 01:09:15 2015 +0300 (2015-08-11)
parents
children 48496086d8c9
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # list - TazPkg module
4 # Produce various lists
7 # Commands and options:
8 # blocked List of blocked packages
9 # categories List of categories
10 # linked List of linked packages
11 # installed List of installed packages
12 # installed_of_category <category> List of installed packages of asked category
13 # mirrored List packages available on the mirror
14 # mirrored --diff Last mirrored packages diff
15 # installed_files List files installed with the package
16 # activity TazPkg activity log
17 # activity --nb=30 Show asked number of lines of TazPkg activity log
18 # config_files [<package>] List configuration files installed
19 # config_files [<package>] --box List formatted for Yad-based TazPkg boxes
20 # suggested List of suggested packages (not installed only)
21 # suggested --all List of suggested packages (both installed and not installed)
24 # Connect function libraries
25 . /lib/libtaz.sh
26 # Get TazPkg configuration variables
27 . /etc/slitaz/slitaz.conf
28 . /etc/slitaz/tazpkg.conf
29 BLOCKED="$PKGS_DB/blocked-packages.list"
32 # Interactive mode
34 im() { tty -s; }
37 # Functions set for translate categories
38 # --------------------------------------
40 # Translate category names (must be last in line)
42 translate_category() {
43 sed "s|base-system$|$(_ base-system)|g; s|x-window$|$(_ x-window)|g;
44 s|utilities$|$(_ utilities)|g; s|network$|$(_ network)|g;
45 s|graphics$|$(_ graphics)|g; s|multimedia$|$(_ multimedia)|g;
46 s|office$|$(_ office)|g; s|development$|$(_ development)|g;
47 s|system-tools$|$(_ system-tools)|g; s|security$|$(_ security)|g;
48 s|games$|$(_ games)|g; s|misc$|$(_ misc)|g; s|meta$|$(_ meta)|g;
49 s|non-free$|$(_ non-free)|g"
50 }
53 # Make array of pre-translated categories
55 cat_i18n=''
56 for c in 'base-system' 'x-window' 'utilities' 'network' 'graphics' \
57 'multimedia' 'office' 'development' 'system-tools' 'security' 'games' \
58 'misc' 'meta' 'non-free'; do
59 cat_i18n="$cat_i18n
60 $(gettext "$c") $c"
61 done
64 # If category is not one of those translated in native language, keep it
65 # untranslated. This allows both native and English language support.
66 # This also supports custom categories.
67 # And now we support spaces in translated categories
69 reverse_translate_category() {
70 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
71 }
74 # Main code
75 # ---------
77 case $1 in
79 blocked)
80 # List of blocked packages
81 title 'Blocked packages'
83 if [ -s "$BLOCKED" ];then
84 cat $BLOCKED
85 num=$(wc -l < $BLOCKED)
86 footer "$(_p '%s package' '%s packages' "$num" \
87 "$(colorize 31 $num)")"
88 else
89 _ 'No blocked packages found.'; newline
90 fi
91 ;;
94 categories)
95 # List of categories
96 title 'Packages categories'
98 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
99 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
100 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
102 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
103 footer "$(_p '%s category' '%s categories' "$num" \
104 "$(colorize 33 $num)")"
105 ;;
108 linked)
109 # List of linked packages
110 title 'Linked packages'
112 linked="$(find $INSTALLED -type l -maxdepth 1)"
113 if [ -n "$linked" ]; then
114 for pkg in $linked; do
115 awk -F$'\t' -vp="$(basename "$pkg")" \
116 '($1==p){printf "%-34s %-17s %s\n", $1, $2, $3}' \
117 $PKGS_DB/installed.info | translate_category
118 done
119 num=$(echo "$linked" | wc -l)
120 footer "$(_p '%s package' '%s packages' "$num" \
121 "$(colorize 31 $num)")"
122 else
123 _ 'No linked packages found.'; newline
124 fi
125 ;;
128 installed)
129 # List of installed packages
130 title 'List of all installed packages'
132 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
133 $PKGS_DB/installed.info | translate_category
134 num=$(wc -l < $PKGS_DB/installed.info)
136 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
137 "$(colorize 32 $num)")"
138 ;;
141 installed_of_category)
142 # List of installed packages of asked category
143 shift
144 ASKED_CATEGORY_I18N="$@"
145 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
146 title 'Installed packages of category "%s"' "$ASKED_CATEGORY_I18N"
148 TMPLIST=$(mktemp)
149 awk -F$'\t' -vcat="$ASKED_CATEGORY" \
150 '{ if ($3 == cat) printf "%-34s %s\n", $1, $2; }' \
151 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
152 num=$(wc -l < $TMPLIST); rm $TMPLIST
154 footer "$(emsg $(_p \
155 '%s package installed of category "%s".' \
156 '%s packages installed of category "%s".' $num \
157 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
158 ;;
161 mirrored)
162 # List packages available on the mirror
163 # Option --diff displays last mirrored packages diff (see recharge).
164 check_for_packages_info
165 if [ -n "$diff" ]; then
166 if [ -f "$PKGS_DB/packages.diff" ]; then
167 title 'Mirrored packages diff'
168 cat $PKGS_DB/packages.diff
169 num=$(wc -l < $PKGS_DB/packages.diff)
170 footer "$(_p \
171 '%s new package listed on the mirror.' \
172 '%s new packages listed on the mirror.' "$num" \
173 "$(colorize 32 $num)")"
174 else
175 newline
176 _ 'Unable to list anything, no packages.diff found.'
177 _ 'Recharge your current list to create a first diff.'
178 newline
179 fi
180 else
181 title 'List of available packages on the mirror'
182 awk -F$'\t' '{
183 split($7, s, " ");
184 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
185 }' $PKGS_DB/packages.info
186 num=$(wc -l < $PKGS_DB/packages.info)
187 footer "$(_p \
188 '%s package in the last recharged list.' \
189 '%s packages in the last recharged list.' "$num" \
190 "$(colorize 32 $num)")"
191 fi
192 ;;
195 installed_files)
196 # List files installed with the package
197 PACKAGE="$2"
198 if [ -d "$INSTALLED/$PACKAGE" ]; then
199 # installed package
200 title 'Installed files by "%s"' "$PACKAGE"
201 sort < "$INSTALLED/$PACKAGE/files.list"
202 num=$(wc -l < "$INSTALLED/$PACKAGE/files.list")
203 footer "$(_p '%s file' '%s files' $num \
204 "$(colorize 32 $num)")"
205 elif [ -n "$(grep "^$PACKAGE"$'\t' $PKGS_DB/packages.info)" ]; then
206 # available package
207 title 'Installed files by "%s"' "$PACKAGE"
209 TMPLIST=$(mktemp)
210 lzcat $PKGS_DB/files.list.lzma | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee $TMPLIST
211 num=$(wc -l < $TMPLIST); rm $TMPLIST
213 footer "$(_p '%s file' '%s files' $num \
214 "$(colorize 32 $num)")"
215 else
216 newline
217 _ 'Package "%s" not available.' "$PACKAGE"
218 newline
219 fi
220 ;;
223 activity)
224 # Show activity log
225 [ -z "$nb" ] && nb='18'
226 title 'TazPkg Activity'
227 IFS=' '
228 tail -n $nb $LOG | tac | \
229 while read date hour none action none pkg vers none; do
230 case $action in
231 Installed)
232 action=$(colorize 32 $action) ;;
233 Removed)
234 action=$(colorize 31 $action) ;;
235 *)
236 action=$(boldify $action) ;;
237 esac
238 date_locale="$(date -d "$date $hour" '+%x %X')"
239 echo "$date_locale : $action $pkg $vers"
240 done
241 unset IFS
242 footer
243 ;;
246 config_files)
247 # List configuration files installed
248 # Option --box displays list formatted for Yad-based TazPkg boxes
249 if [ -n "$2" ]; then
250 FILES="$INSTALLED/$2/volatile.cpio.gz"
251 else
252 FILES="$INSTALLED/*/volatile.cpio.gz"
253 fi
255 if [ -n "$box" ]; then
256 TMP_DIR=$(mktemp -d)
258 for i in $FILES; do
259 mkdir -p $TMP_DIR/temp; cd $TMP_DIR/temp
261 zcat $i | cpio -idm --quiet >/dev/null
263 find . -type f 2>/dev/null | while read file; do
264 if [ ! -e /$file ]; then
265 echo -n "----------|----|----|$(_n 'File lost')"
266 else
267 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
268 cmp $file /$file >/dev/null 2>&1 || \
269 echo -n "$(stat -c "%.16y" /$file)"
270 fi
271 echo "|/$file"
272 done
273 rm -r $TMP_DIR/temp
274 done
275 cd "$TOP_DIR"
276 rm -r $TMP_DIR
277 else
278 im && title 'Configuration files'
279 for i in $FILES; do
280 [ -f "$i" ] || continue
281 zcat $i | cpio -t --quiet
282 done | sed 's|^|/|' | sort
283 im && footer
284 fi
285 ;;
288 suggested)
289 # List of suggested packages
290 # By default list only not installed suggested packages
291 # Option --all displays all (installed and not installed) suggested packages
292 for i in $(ls -d $INSTALLED/*/receipt); do
293 unset SUGGESTED
294 . $i
295 if [ -n "$SUGGESTED" ]; then
296 if [ -z "$all" ]; then
297 for s in $SUGGESTED; do
298 [ -d "$INSTALLED/$s" ] && \
299 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
300 done
301 fi
302 [ -n "$SUGGESTED" ] && cat <<EOT
303 $(boldify $(echo "$PACKAGE"):) $SUGGESTED
304 EOT
305 fi
306 done
307 ;;
309 esac
310 exit 0