tazpkg view modules/list @ rev 931

Add module/bb: manage Busybox applets.
Remove function definitions that are now in the /lib/libtaz.sh (die, im).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jan 08 11:24:12 2017 +0200 (2017-01-08)
parents a02e36d44d06
children
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
27 # Get TazPkg working environment
28 . @@MODULES@@/getenv
33 # Functions set for translate categories
34 # --------------------------------------
36 # Translate category names (must be last in line)
38 translate_category() {
39 sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|;
40 s|utilities$|$(_ utilities)|; s|network$|$(_ network)|;
41 s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|;
42 s|office$|$(_ office)|; s|development$|$(_ development)|;
43 s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|;
44 s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|;
45 s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|"
46 }
49 # Make array of pre-translated categories
51 cat_i18n=''
52 for c in 'base-system' 'x-window' 'utilities' 'network' 'graphics' \
53 'multimedia' 'office' 'development' 'system-tools' 'security' 'games' \
54 'misc' 'meta' 'non-free'; do
55 cat_i18n="$cat_i18n
56 $(gettext "$c") $c"
57 done
60 # If category is not one of those translated in native language, keep it
61 # untranslated. This allows both native and English language support.
62 # This also supports custom categories.
63 # And now we support spaces in translated categories
65 reverse_translate_category() {
66 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
67 }
70 # Main code
71 # ---------
73 case $1 in
75 blocked)
76 # List of blocked packages
77 title 'Blocked packages'
79 if [ -s "$BLOCKED" ];then
80 cat "$BLOCKED"
81 num=$(wc -l < "$BLOCKED")
82 footer "$(_p '%s package' '%s packages' "$num" \
83 "$(colorize 31 $num)")"
84 else
85 _ 'No blocked packages found.'; newline
86 fi
87 ;;
90 categories)
91 # List of categories
92 title 'Packages categories'
94 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
95 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
96 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
98 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
99 footer "$(_p '%s category' '%s categories' "$num" \
100 "$(colorize 33 $num)")"
101 ;;
104 linked)
105 # List of linked packages
106 title 'Linked packages'
108 linked="$(find "$INSTALLED" -type l -maxdepth 1)"
109 if [ -n "$linked" ]; then
110 for pkg in $linked; do
111 awk -F$'\t' -vp="$(basename "$pkg")" \
112 '$1==p{printf "%-34s %-17s %s\n", $1, $2, $3}' \
113 "$PKGS_DB/installed.info" | translate_category
114 done
115 num=$(echo "$linked" | wc -l)
116 footer "$(_p '%s package' '%s packages' "$num" \
117 "$(colorize 31 $num)")"
118 else
119 _ 'No linked packages found.'; newline
120 fi
121 ;;
124 installed)
125 # List of installed packages
126 title 'List of all installed packages'
128 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
129 "$PKGS_DB/installed.info" | translate_category
130 num=$(wc -l < "$PKGS_DB/installed.info")
132 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
133 "$(colorize 32 $num)")"
134 ;;
137 installed_of_category)
138 # List of installed packages of asked category
139 shift
140 ASKED_CATEGORY_I18N="$@"
141 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
142 title 'Installed packages of category "%s"' "$ASKED_CATEGORY_I18N"
144 TMPLIST=$(mktemp)
145 awk -F$'\t' -vcat="$ASKED_CATEGORY" \
146 '$3==cat{printf "%-34s %s\n", $1, $2}' \
147 "$PKGS_DB/installed.info" | tee "$TMPLIST" | translate_category
148 num=$(wc -l < "$TMPLIST"); rm "$TMPLIST"
150 footer "$(emsg $(_p \
151 '%s package installed of category "%s".' \
152 '%s packages installed of category "%s".' $num \
153 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
154 ;;
157 mirrored)
158 # List packages available on the mirror
159 # Option --diff displays last mirrored packages diff (see recharge).
160 if [ -n "$diff" ]; then
161 if [ -f "$PKGS_DB/packages.diff" ]; then
162 title 'Mirrored packages diff'
163 cat "$PKGS_DB/packages.diff"
164 num=$(wc -l < "$PKGS_DB/packages.diff")
165 footer "$(_p \
166 '%s new package listed on the mirror.' \
167 '%s new packages listed on the mirror.' "$num" \
168 "$(colorize 32 $num)")"
169 else
170 newline
171 _ 'Unable to list anything, no packages.diff found.'
172 _ 'Recharge your current list to create a first diff.'
173 newline
174 fi
175 else
176 title 'List of available packages on the mirror'
177 awk -F$'\t' '{
178 split($7, s, " ");
179 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
180 }' "$PKGS_DB/packages.info"
181 num=$(wc -l < "$PKGS_DB/packages.info")
182 footer "$(_p \
183 '%s package in the last recharged list.' \
184 '%s packages in the last recharged list.' "$num" \
185 "$(colorize 32 $num)")"
186 fi
187 ;;
190 installed_files)
191 # List files installed with the package
192 PACKAGE="$2"
193 if [ -d "$INSTALLED/$PACKAGE" ]; then
194 # installed package
195 title 'Installed files by "%s"' "$PACKAGE"
196 sort < "$INSTALLED/$PACKAGE/files.list"
197 num=$(wc -l < "$INSTALLED/$PACKAGE/files.list")
198 footer "$(_p '%s file' '%s files' $num \
199 "$(colorize 32 $num)")"
200 elif [ -n "$(grep "^$PACKAGE"$'\t' "$PKGS_DB/packages.info")" ]; then
201 # available package
202 title 'Installed files by "%s"' "$PACKAGE"
204 TMPLIST=$(mktemp)
205 lzcat "$PKGS_DB/files.list.lzma" | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee "$TMPLIST"
206 num=$(wc -l < "$TMPLIST"); rm "$TMPLIST"
208 footer "$(_p '%s file' '%s files' $num \
209 "$(colorize 32 $num)")"
210 else
211 newline
212 _ 'Package "%s" not available.' "$PACKAGE"
213 newline
214 fi
215 ;;
218 activity)
219 # Show activity log
220 : ${nb=18}
221 title 'TazPkg Activity'
222 IFS=' '
223 tail -n $nb "$LOG" | tac | \
224 while read date hour none action none pkg vers none; do
225 case $action in
226 Installed)
227 action=$(colorize 32 $action) ;;
228 Removed)
229 action=$(colorize 31 $action) ;;
230 *)
231 action=$(boldify $action) ;;
232 esac
233 date_locale="$(date -d "$date $hour" '+%x %X')"
234 echo "$date_locale : $action $pkg $vers"
235 done
236 unset IFS
237 footer
238 ;;
241 config_files)
242 # List configuration files installed
243 # Option --box displays list formatted for Yad-based TazPkg boxes
244 FILES="$INSTALLED/${2:-*}/volatile.cpio.gz"
246 if [ -n "$box" ]; then
247 TMP_DIR=$(mktemp -d)
249 for i in $FILES; do
250 mkdir -p "$TMP_DIR/temp"; cd "$TMP_DIR/temp"
252 zcat $i | cpio -idm --quiet >/dev/null
254 find . -type f 2>/dev/null | while read file; do
255 if [ ! -e "/$file" ]; then
256 echo -n "----------|----|----|$(_n 'File lost')"
257 else
258 echo -n "$(stat -c "%A|%U|%G|%s|" "/$file")"
259 cmp "$file" "/$file" >/dev/null 2>&1 || \
260 echo -n "$(stat -c "%.16y" "/$file")"
261 fi
262 echo "|/$file"
263 done
264 rm -r "$TMP_DIR/temp"
265 done
266 rm -r "$TMP_DIR"
267 else
268 im && title 'Configuration files'
269 for i in $FILES; do
270 [ -f "$i" ] || continue
271 zcat "$i" | cpio -t --quiet
272 done | sed 's|^|/|' | sort
273 im && footer
274 fi
275 ;;
278 suggested)
279 # List of suggested packages
280 # By default list only not installed suggested packages
281 # Option --all displays all (installed and not installed) suggested packages
282 for i in $(ls -d "$INSTALLED"/*/receipt); do
283 unset SUGGESTED
284 . $i
285 if [ -n "$SUGGESTED" ]; then
286 if [ -z "$all" ]; then
287 for s in $SUGGESTED; do
288 [ -d "$INSTALLED/$s" ] && \
289 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
290 done
291 fi
292 [ -n "$SUGGESTED" ] && cat <<EOT
293 $(boldify $(echo "$PACKAGE"):) $SUGGESTED
294 EOT
295 fi
296 done
297 ;;
299 esac
300 exit 0