tazpkg view modules/list @ rev 846
Remove "busybox" "prefixes" (thanks llev)
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Oct 09 13:14:01 2015 +0300 (2015-10-09) |
parents | 48496086d8c9 |
children | 45d90da42ede |
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 # Interactive mode
35 im() { tty -s; }
38 # Functions set for translate categories
39 # --------------------------------------
41 # Translate category names (must be last in line)
43 translate_category() {
44 sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|;
45 s|utilities$|$(_ utilities)|; s|network$|$(_ network)|;
46 s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|;
47 s|office$|$(_ office)|; s|development$|$(_ development)|;
48 s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|;
49 s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|;
50 s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|"
51 }
54 # Make array of pre-translated categories
56 cat_i18n=''
57 for c in 'base-system' 'x-window' 'utilities' 'network' 'graphics' \
58 'multimedia' 'office' 'development' 'system-tools' 'security' 'games' \
59 'misc' 'meta' 'non-free'; do
60 cat_i18n="$cat_i18n
61 $(gettext "$c") $c"
62 done
65 # If category is not one of those translated in native language, keep it
66 # untranslated. This allows both native and English language support.
67 # This also supports custom categories.
68 # And now we support spaces in translated categories
70 reverse_translate_category() {
71 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
72 }
75 # Main code
76 # ---------
78 case $1 in
80 blocked)
81 # List of blocked packages
82 title 'Blocked packages'
84 if [ -s "$BLOCKED" ];then
85 cat "$BLOCKED"
86 num=$(wc -l < "$BLOCKED")
87 footer "$(_p '%s package' '%s packages' "$num" \
88 "$(colorize 31 $num)")"
89 else
90 _ 'No blocked packages found.'; newline
91 fi
92 ;;
95 categories)
96 # List of categories
97 title 'Packages categories'
99 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
100 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
101 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
103 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
104 footer "$(_p '%s category' '%s categories' "$num" \
105 "$(colorize 33 $num)")"
106 ;;
109 linked)
110 # List of linked packages
111 title 'Linked packages'
113 linked="$(find "$INSTALLED" -type l -maxdepth 1)"
114 if [ -n "$linked" ]; then
115 for pkg in $linked; do
116 awk -F$'\t' -vp="$(basename "$pkg")" \
117 '$1==p{printf "%-34s %-17s %s\n", $1, $2, $3}' \
118 "$PKGS_DB/installed.info" | translate_category
119 done
120 num=$(echo "$linked" | wc -l)
121 footer "$(_p '%s package' '%s packages' "$num" \
122 "$(colorize 31 $num)")"
123 else
124 _ 'No linked packages found.'; newline
125 fi
126 ;;
129 installed)
130 # List of installed packages
131 title 'List of all installed packages'
133 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
134 "$PKGS_DB/installed.info" | translate_category
135 num=$(wc -l < "$PKGS_DB/installed.info")
137 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
138 "$(colorize 32 $num)")"
139 ;;
142 installed_of_category)
143 # List of installed packages of asked category
144 shift
145 ASKED_CATEGORY_I18N="$@"
146 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
147 title 'Installed packages of category "%s"' "$ASKED_CATEGORY_I18N"
149 TMPLIST=$(mktemp)
150 awk -F$'\t' -vcat="$ASKED_CATEGORY" \
151 '$3==cat{printf "%-34s %s\n", $1, $2}' \
152 "$PKGS_DB/installed.info" | tee "$TMPLIST" | translate_category
153 num=$(wc -l < "$TMPLIST"); rm "$TMPLIST"
155 footer "$(emsg $(_p \
156 '%s package installed of category "%s".' \
157 '%s packages installed of category "%s".' $num \
158 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
159 ;;
162 mirrored)
163 # List packages available on the mirror
164 # Option --diff displays last mirrored packages diff (see recharge).
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 : ${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 FILES="$INSTALLED/${2:-*}/volatile.cpio.gz"
251 if [ -n "$box" ]; then
252 TMP_DIR=$(mktemp -d)
254 for i in $FILES; do
255 mkdir -p "$TMP_DIR/temp"; cd "$TMP_DIR/temp"
257 zcat $i | cpio -idm --quiet >/dev/null
259 find . -type f 2>/dev/null | while read file; do
260 if [ ! -e "/$file" ]; then
261 echo -n "----------|----|----|$(_n 'File lost')"
262 else
263 echo -n "$(stat -c "%A|%U|%G|%s|" "/$file")"
264 cmp "$file" "/$file" >/dev/null 2>&1 || \
265 echo -n "$(stat -c "%.16y" "/$file")"
266 fi
267 echo "|/$file"
268 done
269 rm -r "$TMP_DIR/temp"
270 done
271 rm -r "$TMP_DIR"
272 else
273 im && title 'Configuration files'
274 for i in $FILES; do
275 [ -f "$i" ] || continue
276 zcat "$i" | cpio -t --quiet
277 done | sed 's|^|/|' | sort
278 im && footer
279 fi
280 ;;
283 suggested)
284 # List of suggested packages
285 # By default list only not installed suggested packages
286 # Option --all displays all (installed and not installed) suggested packages
287 for i in $(ls -d "$INSTALLED"/*/receipt); do
288 unset SUGGESTED
289 . $i
290 if [ -n "$SUGGESTED" ]; then
291 if [ -z "$all" ]; then
292 for s in $SUGGESTED; do
293 [ -d "$INSTALLED/$s" ] && \
294 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
295 done
296 fi
297 [ -n "$SUGGESTED" ] && cat <<EOT
298 $(boldify $(echo "$PACKAGE"):) $SUGGESTED
299 EOT
300 fi
301 done
302 ;;
304 esac
305 exit 0