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