tazpkg view tazpkg @ rev 578

tazpkg: fix update-mime-database post_install
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 29 08:56:51 2012 +0200 (2012-03-29)
parents 915b983a7f6d
children 1261d89830ee
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomous zone packages manager.
3 #
4 # This is a lightwight packages manager for *.tazpkg files written in
5 # SHell script. It works well with Busybox ash shell and bash. Tazpkg lets you
6 # list, install, remove, download or get information about a package. You can
7 # use 'tazpkg usage' to get a list of commands with short descriptions. Tazpkg
8 # also resolves dependencies and can upgrade packages from a mirror. I18n is
9 # done using gettext and eval_gettext, ex:
10 # gettext "displayed text"; echo
11 # eval_gettext "display \$VARIABLE"; echo
12 # echo -e "BOLD `gettext \"i18n message\"`"
13 #
14 # (C) 2007-2012 SliTaz - GNU General Public License v3.
15 #
16 # Authors : Christophe Lincoln <pankso@slitaz.org>
17 # Pascal Bellard <pascal.bellard@slitaz.org>
18 # Eric Joseph-Alexandre <erjo@slitaz.org>
19 # Paul Issott <paul@slitaz.org>
20 # Rohit Joshi <jozee@slitaz.org>
21 # Antoine Bodin <gokhlayeh@slitaz.org>
22 # Christopher Rogers <slaxemulator@gmail.com>
23 #
24 VERSION=4.9.1
26 ####################
27 # Script variables #
28 ####################
30 source /usr/lib/slitaz/libtaz
31 source_lib commons
32 . /etc/slitaz/tazpkg.conf
34 # Include gettext helper script.
35 . /usr/bin/gettext.sh
37 # Export package name for gettext.
38 TEXTDOMAIN='tazpkg'
39 export TEXTDOMAIN
41 # Initialize some variables to use words rather than numbers for functions
42 # and actions.
43 COMMAND=$1
44 PACKAGE=${2%/}
45 PACKAGE_DIR="$(cd $(dirname $PACKAGE 2>/dev/null) 2>/dev/null; pwd)"
46 [ -n "$PACKAGE" ] &&
47 PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
48 if [ -f "$PACKAGE" ]; then
49 # Set pkg basename for install, extract
50 PACKAGE=$(basename ${PACKAGE%.tazpkg} 2>/dev/null)
51 else
52 # Pkg name for remove, search and all other cmds
53 PACKAGE=${PACKAGE%.tazpkg}
54 fi
55 TARGET_DIR=$3
56 TOP_DIR=`pwd`
57 TMP_DIR=$tmp/$RANDOM
58 INSTALL_LIST=""
59 SAVE_CACHE_DIR="$CACHE_DIR"
61 # Path to tazpkg used dir and configuration files
62 INSTALLED=$LOCALSTATE/installed
63 MIRROR=$LOCALSTATE/mirror
64 BLOCKED=$LOCALSTATE/blocked-packages.list
65 UP_LIST=$LOCALSTATE/packages.up
66 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
68 # Need by check_depends
69 TMPLOCALSTATE=
71 # Check if the directories and files used by Tazpkg
72 # exist. If not and user is root we create them.
73 check_base_dir()
74 {
75 if test $(id -u) = 0 ; then
76 check_dir $1$CACHE_DIR
77 check_dir $1$INSTALLED
78 if [ ! -f "$1$LOCALSTATE/mirror" ]; then
79 echo "$DEFAULT_MIRROR" > $1$LOCALSTATE/mirror
80 [ -n "$1" ] && cp $LOCALSTATE/packages.* $1$LOCALSTATE/
81 fi
82 fi
83 }
84 check_base_dir
86 ####################
87 # Script functions #
88 ####################
90 # Print the usage.
91 usage ()
92 {
93 echo -e "`gettext \"SliTaz package manager - Version\"`: $VERSION
94 \033[1m`gettext \"Usage\"`:\033[0m `gettext \"tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]\"`
95 tazpkg shell\n
96 \033[1m`gettext \"Commands\"`: \033[0m
97 usage `gettext \"Print this short usage.\"`
98 bugs `gettext \"Show known bugs in packages.\"`
99 list|-l `gettext \"List installed packages on the system by category or all.\"`
100 xhtml-list `gettext \"Create a xHTML list of installed packages.\"`
101 list-mirror `gettext \"List all available packages on the mirror (--diff for new).\"`
102 info `gettext \"Print information about a package.\"`
103 desc `gettext \"Print description of a package (if it exists).\"`
104 list-files `gettext \"List the files installed with a package.\"`
105 list-config `gettext \"List the configuration files.\"`
106 search|-s `gettext \"Search for a package by pattern or name (options: -i|-l|-m).\"`
107 search-pkgname `gettext \"Search on mirror for package having a particular file.\"`
108 search-file `gettext \"Search for file(s) in all installed packages files.\"`
109 install|-i `gettext \"Install a local (*.tazpkg) package (--forced to force).\"`
110 install-list `gettext \"Install all packages from a list of packages.\"`
111 remove|-r `gettext \"Remove the specified package and all installed files.\"`
112 extract `gettext \"Extract a (*.tazpkg) package into a directory.\"`
113 pack `gettext \"Pack an unpacked or prepared package tree.\"`
114 recharge `gettext \"Recharge your packages.list from the mirror.\"`
115 up|--help-up `gettext \"Check packages md5sum to list and install latest upgrades.\"`
116 repack `gettext \"Create a package archive from an installed package.\"`
117 repack-config `gettext \"Create a package archive with configuration files.\"`
118 recompress `gettext \"Rebuild a package with a better compression ratio.\"`
119 block|unblock `gettext \"Block an installed package version or unblock it for upgrade.\"`
120 get `gettext \"Download a package into the current directory.\"`
121 get-install|-gi `gettext \"Download and install a package from the mirror.\"`
122 get-install-list `gettext \"Download and install a list of packages from the mirror.\"`
123 check `gettext \"Verify consistency of installed packages.\"`
124 add-flavor `gettext \"Install the flavor list of packages.\"`
125 install-flavor `gettext \"Install the flavor list of packages and remove other ones.\"`
126 set-release `gettext \"Change release and update packages.\"`
127 clean-cache|-cc `gettext \"Clean all packages downloaded in cache directory.\"`
128 depends `gettext \"Display dependencies tree.\"`
129 rdepends `gettext \"Display reverse dependencies tree.\"`
130 convert `gettext \"Convert a deb/rpm/tgz/arch package to a slitaz (.tazpkg).\"`
131 link `gettext \"Link a package from another slitaz installation.\"`
132 setup-mirror `gettext \"Change the mirror url configuration.\"`
133 list-undigest `gettext \"List undigest mirrors.\"`
134 remove-undigest `gettext \"Remove an undigest mirror.\"`
135 add-undigest `gettext \"Add an undigest mirror.\"`
136 setup-undigest `gettext \"Update an undigest mirror.\"`
137 reconfigure `gettext \"Replay post install script from package.\"`"
138 }
140 usage_up() {
141 echo -e "
142 \033[1m`gettext \"Tazpkg usage for command up\"`:\033[0m `gettext \"tazpkg up [--option]`\n
143 * `gettext \"Without options run in interactive mode and ask before install\"`
145 \033[1m`gettext \"Where options are\"`: \033[0m
146 --check |-c `gettext \"Check only for available upgrades\"`
147 --recharge |-r `gettext \"Force recharge of packages list and check\"`
148 --install |-i `gettext \"Check for upgrades and install them all\"`
150 \033[1m`gettext \"Example\"`: \033[0m
151 tazpkg up --recharge --install
152 tazpkg up -c -r
153 "
154 }
156 separator() {
157 echo "================================================================================"
158 }
160 # Check for a package name on cmdline.
161 check_for_package_on_cmdline()
162 {
163 if [ -z "$PACKAGE" ]; then
164 echo ""
165 gettext "Please specify a package name on the command line."; echo
166 echo ""
167 exit 0
168 fi
169 }
171 # Check if the package (*.tazpkg) exists before installing or extracting.
172 check_for_package_file()
173 {
174 if [ ! -f "$PACKAGE_FILE" ]; then
175 echo ""
176 eval_gettext "Unable to find: \$PACKAGE_FILE"; echo
177 echo "" && exit 0
178 fi
179 }
181 # Check for the receipt of an installed package.
182 check_for_receipt()
183 {
184 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
185 FS=$1
186 echo ""
187 eval_gettext "Unable to find the receipt: \$FS\$INSTALLED/\$PACKAGE/receipt"; echo
188 echo "" && exit 0
189 fi
190 }
192 # Get repositories priority using $LOCALSTATE/priority.
193 # In this files, undigest are called by their name and main mirror
194 # by main. Sort order : priority
195 look_for_priority()
196 {
197 [ -s $LOCALSTATE/priority ] && priority=$(cat $LOCALSTATE/priority)
198 for rep in main $(ls $LOCALSTATE/undigest 2>/dev/null); do
199 if [ ! -s $LOCALSTATE/priority ] || \
200 ! grep -q ^$rep$ $LOCALSTATE/priority; then
201 priority=$(echo -e "$priority\n$rep")
202 fi
203 done
204 priority=$(echo "$priority" | sed '/^$/d' | \
205 while read line; do
206 if [ "$line" = main ]; then
207 echo $LOCALSTATE
208 else
209 echo $LOCALSTATE/undigest/$line
210 fi
211 done)
212 }
214 # Get package name in a directory
215 package_fullname_in_dir()
216 {
217 [ -f $1/receipt ] || return
218 EXTRAVERSION=""
219 . $1/receipt
220 echo $PACKAGE-$VERSION$EXTRAVERSION
221 }
223 # Get package name that is already installed.
224 get_installed_package_pathname()
225 {
226 for i in $2$INSTALLED/${1%%-*}*; do
227 [ -d $i ] || continue
228 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
229 echo $i
230 return
231 fi
232 done
233 }
235 # Check if a package is already installed.
236 check_for_installed_package()
237 {
238 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
239 echo ""
240 eval_gettext "\$PACKAGE package is already installed. You can
241 use the --forced option to force installation or remove it and reinstall."; echo
242 echo "" && exit 0
243 fi
244 }
246 # Check for packages.list to download and install packages.
247 check_for_packages_list()
248 {
249 if [ ! -f "$LOCALSTATE/packages.list" ]; then
250 if test $(id -u) = 0 ; then
251 tazpkg recharge
252 else
253 echo ""
254 eval_gettext "Unable to find the list: \$LOCALSTATE/packages.list"; echo
255 gettext \
256 "You must probably run 'tazpkg recharge' as root to get the latest list of
257 packages available on the mirror."; echo
258 echo "" && exit 0
259 fi
260 fi
261 }
263 get_cache_dir()
264 {
265 echo $rep > $tmp/rep
266 if [ "$rep" = "$LOCALSTATE" ]; then
267 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_VERSION/packages"
268 elif [ "${rep%-incoming}" = "$rep" ]; then
269 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
270 else
271 rep="${rep%-incoming}"
272 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
273 fi
274 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
275 echo $CACHE_DIR > $tmp/cachedir
276 }
278 # get an already installed package from packages.equiv
279 equivalent_pkg()
280 {
281 for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \
282 $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do
283 if echo $i | fgrep -q : ; then
284 # format 'alternative:newname'
285 # if alternative is installed then substitute newname
286 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
287 # substitute package dependancy
288 echo ${i#*:}
289 return
290 fi
291 else
292 # if alternative is installed then nothing to install
293 if [ -f $2$INSTALLED/$i/receipt ]; then
294 # substitute installed package
295 echo $i
296 return
297 fi
298 fi
299 done
300 # if not found in packages.equiv then no substitution
301 echo $1
302 }
304 # get a virtual package from packages.equiv
305 virtual_pkg()
306 {
307 for i in $(for rep in $priority; do
308 grep -hs "^$1=" $rep/packages.equiv
309 done | sed "s/^$1=//"); do
310 if echo $i | fgrep -q : ; then
311 # format 'alternative:newname'
312 # if alternative is installed then substitute newname
313 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
314 # substitute package dependancy
315 echo ${i#*:}
316 return
317 fi
318 else
319 # unconditional substitution
320 echo $i
321 return
322 fi
323 done
324 }
326 # Get package filename available on the mirror
327 get_package_filename()
328 {
329 local pkg
330 for rep in $priority; do
331 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | \
332 sed 's/^ *//')
333 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \
334 $rep/packages.list | head -1)
336 # Allow user to call a package with his version number.
337 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
339 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \
340 $rep/packages.list | head -1)
341 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \
342 $rep/packages.list | head -1)
343 [ "$pkg" ] && get_cache_dir && break
344 done
345 if [ -z "$pkg" ]; then
346 # Check for vitual package
347 local equiv
348 equiv=$(virtual_pkg $1)
349 if [ "$equiv" != "$1" ]; then
350 PACKAGE=$equiv
351 get_package_filename $PACKAGE
352 return
353 fi
354 fi
355 echo $pkg
356 }
358 # Check for a package in packages.list. Used by get and get-install to grep
359 # package basename.
360 check_for_package_in_list()
361 {
362 local filename
363 local check_only
364 check_only="$1"
365 filename=$(get_package_filename $PACKAGE)
366 if [ "$filename" ]; then
367 PACKAGE=$filename
368 CACHE_DIR=$(cat $tmp/cachedir)
369 rep=$(cat $tmp/rep)
370 rm -f $tmp/rep $tmp/cachedir
371 else
372 echo ""
373 eval_gettext "Unable to find: \$PACKAGE in the mirrored packages list."; echo
374 echo ""
375 [ -n "$check_only" ] && return 1
376 exit 0
377 fi
378 }
380 # Log this activity
381 log()
382 {
383 local extra
384 [ "$1" = "Installed" ] && \
385 extra=" - $(fgrep $PACKAGE-$VERSION $LOCALSTATE/installed.md5 | awk '{ print $1 }')"
386 [ -e $LOG ] || touch $LOG
387 DATE=`date +'%F %T'`
388 [ -w $LOG ] &&
389 echo "$DATE - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
390 }
392 # Download a file from this mirror
393 download_from()
394 {
395 local i
396 local mirrors
397 mirrors="$1"
398 shift
399 for i in $mirrors; do
400 case "$i" in
401 http://*|ftp://*) wget -c $i/$@ && break;;
402 *) ln -sf $i/$1 . && break;;
403 esac
404 done
405 }
407 # Download a file trying all mirrors
408 download()
409 {
410 local i
411 case "$1" in
412 *.tazpkg)
413 for i in $priority ; do
414 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
415 download_from "$(cat $i/mirror)" "$@" && return
416 done
417 esac
418 for i in $(cat `for rep in $priority; do echo $rep/mirror; done` \
419 2> /dev/null); do
420 download_from "$i" "$@" && break
421 done
422 }
424 # Extract a package with cpio and gzip/lzma.
425 extract_package()
426 {
427 eval_gettext "Extracting \$PACKAGE... "
428 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
429 status
430 if [ -f fs.cpio.lzma ]; then
431 gettext "Extracting the pseudo fs... "
432 echo -n "(lzma) "
433 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
434 status
435 elif [ -f fs.cpio.gz ]; then
436 gettext "Extracting the pseudo fs... "
437 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
438 status
439 fi
440 }
442 remove_with_path()
443 {
444 # Avoid dirname errors by checking for argument.
445 [ "$1" ] || return
447 local dir
448 rm -f $1 2>/dev/null
449 dir="$1"
450 while [ "$dir" != "/" ]; do
451 dir="$(dirname $dir)"
452 rmdir $dir 2> /dev/null || break
453 done
454 }
456 grepesc()
457 {
458 sed 's/\[/\\[/g'
459 }
461 # This function installs a package in the rootfs.
462 install_package()
463 {
464 ROOT=$1
465 if [ -n "$ROOT" ]; then
466 # Get absolute path
467 ROOT=$(cd $ROOT; pwd)
468 fi
469 {
470 # Create package path early to avoid dependencies loop
471 mkdir -p $TMP_DIR
472 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
473 . $TMP_DIR/receipt
474 if grep -q ^pre_depends $TMP_DIR/receipt; then
475 pre_depends $ROOT
476 fi
477 # Keep modifers and file list on upgrade
478 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
479 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
480 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
481 # Make the installed package data dir to store
482 # the receipt and the files list.
483 mkdir -p $ROOT$INSTALLED/$PACKAGE
484 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
485 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
486 rm -rf $TMP_DIR 2> /dev/null
487 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
488 $ROOT$LOCALSTATE/installed.md5 2> /dev/null
489 cd $(dirname $PACKAGE_FILE)
490 md5sum $(basename $PACKAGE_FILE) >> $ROOT$LOCALSTATE/installed.md5
491 }
492 # Resolve package deps.
493 check_for_deps $ROOT
494 if [ ! "$MISSING_PACKAGE" = "" ]; then
495 install_deps $ROOT
496 fi
497 mkdir -p $TMP_DIR
498 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $INSTALL_LIST-processed
499 echo ""
500 echo -e "\033[1m`gettext \"Installation of :\"`\033[0m $PACKAGE"
501 separator
502 eval_gettext "Copying \$PACKAGE... "
503 cp $PACKAGE_FILE $TMP_DIR
504 status
505 cd $TMP_DIR
506 extract_package
507 SELF_INSTALL=0
508 EXTRAVERSION=""
509 CONFIG_FILES=""
510 # Include temporary receipt to get the right variables.
511 . $PWD/receipt
512 cd $ROOT$INSTALLED
513 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
514 gettext "Checking post install dependencies... "
515 [ -f $INSTALLED/$PACKAGE/receipt ]
516 if ! status; then
517 eval_gettext "Please run 'tazpkg install \$PACKAGE_FILE' in / and retry."; echo
518 rm -rf $TMP_DIR
519 exit 1
520 fi
521 fi
522 # Get files to remove if upgrading
523 if [ -f $PACKAGE/files.list ]; then
524 while read file; do
525 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
526 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
527 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
528 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
529 done
530 echo $file
531 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
532 fi
533 # Remember modified packages
534 { check=false
535 for i in $(fgrep -v [ $TMP_DIR/files.list); do
536 [ -e "$ROOT$i" ] || continue
537 [ -d "$ROOT$i" ] && continue
538 echo "- $i"
539 check=true
540 done ;
541 $check && for i in *; do
542 [ "$i" == "$PACKAGE" ] && continue
543 [ -s $i/files.list ] || continue
544 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
545 done; } | awk '
546 {
547 if ($1 == "-" || file[$2] != "") {
548 file[$2] = file[$2] " " $1
549 if ($1 != "-") {
550 if (pkg[$1] == "") all = all " " $1
551 pkg[$1] = pkg[$1] " " $2
552 }
553 }
554 }
555 END {
556 for (i = split(all, p, " "); i > 0; i--)
557 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
558 printf "%s %s\n",p[i],f[j];
559 }
560 ' | while read dir file; do
561 if grep -qs ^$dir$ $PACKAGE/modifiers; then
562 # Do not overload an overloaded file !
563 rm $TMP_DIR$file 2> /dev/null
564 continue
565 fi
566 grep -qs ^$PACKAGE$ $dir/modifiers && continue
567 if [ -s "$dir/volatile.cpio.gz" ]; then
568 # We can modify backed up files without notice
569 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
570 grep -q "^${file#/}$" && continue
571 fi
572 echo "$PACKAGE" >> $dir/modifiers
573 done
575 cd $TMP_DIR
576 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
577 # Copy the description if found.
578 if [ -f "description.txt" ]; then
579 cp description.txt $ROOT$INSTALLED/$PACKAGE
580 fi
581 # Copy the md5sum if found.
582 if [ -f "md5sum" ]; then
583 cp md5sum $ROOT$INSTALLED/$PACKAGE
584 fi
585 # Pre install commands.
586 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
587 pre_install $ROOT
588 fi
589 if [ -n "$CONFIG_FILES" ]; then
590 # save 'official' configuration files
591 eval_gettext "Saving configuration files for \$PACKAGE... "
592 for i in $CONFIG_FILES; do
593 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
594 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
595 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
596 # keep user configuration files
597 for i in $CONFIG_FILES; do
598 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
599 done | while read i; do
600 [ -e $ROOT/$i ] || continue
601 cp -a $ROOT/$i fs/$i
602 done
603 status
604 fi
605 eval_gettext "Installing \$PACKAGE... "
606 cp -a fs/* $ROOT/
607 status
608 if [ -s files2remove.list ]; then
609 eval_gettext "Removing old \$PACKAGE... "
610 while read file; do
611 remove_with_path $ROOT$file
612 done < files2remove.list
613 true
614 status
615 fi
616 # Remove the temporary random directory.
617 gettext "Removing all tmp files... "
618 cd .. && rm -rf $TMP_DIR
619 status
620 # Post install commands.
621 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
622 post_install $ROOT
623 fi
624 # Update-desktop-database if needed.
625 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
626 updatedesktopdb=yes
627 fi
628 # Update-mime-database if needed.
629 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
630 updatemimedb=yes
631 fi
632 # Update-icon-database
633 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
634 updateicondb=yes
635 fi
636 # Compile glib schemas if needed.
637 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
638 compile_schemas=yes
639 fi
640 cd $TOP_DIR
641 separator
642 eval_gettext "\$PACKAGE (\$VERSION\$EXTRAVERSION) is installed."; echo
643 echo ""
644 # Log this activity
645 [ -n "$ROOT" ] || log Installed
646 }
648 # Check for loop in deps tree.
649 check_for_deps_loop()
650 {
651 local list
652 local pkg
653 local deps
654 pkg=$1
655 shift
656 [ -n "$1" ] || return
657 list=""
658 # Filter out already processed deps
659 for i in $@; do
660 case " $ALL_DEPS" in
661 *\ $i\ *);;
662 *) list="$list $i";;
663 esac
664 done
665 ALL_DEPS="$ALL_DEPS$list "
666 for i in $list; do
667 [ -f $i/receipt ] || continue
668 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
669 case " $deps " in
670 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
671 *) check_for_deps_loop $pkg $deps;;
672 esac
673 done
674 }
676 # Check for missing deps listed in a receipt packages.
677 check_for_deps()
678 {
679 local saved;
680 saved=$PACKAGE
681 mkdir -p $TMP_DIR
682 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
683 . $TMP_DIR/receipt
684 PACKAGE=$saved
685 rm -rf $TMP_DIR
686 for pkgorg in $DEPENDS
687 do
688 i=$(equivalent_pkg $pkgorg $1)
689 if [ ! -d "$1$INSTALLED/$i" ]; then
690 MISSING_PACKAGE=$i
691 deps=$(($deps+1))
692 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
693 eval_gettext "WARNING Dependency loop between \$PACKAGE and \$i."; echo
694 fi
695 done
696 if [ ! "$MISSING_PACKAGE" = "" ]; then
697 echo -e "\033[1m`gettext \"Tracking dependencies for :\"`\033[0m $PACKAGE"
698 separator
699 for pkgorg in $DEPENDS
700 do
701 i=$(equivalent_pkg $pkgorg $1)
702 if [ ! -d "$1$INSTALLED/$i" ]; then
703 MISSING_PACKAGE=$i
704 eval_gettext "Missing: \$MISSING_PACKAGE"; echo
705 fi
706 done
707 separator
708 eval_gettext "\$deps missing package(s) to install."; echo
709 fi
710 }
712 # Install all missing deps. Auto install or ask user then install all missing
713 # deps from local dir, cdrom, media or from the mirror. In case we want to
714 # install packages from local, we need a packages.list to find the version.
715 install_deps()
716 {
717 local root
718 root=""
719 [ -n "$1" ] && root="--root=$1"
720 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
721 answer=`translate_querry y`
722 else
723 echo ""
724 gettext "Install all missing dependencies"
725 echo -n " (`translate_querry y`/`translate_querry N`) ? "
726 read answer
727 echo ""
728 fi
729 if [ "$answer" == "$(translate_querry y)" ]; then
730 for pkgorg in $DEPENDS
731 do
732 pkg=$(equivalent_pkg $pkgorg $1)
733 if [ ! -d "$1$INSTALLED/$pkg" ]; then
734 local list
735 list="$INSTALL_LIST"
736 [ -n "$list" ] || list="$TOP_DIR/packages.list"
737 # We can install packages from a local dir by greping
738 # the TAZPKG_BASENAME in the local packages.list.
739 found=0
740 if [ -f "$list" ]; then
741 eval_gettext "Checking if \$pkg exists in local list... "; echo
742 mkdir $TMP_DIR
743 for i in $pkg-*.tazpkg; do
744 [ -f $i ] || continue
745 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
746 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
747 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
748 then
749 found=1
750 tazpkg install $i $root --list=$list
751 break
752 fi
753 done
754 rm -rf $TMP_DIR
755 fi
756 # Install deps from the mirror.
757 if [ $found -eq 0 ]; then
758 if [ ! -f "$LOCALSTATE/packages.list" ]; then
759 tazpkg recharge
760 fi
761 tazpkg get-install $pkg $root
762 fi
763 fi
764 done
765 else
766 echo ""
767 eval_gettext \
768 "Leaving dependencies for \$PACKAGE unresolved. The package is installed but
769 will probably not work."; echo
770 echo ""
771 fi
772 }
774 # xHTML packages list header.
775 xhtml_header()
776 {
777 cat > $XHTML_LIST << _EOT_
778 <!DOCTYPE html>
779 <html xmlns="http://www.w3.org/1999/xhtml">
780 <head>
781 <title>Install packages on: `hostname`</title>
782 <meta charset="utf-8" />
783 <style type="text/css">
784 body { font: 88% sans-serif, vernada, arial; margin: 0; }
785 #header { background: #351a0a; height: 40px; border-bottom: 8px solid #d66018; }
786 #content { margin: 40px 80px; text-align: justify; }
787 #footer { text-align: center; padding: 20px; border-top: 1px solid #ddd; }
788 h1 { margin: 0; padding: 8px; color: #fff; font-size: 20px; }
789 h2 { color: #444; } h3 { color: #666; font-size: 140%; }
790 pre { background-color: #f8f8f8; border: 1px solid #ddd; padding: 10px;
791 -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;}
792 </style>
793 </head>
794 <body>
796 <body>
797 <div id="header">
798 <h1>Installed packages list</h1>
799 </div>
801 <!-- Start content -->
802 <div id="content">
804 <p>
805 _packages_ packages installed - List generated on : $DATE
806 <p>
808 _EOT_
809 }
811 # xHTML content with packages info.
812 xhtml_pkg_info()
813 {
814 cat >> $XHTML_LIST << _EOT_
815 <h3>$PACKAGE</h3>
816 <pre>
817 Version : $VERSION$EXTRAVERSION
818 Short desc : $SHORT_DESC
819 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
820 </pre>
822 _EOT_
823 }
825 # xHTML packages list footer.
826 xhtml_footer()
827 {
828 cat >> $XHTML_LIST << _EOT_
829 <hr />
830 <p id="footer">
831 $packages packages installed - List generated on : $DATE
832 </p>
834 <!-- End content -->
835 </div>
836 </body>
837 </html>
838 _EOT_
839 }
841 # Search pattern in installed packages.
842 search_in_installed_packages()
843 {
844 gettext "Installed packages"; echo
845 separator
846 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
847 for pkg in $list
848 do
849 EXTRAVERSION=""
850 [ -f $INSTALLED/$pkg/receipt ] || continue
851 . $INSTALLED/$pkg/receipt
852 echo -n "$PACKAGE "
853 echo -en "\033[24G $VERSION$EXTRAVERSION"
854 echo -e "\033[42G `translate_category $CATEGORY`."
855 packages=$(($packages+1))
856 done
857 # Set correct ending messages.
858 if [ "$packages" = "" ]; then
859 eval_gettext "0 installed packages found for : \$PATTERN"; echo
860 echo ""
861 else
862 separator
863 eval_gettext "\$packages installed package(s) found for : \$PATTERN"; echo
864 echo ""
865 fi
866 }
868 # Search in packages.list for available pkgs.
869 search_in_packages_list()
870 {
871 gettext "Available packages name-version"; echo
872 separator
873 packages=0
874 for i in $LOCALSTATE/packages.list $LOCALSTATE/undigest/*/packages.list; do
875 grep -is "$PATTERN" $i
876 packages=$(($packages + `grep -is "$PATTERN" $i | wc -l`))
877 done
878 if [ ! -f "$LOCALSTATE/packages.list" ]; then
879 echo ""
880 gettext \
881 "No 'packages.list' found to check for mirrored packages. For more results,
882 please run 'tazpkg recharge' once as root before searching."; echo
883 echo ""
884 fi
885 if [ "$packages" = "0" ]; then
886 eval_gettext "0 available packages found for : \$PATTERN"; echo
887 echo ""
888 else
889 separator
890 eval_gettext "\$packages available package(s) found for : \$PATTERN"; echo
891 echo ""
892 fi
893 }
895 # search --mirror: Search in packages.txt for available pkgs and give more
896 # info than --list or default.
897 search_in_packages_txt()
898 {
899 gettext "Matching packages name with version and desc"; echo
900 separator
901 packages=0
902 for i in $LOCALSTATE/packages.txt $LOCALSTATE/undigest/*/packages.txt; do
903 grep -is -A 2 "^$PATTERN" $i
904 packages=$(($packages + `grep -is "^$PATTERN" $i | wc -l`))
905 done
906 if [ ! -f "$LOCALSTATE/packages.txt" ]; then
907 echo ""
908 gettext \
909 "No 'packages.txt' found to check for mirrored packages. For more results,
910 please run 'tazpkg recharge' once as root before searching."; echo
911 echo ""
912 fi
913 if [ "$packages" = "0" ]; then
914 eval_gettext "0 available packages found for : \$PATTERN"; echo
915 echo ""
916 else
917 separator
918 eval_gettext "\$packages available package(s) found for : \$PATTERN"; echo
919 echo ""
920 fi
921 }
923 # Install package-list from a flavor
924 install_flavor()
925 {
926 check_root
928 # Get repositories priority list.
929 look_for_priority
931 FLAVOR=$1
932 ARG=$2
933 mkdir -p $TMP_DIR
934 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
935 cd $TMP_DIR
936 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
937 zcat $FLAVOR.flavor | cpio --quiet -i >/dev/null
938 while read file; do
939 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
940 [ -f $pkg/receipt ] || continue
941 EXTRAVERSION=""
942 . $pkg/receipt
943 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
944 done
945 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
946 cd $CACHE_DIR
947 download $file.tazpkg
948 cd $TMP_DIR
949 tazpkg install $CACHE_DIR/$file.tazpkg --forced
950 done < $FLAVOR.pkglist
951 [ -f $FLAVOR.nonfree ] && while read pkg; do
952 [ -d $INSTALLED/$pkg ] || continue
953 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
954 get-$pkg
955 done < $FLAVOR.nonfree
956 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
957 [ -f $INSTALLED/$pkg/receipt ] || continue
958 EXTRAVERSION=""
959 . $INSTALLED/$pkg/receipt
960 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
961 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
962 tazpkg remove $PACKAGE
963 done
964 else
965 eval_gettext "Can't find flavor \$FLAVOR. Abort."; echo
966 fi
967 cd $TOP_DIR
968 rm -rf $TMP_DIR
969 }
971 # Update mirror urls
972 setup_mirror()
973 {
974 # Backup old list.
975 if [ -f "$1/mirror" ]; then
976 cp -f $1/mirror $1/mirror.bak
977 fi
978 echo ""
979 echo -e "\033[1m`gettext \"Current mirror(s)\"`\033[0m"
980 separator
981 echo " `cat $1/mirror 2> /dev/null`"
982 gettext \
983 "Please enter URL of the new mirror (http, ftp or local path). You must specify
984 the complete address to the directory of the packages and packages.list file."; echo
985 echo ""
986 gettext "New mirror(s) URL : "
987 NEW_MIRROR_URL=$2
988 if [ -n "$NEW_MIRROR_URL" ]; then
989 echo $NEW_MIRROR_URL
990 else
991 read NEW_MIRROR_URL
992 fi
993 if [ "$NEW_MIRROR_URL" = "" ]; then
994 gettext "Nothing has been changed."; echo
995 else
996 eval_gettext "Setting mirror(s) to : $NEW_MIRROR_URL"; echo
997 rm -f $1/mirror
998 for i in $NEW_MIRROR_URL; do
999 echo "$i" >> $1/mirror
1000 done
1001 fi
1002 echo ""
1005 # recursive dependencies scan
1006 dep_scan()
1008 for i in $1; do
1009 case " $ALL_DEPS " in
1010 *\ $i\ *) continue;;
1011 esac
1012 ALL_DEPS="$ALL_DEPS $i"
1013 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $LOCALSTATE/packages.txt \
1014 | tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1015 [ -f $i/receipt ] || continue
1016 DEPENDS=""
1017 . $i/receipt
1018 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1019 done
1022 # recursive reverse dependencies scan
1023 rdep_scan()
1025 SEARCH=$1
1027 for i in * ; do
1028 DEPENDS=""
1029 . $i/receipt
1030 echo "$i $(echo $DEPENDS)"
1031 done | awk -v search=$SEARCH '
1032 function show_deps(deps, all_deps, pkg, space)
1034 if (all_deps[pkg] == 1) return
1035 all_deps[pkg] = 1
1036 if (space != "") printf "%s %s\n",space,pkg
1037 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1038 show_deps(deps, all_deps, mydeps[i],"==" space)
1043 all_deps[$1] = 0
1044 for (i = 2; i <= NF; i++)
1045 deps[$i] = deps[$i] " " $1
1048 END {
1049 show_deps(deps, all_deps, search, "")
1051 ' | while read spc pkg; do
1052 echo -n $spc | sed 's/=/ /g'
1053 echo -n $pkg
1054 echo -n ' ('
1055 fgrep -A 3 $pkg $LOCALSTATE/packages.txt | tail -1 | \
1056 sed 's/.*(\([^ ]*\).*/\1)/'
1057 done
1060 # Check for ELF file
1061 is_elf()
1063 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
1066 # Print shared library dependencies
1067 ldd()
1069 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
1072 # search dependencies for files in $TMP_DIR/$file/fs
1073 find_depends()
1075 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
1077 [ -n "$TMPLOCALSTATE" ] || TMPLOCALSTATE=$LOCALSTATE
1078 [ -f $TMPLOCALSTATE/files.list.lzma ] || tazpkg recharge > /dev/null
1079 for i in $TMPLOCALSTATE/files.list.lzma \
1080 $TMPLOCALSTATE/undigest/*/files.list.lzma ; do
1081 [ -f $i ] && lzma d $i -so >> $TMP_DIR/files.list
1082 done
1083 find $TMP_DIR/$file/fs -type f | while read chkfile ; do
1084 is_elf $chkfile || continue
1085 case "$chkfile" in
1086 *.o|*.ko|*.ko.gz) continue;;
1087 esac
1088 ldd $chkfile | while read lib rem; do
1089 case "$lib" in
1090 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
1091 continue;;
1092 esac
1093 find $TMP_DIR/$file/fs | grep -q /$lib$ && continue
1094 for dep in $(fgrep $lib files.list | cut -d: -f1); do
1095 case " $DEFAULT_DEPENDS " in
1096 *\ $dep\ *) continue 2;;
1097 esac
1098 grep -qs "^$dep$" $TMP_DIR/depends && continue 2
1099 done
1100 if [ -n "$dep" ]; then
1101 echo "$dep" >> $TMP_DIR/depends
1102 else
1103 grep -qs ^$lib$ $TMP_DIR/unresolved ||
1104 echo "$lib" >> $TMP_DIR/unresolved
1105 fi
1106 done
1107 done
1108 spc=""
1109 cat $TMP_DIR/depends 2> /dev/null | sort | uniq | while read file; do
1110 echo -n "$spc$file"
1111 spc=" "
1112 done
1115 show_unresolved_lib()
1117 if [ -s $TMP_DIR/unresolved ]; then
1118 echo -e "BUGS=\"`gettext \"No dependency for\"`" >> $1
1119 cat $TMP_DIR/unresolved | sort | uniq | while read file; do
1120 eval_gettext "WARNING: unknown dependency for \$lib"; echo
1121 echo -n " $file" >> $1
1122 done
1123 echo "\"" >> $1
1124 fi
1127 # convert a .ipk package to .tazpkg
1128 convert_ipk()
1130 mkdir -p $TMP_DIR
1131 tar xOzf $PACKAGE_FILE ./control.tar.gz | tar xzf - -C $TMP_DIR
1132 package="$(grep ^Package $TMP_DIR/control | sed 's/.*: //')"
1133 version="$(grep ^Version $TMP_DIR/control | sed 's/.*: //')"
1134 maintainer="$(grep ^Maintainer $TMP_DIR/control | sed 's/.*: //')"
1135 target="$(grep ^Architecture $TMP_DIR/control | sed 's/.*: //')"
1136 descrip="$(grep ^Description $TMP_DIR/control | sed 's/.*: //')"
1137 url="http://openwrt.org/"
1138 case "$target" in
1139 i386|all)
1140 file=$package-$version
1141 mkdir -p $TMP_DIR/$file/fs
1142 tar xOzf $PACKAGE_FILE ./data.tar.gz | \
1143 tar xzf - -C $TMP_DIR/$file/fs
1144 cd $TMP_DIR
1145 cat > $file/receipt <<EOT
1146 # SliTaz package receipt.
1147 # generated by tazpkg from package $(basename $PACKAGE_FILE)
1148 PACKAGE="$package"
1149 VERSION="$version"
1150 CATEGORY="misc"
1151 SHORT_DESC="$descrip"
1152 WEB_SITE="$url"
1153 MAINTAINER="$maintainer"
1154 DEPENDS="$(find_depends)"
1155 EOT
1156 [ -s conffiles ] && cat >> $file/receipt <<EOT
1157 CONFIG_FILES="$(cat conffiles)"
1158 EOT
1159 show_unresolved_lib $file/receipt
1160 while read script func; do
1161 [ -s $script ] && cat >> $file/receipt <<EOT
1163 $func()
1165 $(cat $script)
1167 EOT
1168 done <<EOT
1169 preinst pre_install
1170 postinst post_install
1171 prerm pre_remove
1172 postrm post_remove
1173 EOT
1174 awk '
1176 if (/^ / && show) print substr($0,2);
1177 else show=0;
1178 if (/^Description/) show=1;
1179 }' < $TMP_DIR/control > $file/description.txt
1180 sed -i 's/^\.$//' $file/description.txt
1181 [ -s $file/description.txt ] || rm -f $file/description.txt
1182 tazpkg pack $file
1183 cd $TOP_DIR
1184 mv $TMP_DIR/$file.tazpkg .
1185 ;;
1186 *)
1187 gettext "Invalid target: $target (expected i386)"; echo
1188 ;;
1189 esac
1190 rm -rf $TMP_DIR
1193 # convert a .pkg.tar.gz/.apk package to .tazpkg
1194 convert_arch()
1196 mkdir -p $TMP_DIR/fs
1197 tar xzf $PACKAGE_FILE -C $TMP_DIR/fs
1198 if [ -f $TMP_DIR/fs/.PKGINFO ]; then
1199 cd $TMP_DIR
1200 package="$(grep ^pkgname fs/.PKGINFO | sed 's/.*= //')"
1201 version="$(grep ^pkgver fs/.PKGINFO | sed 's/.*= //')"
1202 descrip="$(grep ^pkgdesc fs/.PKGINFO | sed 's/.*= //')"
1203 url="$(grep ^url fs/.PKGINFO | sed 's/.*= //')"
1204 maintainer="$(grep ^packager fs/.PKGINFO | sed 's/.*= //')"
1205 file=$package-$version
1206 mkdir $file
1207 mv fs $file
1208 cat > $file/receipt <<EOT
1209 # SliTaz package receipt.
1210 # generated by tazpkg from Archlinux package $(basename $PACKAGE_FILE)
1211 PACKAGE="$package"
1212 VERSION="$version"
1213 CATEGORY="misc"
1214 SHORT_DESC="$descrip"
1215 WEB_SITE="$url"
1216 MAINTAINER="$maintainer"
1217 DEPENDS="$(find_depends)"
1218 EOT
1219 show_unresolved_lib $file/receipt
1220 rm -f $file/fs/.[A-Z]*
1221 tazpkg pack $file
1222 mv $file.tazpkg $TOP_DIR
1223 else
1224 eval_gettext "\$PACKAGE_FILE does not look like an Archlinux/Alpine package !"; echo
1225 fi
1226 cd $TOP_DIR
1227 rm -rf $TMP_DIR
1230 # convert a .tgz package to .tazpkg
1231 convert_tgz()
1233 package=$(basename $PACKAGE_FILE)
1234 IFS='-'
1235 set -- $package
1236 unset IFS
1237 package=$1
1238 version=$2
1239 file="$package-$version"
1240 mkdir -p $TMP_DIR/$file/fs
1241 tar xzf $PACKAGE_FILE -C $TMP_DIR/$file/fs
1242 cd $TMP_DIR
1243 if [ -d $file/fs/install ]; then
1244 descrip=$(grep ^$package $file/fs/install/slack-desc | \
1245 head -1 | sed 's/.*(\(.*\)).*/\1/')
1246 cat > $file/receipt <<EOT
1247 # SliTaz package receipt.
1248 # generated by tazpkg from slackware package $(basename $PACKAGE_FILE)
1249 PACKAGE="$package"
1250 VERSION="$version"
1251 CATEGORY="misc"
1252 SHORT_DESC="$descrip"
1253 WEB_SITE="http://www.slackware.com/packages/"
1254 MAINTAINER="nobody@slitaz.org"
1255 DEPENDS="$(find_depends)"
1256 EOT
1257 show_unresolved_lib $file/receipt
1258 [ -f $file/fs/install/doinst.sh ] && cat >> $file/receipt <<EOM
1260 post_install()
1262 chroot \$1/ sh - << EOT
1263 cd /
1264 $(cat $file/fs/install/doinst.sh | sed -e 's/\\/\\\\/g' | sed -e 's/\$/\\$/g')
1265 EOT
1267 EOM
1268 grep ^$package $file/fs/install/slack-desc | \
1269 sed "s/^$package://" > $file/description.txt
1270 [ -s $file/description.txt ] || rm -f $file/description.txt
1271 rm -rf $file/fs/install
1272 tazpkg pack $file
1273 mv $file.tazpkg $TOP_DIR
1274 else
1275 eval_gettext "\$PACKAGE_FILE does not look like a Slackware package !"; echo
1276 fi
1277 cd $TOP_DIR
1278 rm -rf $TMP_DIR
1281 # convert a .deb package to .tazpkg
1282 convert_deb()
1284 mkdir -p $TMP_DIR
1285 dpkg-deb -e $PACKAGE_FILE $TMP_DIR
1286 package=$(grep '^ *Package:' $TMP_DIR/control)
1287 package=$(echo ${package##*:})
1288 version=$(grep '^ *Version:' $TMP_DIR/control)
1289 version=$(echo ${version##*:})
1290 descrip=$(grep '^ *Description:' $TMP_DIR/control)
1291 descrip=$(echo ${descrip##*:})
1292 target="$(grep ^Architecture $TMP_DIR/control | sed 's/.*: //')"
1293 case "$target" in
1294 i386|all)
1295 file="$package-$version"
1296 mkdir -p $TMP_DIR/$file/fs/
1297 dpkg-deb -x $PACKAGE_FILE $TMP_DIR/$file/fs
1298 cd $TMP_DIR
1299 cat > $file/receipt <<EOT
1300 # SliTaz package receipt.
1301 # generated by tazpkg from debian package $(basename $PACKAGE_FILE)
1302 PACKAGE="$package"
1303 VERSION="$version"
1304 CATEGORY="misc"
1305 SHORT_DESC="$descrip"
1306 WEB_SITE="http://packages.debian.org/search?keywords=$package"
1307 MAINTAINER="nobody@slitaz.org"
1308 DEPENDS="$(find_depends)"
1309 EOT
1310 [ -s conffiles ] && cat >> $file/receipt <<EOT
1311 CONFIG_FILES="$(cat conffiles)"
1312 EOT
1313 show_unresolved_lib $file/receipt
1314 awk '
1316 if (/^ / && show) print substr($0,2);
1317 else show=0;
1318 if (/^Description/) show=1;
1319 }' < $TMP_DIR/control > $file/description.txt
1320 sed -i 's/^\.$//' $file/description.txt
1321 [ -s $file/description.txt ] || rm -f $file/description.txt
1322 tazpkg pack $file
1323 mv $file.tazpkg $TOP_DIR
1324 ;;
1325 *)
1326 gettext "Invalid target: $target (expected i386)"; echo
1327 ;;
1328 esac
1329 cd $TOP_DIR
1330 rm -rf $TMP_DIR
1333 # convert a .rpm package to .tazpkg
1334 convert_rpm()
1336 mkdir -p $TMP_DIR
1337 cp $PACKAGE_FILE $TMP_DIR
1338 PACKAGE_FILE=$TMP_DIR/$(basename $PACKAGE_FILE)
1339 rpm -qip $PACKAGE_FILE | awk -v pkg=$(basename $PACKAGE_FILE) '
1340 BEGIN {
1341 goturl=0;
1342 printf "# Taz package receipt.\n";
1343 printf "# Generated by tazpkg from rpm package %s\n",pkg;
1346 if (/^Name/) { name=$3; printf "PACKAGE=\"%s\"\n",$3; }
1347 if (/^Version/) printf "VERSION=\"%s-",$3;
1348 if (/^Release/) printf "%s\"\n",$3;
1349 if (/^Summary/) printf "SHORT_DESC=\"%s\"\n",substr($0,15);
1350 if (/^URL/) { goturl=1; printf "WEB_SITE=\"%s\"\n",$3; }
1352 END {
1353 if (goturl == 0)
1354 printf "WEB_SITE=\"http://rpmfind.net/linux/rpm2html/search.php?query=%s\"\n",name;
1355 printf "CATEGORY=\"misc\"\n";
1356 printf "MAINTAINER=\"nobody@slitaz.org\"\n";
1358 ' > $TMP_DIR/receipt
1359 . $TMP_DIR/receipt
1360 file=$PACKAGE-$VERSION
1361 mkdir -p $TMP_DIR/$file/fs/
1362 mv $TMP_DIR/receipt $TMP_DIR/$file
1363 rpm -qip $PACKAGE_FILE | awk '
1364 DEGIN { show=0 }
1366 if (show) print;
1367 if (/^Description/) show=1;
1369 ' > $TMP_DIR/$file/description.txt
1370 cd $TMP_DIR/$file/fs/
1371 rpm2cpio $PACKAGE_FILE | cpio -idm --quiet
1372 cd ../..
1373 echo "DEPENDS=\"$(find_depends)\"" >> $TMP_DIR/$file/receipt
1374 show_unresolved_lib $TMP_DIR/$file/receipt
1375 tazpkg pack $file
1376 mv $file.tazpkg $TOP_DIR
1377 cd $TOP_DIR
1378 rm -rf $TMP_DIR
1381 update_desktop_database()
1383 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1384 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1385 fi
1388 update_mime_database()
1390 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1391 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1392 fi
1395 update_icon_database()
1397 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1398 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1399 fi
1402 compile_glib_schemas()
1404 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1405 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1406 fi
1409 translate_category()
1411 case $1 in
1412 base-system) gettext "base-system" ;;
1413 x-window) gettext "x-window" ;;
1414 utilities) gettext "utilities" ;;
1415 network) gettext "network" ;;
1416 graphics) gettext "graphics" ;;
1417 multimedia) gettext "multimedia" ;;
1418 office) gettext "office" ;;
1419 development) gettext "development" ;;
1420 system-tools) gettext "system-tools" ;;
1421 security) gettext "security" ;;
1422 games) gettext "games" ;;
1423 misc) gettext "misc" ;;
1424 meta) gettext "meta" ;;
1425 non-free) gettext "non-free" ;;
1427 # Support custom categories by keeping them untranslated.
1428 *) echo "$1" ;;
1430 esac
1433 reverse_translate_category()
1435 case $1 in
1436 `gettext "base-system"`) echo "base-system" ;;
1437 `gettext "x-window"`) echo "x-window" ;;
1438 `gettext "utilities"`) echo "utilities" ;;
1439 `gettext "network"`) echo "network" ;;
1440 `gettext "graphics"`) echo "graphics" ;;
1441 `gettext "multimedia"`) echo "multimedia" ;;
1442 `gettext "office"`) echo "office" ;;
1443 `gettext "development"`) echo "development" ;;
1444 `gettext "system-tools"`) echo "system-tools" ;;
1445 `gettext "security"`) echo "security" ;;
1446 `gettext "games"`) echo "games" ;;
1447 `gettext "misc"`) echo "misc" ;;
1448 `gettext "meta"`) echo "meta" ;;
1449 `gettext "non-free"`) echo "non-free" ;;
1451 # If category is not one of those translated in native language,
1452 # keep it untranslated. This allows both native and english
1453 # language support. This also supports custom categories.
1454 *) echo "$1" ;;
1456 esac
1459 translate_querry()
1461 case $1 in
1462 y) gettext "y" ;;
1463 Y) gettext "Y" ;;
1464 n) gettext "n" ;;
1465 N) gettext "N" ;;
1466 # Support other cases but keep them untranslated.
1467 *) echo "$1" ;;
1468 esac
1471 ###################
1472 # Tazpkg commands #
1473 ###################
1475 case "$COMMAND" in
1476 list|-l)
1477 # List all installed packages or a specific category.
1478 if [ "$2" = "blocked" ]; then
1479 echo ""
1480 echo -e "\033[1m`gettext \"Blocked packages\"`\033[0m"
1481 separator
1482 if [ -s "$BLOCKED" ];then
1483 cat $BLOCKED
1484 else
1485 gettext "No blocked packages found."; echo
1486 fi
1487 echo "" && exit 0
1488 fi
1489 # Display the list of categories.
1490 if [ "$2" = "cat" -o "$2" = "categories" ]; then
1491 echo ""
1492 echo -e "\033[1m`gettext \"Packages categories\"`\033[0m"
1493 separator
1494 for i in $CATEGORIES
1495 do
1496 translate_category $i; echo
1497 categories=$(($categories+1))
1498 done
1499 separator
1500 eval_gettext "\$categories categories"; echo
1501 echo ""
1502 exit 0
1503 fi
1504 # Check for an asked category.
1505 if [ -n "$2" ]; then
1506 ASKED_CATEGORY_I18N=$2
1507 ASKED_CATEGORY=$(reverse_translate_category $2)
1508 echo ""
1509 echo -e "\033[1m`gettext \"Installed packages of category:\"`\033[0m $ASKED_CATEGORY_I18N"
1510 separator
1511 for pkg in $INSTALLED/*
1512 do
1513 [ -f $pkg/receipt ] || continue
1514 EXTRAVERSION=""
1515 . $pkg/receipt
1516 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1517 echo -n "$PACKAGE"
1518 echo -e "\033[24G $VERSION$EXTRAVERSION"
1519 packages=$(($packages+1))
1520 fi
1521 done
1522 separator
1523 eval_gettext "\$packages packages installed of category \$ASKED_CATEGORY_I18N."; echo
1524 echo ""
1525 else
1526 # By default list all packages and versions.
1527 echo ""
1528 echo -e "\033[1m`gettext \"List of all installed packages\"`\033[0m"
1529 separator
1530 for pkg in $INSTALLED/*
1531 do
1532 [ -f $pkg/receipt ] || continue
1533 EXTRAVERSION=""
1534 . $pkg/receipt
1535 echo -n "$PACKAGE"
1536 echo -en "\033[24G $VERSION$EXTRAVERSION"
1537 echo -e "\033[42G `translate_category $CATEGORY`"
1538 packages=$(($packages+1))
1539 done
1540 separator
1541 eval_gettext "\$packages packages installed."; echo
1542 echo ""
1543 fi ;;
1544 xhtml-list)
1545 # Get info in receipts and build list.
1546 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
1547 if [ -n "$2" ]; then
1548 XHTML_LIST=$2
1549 else
1550 XHTML_LIST=installed-packages.html
1551 fi
1552 echo ""
1553 echo -e "\033[1m`gettext \"Creating xHTML list of installed packages\"`\033[0m"
1554 separator
1555 gettext "Generating xHTML header..."
1556 xhtml_header
1557 status
1558 # Packages
1559 gettext "Creating packages information..."
1560 for pkg in $INSTALLED/*
1561 do
1562 [ -f $pkg/receipt ] || continue
1563 EXTRAVERSION=""
1564 . $pkg/receipt
1565 xhtml_pkg_info
1566 packages=$(($packages+1))
1567 done
1568 status
1569 gettext "Generating xHTML footer..."
1570 xhtml_footer
1571 status
1572 # sed pkgs nb in header.
1573 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
1574 separator
1575 eval_gettext "\$XHTML_LIST created - $packages packages."; echo
1576 echo "" ;;
1577 list-mirror)
1578 # List all available packages on the mirror. Option --diff displays
1579 # last mirrored packages diff (see recharge).
1580 check_for_packages_list
1581 case $2 in
1582 --diff)
1583 if [ -f "$LOCALSTATE/packages.diff" ]; then
1584 echo ""
1585 echo -e "\033[1m`gettext \"Mirrored packages diff\"`\033[0m"
1586 separator
1587 cat $LOCALSTATE/packages.diff
1588 separator
1589 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
1590 eval_gettext "\$pkgs new packages listed on the mirror."; echo
1591 echo ""
1592 else
1593 echo ""
1594 gettext "Unable to list anything, no packages.diff found."; echo
1595 gettext "Recharge your current list to create a first diff."; echo
1596 echo ""
1597 fi && exit 0 ;;
1598 --text|--txt)
1599 echo ""
1600 echo -e "\033[1m`gettext \"List of available packages on the mirror\"`\033[0m"
1601 separator
1602 cat $LOCALSTATE/packages.txt ;;
1603 --raw|*)
1604 echo ""
1605 echo -e "\033[1m`gettext \"List of available packages on the mirror\"`\033[0m"
1606 separator
1607 cat $LOCALSTATE/packages.list ;;
1608 esac
1609 separator
1610 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
1611 eval_gettext "\$pkgs packages in the last recharged list."; echo
1612 echo "" ;;
1613 list-files)
1614 # List files installed with the package.
1615 check_for_package_on_cmdline
1616 check_for_receipt
1617 echo ""
1618 echo -e "\033[1m`gettext \"Installed files with:\"`\033[0m $PACKAGE"
1619 separator
1620 cat $INSTALLED/$PACKAGE/files.list | sort
1621 separator
1622 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
1623 eval_gettext "\$files files installed with \$PACKAGE."; echo
1624 echo "" ;;
1625 info)
1626 # Information about package.
1627 check_for_package_on_cmdline
1628 check_for_receipt
1629 EXTRAVERSION=""
1630 . $INSTALLED/$PACKAGE/receipt
1631 echo ""
1632 echo -e "\033[1m`gettext \"Tazpkg information\"`\033[0m
1633 ================================================================================
1634 `gettext \"Package :\"` $PACKAGE
1635 `gettext \"Version :\"` $VERSION$EXTRAVERSION
1636 `gettext \"Category :\"` `translate_category $CATEGORY`
1637 `gettext \"Short desc :\"` $SHORT_DESC
1638 `gettext \"Maintainer :\"` $MAINTAINER"
1639 if [ "$DEPENDS" ]; then
1640 echo -e "`gettext \"Depends :\"` $DEPENDS"
1641 fi
1642 if [ "$SUGGESTED" ]; then
1643 echo -e "`gettext \"Suggested :\"` $SUGGESTED"
1644 fi
1645 if [ "$BUILD_DEPENDS" ]; then
1646 echo -e "`gettext \"Build deps :\"` $BUILD_DEPENDS"
1647 fi
1648 if [ "$WANTED" ]; then
1649 echo -e "`gettext \"Wanted src :\"` $WANTED"
1650 fi
1651 if [ "$WEB_SITE" ]; then
1652 echo -e "`gettext \"Web site :\"` $WEB_SITE"
1653 fi
1654 separator
1655 echo "" ;;
1656 desc)
1657 # Display package description.txt if available.
1658 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1659 echo ""
1660 echo -e "\033[1m`gettext \"Description of:\"`\033[0m $PACKAGE"
1661 separator
1662 cat $INSTALLED/$PACKAGE/description.txt
1663 separator
1664 echo ""
1665 else
1666 echo ""
1667 gettext "Sorry, no description available for this package."; echo
1668 echo ""
1669 fi ;;
1670 search|-s)
1671 # Search for a package by pattern or name.
1672 PATTERN="$2"
1673 if [ -z "$PATTERN" ]; then
1674 echo ""
1675 gettext "Please specify a pattern or package name to search for."; echo
1676 gettext "Example : 'tazpkg search paint'"; echo
1677 echo ""
1678 exit 0
1679 fi
1680 echo ""
1681 echo -e "\033[1m`gettext \"Search result for:\"`\033[0m $PATTERN"
1682 echo ""
1683 # Default is to search in installed pkgs and the raw list.
1684 case $3 in
1685 -i|--installed)
1686 search_in_installed_packages ;;
1687 -l|--list)
1688 search_in_packages_list ;;
1689 -m|--mirror)
1690 search_in_packages_txt ;;
1691 *)
1692 search_in_installed_packages
1693 search_in_packages_list ;;
1694 esac ;;
1695 search-file)
1696 # Search for a file by pattern or name in all files.list.
1697 if [ -z "$2" ]; then
1698 echo ""
1699 gettext "Please specify a pattern or file name to search for."; echo
1700 gettext "Example : 'tazpkg search-file libnss'"; echo
1701 echo ""
1702 exit 0
1703 fi
1704 echo ""
1705 echo -e "\033[1m`gettext \"Search result for file\"`\033[0m $2"
1706 separator
1708 if [ "$3" == "--mirror" ]; then
1710 match=0
1711 for i in $LOCALSTATE/files.list.lzma \
1712 $LOCALSTATE/undigest/*/files.list.lzma; do
1713 [ -f $i ] || continue
1714 unlzma -c $i | grep -- ".*:.*$2" | awk '
1715 BEGIN { last="" }
1717 pkg=substr($0,0,index($0,":")-1);
1718 file=substr($0,index($0,":")+2);
1719 if (last != pkg) {
1720 last = pkg;
1721 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1723 printf("%s\n",file);
1724 }'
1725 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1726 done
1728 else
1730 # Check all pkg files.list in search match which specify the package
1731 # name and the full path to the file(s).
1732 for pkg in $INSTALLED/*
1733 do
1734 if grep -qs "$2" $pkg/files.list; then
1735 . $pkg/receipt
1736 echo ""
1737 echo -e "\033[1m`gettext \"Package\"` $PACKAGE:\033[0m"
1738 grep "$2" $pkg/files.list
1739 files=`grep $2 $pkg/files.list | wc -l`
1740 match=$(($match+$files))
1741 fi
1742 done
1744 fi
1745 pkg=$2
1746 if [ "$match" = "" ]; then
1747 eval_gettext "0 file found for: \$pkg"; echo
1748 echo ""
1749 else
1750 echo ""
1751 separator
1752 eval_gettext "\$match file(s) found for: \$pkg"; echo
1753 echo ""
1754 fi ;;
1755 search-pkgname)
1756 # Search for a package name
1757 if [ -z "$2" ]; then
1758 echo ""
1759 gettext "Please specify a pattern or file name to search for."; echo
1760 gettext "Example : 'tazpkg search-pkgname libnss'"; echo
1761 echo ""
1762 exit 0
1763 fi
1764 echo ""
1765 echo -e "\033[1m`gettext \"Search result for file\"`\033[0m $2"
1766 separator
1768 # Search for a file on mirror and output only the package name
1769 match=0
1770 for i in $LOCALSTATE/files.list.lzma \
1771 $LOCALSTATE/undigest/*/files.list.lzma; do
1772 [ -f $i ] || continue
1773 unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | awk '{ print $1 }'
1774 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | wc -l`))
1775 done
1776 file=$2
1777 if [ "$match" = "" ]; then
1778 eval_gettext "0 file found for : \$file"; echo
1779 echo ""
1780 else
1781 echo ""
1782 separator
1783 eval_gettext "$match pkg(s) found with file: \$file"; echo
1784 echo ""
1785 fi
1786 ;;
1787 install|-i)
1788 # Install .tazpkg packages.
1789 check_root
1790 check_for_package_on_cmdline
1791 check_for_package_file
1793 get_options_list="root forced list rootconfig"
1794 get_options
1796 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
1797 [ "$list" ] && INSTALL_LIST="$list"
1798 if [ "$rootconfig" ]; then
1799 if [ "$root" ]; then
1800 CACHE_DIR=$root/$CACHE_DIR
1801 SAVE_CACHE_DIR=$CACHE_DIR
1802 LOCALSTATE=$root/$LOCALSTATE
1803 else
1804 echo "rootconfig needs --root= option used." >&2
1805 exit 1
1806 fi
1807 fi
1809 # Get repositories priority list.
1810 look_for_priority
1812 # Check if forced install.
1813 if ! [ "$forced" ]; then
1814 check_for_installed_package $ROOT
1815 fi
1816 install_package $ROOT
1817 update_desktop_database $ROOT
1818 update_mime_database $ROOT
1819 update_icon_database $ROOT
1820 compile_glib_schemas $ROOT ;;
1821 install-list|get-install-list)
1822 # Install a set of packages from a list.
1823 check_root
1824 if [ -z "$2" ]; then
1825 echo ""
1826 gettext \
1827 "Please change directory (cd) to the packages repository and specify the
1828 list of packages to install. Example : tazpkg install-list packages.list"
1829 echo "" && exit 0
1830 fi
1831 # Check if the packages list exist.
1832 list_file=$2
1833 if [ ! -f "$list_file" ]; then
1834 gettext "Unable to find : $list_file"; echo
1835 exit 0
1836 else
1837 LIST=`cat $2`
1838 fi
1840 # Remember processed list
1841 export INSTALL_LIST="$2"
1843 # Set $COMMAND and install all packages.
1844 if [ "$1" = "get-install-list" ]; then
1845 COMMAND=get-install
1846 else
1847 COMMAND=install
1848 fi
1849 touch $2-processed
1851 # Upgrade tazpkg first. It may handle new features/formats...
1852 # then upgrade essential packages early
1853 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1854 slitaz-base-files tazpkg ; do
1855 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1856 [ -n "$pkg" ] || continue
1857 eval_gettext "Adding implicit depends \$pkg ..."; echo
1858 LIST="$pkg
1859 $LIST"
1860 done
1862 for pkg in $LIST
1863 do
1864 grep -qs ^$pkg$ $2-processed && continue
1865 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1866 done
1867 rm -f $2-processed ;;
1868 add-flavor)
1869 # Install a set of packages from a flavor.
1870 install_flavor $2 ;;
1871 install-flavor)
1872 # Install a set of packages from a flavor and purge other ones.
1873 install_flavor $2 --purge ;;
1874 set-release)
1875 # Change curent release and upgrade packages.
1876 RELEASE=$2
1877 if [ -z "$RELEASE" ]; then
1878 echo ""
1879 gettext "Please specify the release you want on the command line."; echo
1880 gettext "Example: tazpkg set-release cooking"; echo
1881 echo ""
1882 exit 0
1883 fi
1884 rm $LOCALSTATE/mirror
1885 echo "$RELEASE" > /etc/slitaz-release
1886 tazpkg recharge && tazpkg upgrade
1888 # Install missing depends
1889 cd $INSTALLED
1890 for i in * ; do
1891 DEPENDS=""
1892 . $i/receipt
1893 for j in $DEPENDS ; do
1894 [ -d $j ] || tazpkg get-install $j
1895 done
1896 done ;;
1897 remove|-r)
1898 # Remove packages.
1899 check_root
1900 check_for_package_on_cmdline
1901 get_options_list="root auto"
1902 get_options
1903 [ "$root" ] && ROOT="$root"
1904 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1905 echo ""
1906 eval_gettext "\$PACKAGE is not installed."; echo
1907 exit 0
1908 else
1909 ALTERED=""
1910 THE_PACKAGE=$PACKAGE # altered by receipt
1911 for i in $(cd $ROOT$INSTALLED ; ls); do
1912 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1913 DEPENDS=""
1914 . $ROOT$INSTALLED/$i/receipt
1915 case " $(echo $DEPENDS) " in
1916 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1917 esac
1918 done
1919 EXTRAVERSION=""
1920 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1921 fi
1922 echo ""
1923 if [ -n "$ALTERED" ]; then
1924 eval_gettext "The following packages depend on \$PACKAGE:"; echo
1925 for i in $ALTERED; do
1926 echo " $i"
1927 done
1928 fi
1929 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1930 if [ -n "$REFRESH" ]; then
1931 eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
1932 for i in $REFRESH; do
1933 echo " ${i%/modifiers}"
1934 done
1935 fi
1936 if [ "$auto" ]; then
1937 answer=`translate_querry y`
1938 else
1939 eval_gettext "Remove \$PACKAGE (\$VERSION\$EXTRAVERSION) ?"; echo
1940 gettext "Please confirm uninstallation"
1941 echo -n " (`translate_querry y`/`translate_querry N`) : "; read answer
1942 fi
1943 if [ "$answer" = "$(translate_querry y)" ]; then
1944 echo ""
1945 echo -e "\033[1m`gettext \"Removing:\"`\033[0m $PACKAGE"
1946 separator
1947 # Pre remove commands.
1948 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1949 pre_remove $ROOT
1950 fi
1951 gettext "Removing all files installed..."
1952 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1953 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1954 do
1955 for mod in `cat $ROOT$INSTALLED/$PACKAGE/modifiers`
1956 do
1957 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1958 done
1959 remove_with_path $ROOT$file
1960 done
1961 else
1962 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1963 do
1964 remove_with_path $ROOT$file
1965 done
1966 fi
1967 status
1968 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1969 post_remove $ROOT
1970 fi
1971 # Remove package receipt.
1972 gettext "Removing package receipt..."
1973 rm -rf $ROOT$INSTALLED/$PACKAGE
1974 status
1975 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1976 $LOCALSTATE/installed.md5 2> /dev/null
1977 # Log this activity
1978 log Removed
1979 if [ "$ALTERED" ]; then
1980 if [ "$auto" ]; then
1981 answer=`translate_querry y`
1982 else
1983 eval_gettext "Remove packages depending on \$PACKAGE"
1984 echo -n " (`translate_querry y`/`translate_querry N`) ? "
1985 read answer
1986 fi
1987 if [ "$answer" = "$(translate_querry y)" ]; then
1988 for i in $ALTERED; do
1989 if [ -d "$ROOT$INSTALLED/$i" ]; then
1990 tazpkg remove $i $ROOTOPTS
1991 fi
1992 done
1993 fi
1994 fi
1995 if [ "$REFRESH" ]; then
1996 if [ "$auto" ]; then
1997 answer=`translate_querry y`
1998 else
1999 eval_gettext "Reinstall packages modified by \$PACKAGE"
2000 echo -n " (`translate_querry y`/`translate_querry N`) ? "
2001 read answer
2002 fi
2003 if [ "$answer" = "$(translate_querry y)" ]; then
2004 for i in $REFRESH; do
2005 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
2006 eval_gettext "Check \$INSTALLED/\$i for reinstallation"; echo
2007 continue
2008 fi
2009 rm -r $ROOT$INSTALLED/$i
2010 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
2011 done
2012 fi
2013 fi
2014 else
2015 echo ""
2016 eval_gettext "Uninstallation of \$PACKAGE cancelled."; echo
2017 fi
2018 echo "" ;;
2019 extract)
2020 # Extract .tazpkg cpio archive into a directory.
2021 check_for_package_on_cmdline
2022 check_for_package_file
2023 echo ""
2024 echo -e "\033[1m`gettext \"Extracting:\"`\033[0m $PACKAGE"
2025 separator
2026 # If no directory destination is found on the cmdline
2027 # we create one in the current dir using the package name.
2028 if [ -n "$TARGET_DIR" ]; then
2029 DESTDIR=$TARGET_DIR/$PACKAGE
2030 else
2031 DESTDIR=$PACKAGE
2032 fi
2033 mkdir -p $DESTDIR
2034 gettext "Copying original package..."
2035 cp $PACKAGE_FILE $DESTDIR
2036 status
2037 cd $DESTDIR
2038 extract_package
2039 separator
2040 eval_gettext "\$PACKAGE is extracted to: \$DESTDIR"; echo
2041 echo "" ;;
2042 recompress)
2043 # Recompress .tazpkg cpio archive with lzma.
2044 check_for_package_on_cmdline
2045 check_for_package_file
2046 echo ""
2047 echo -e "\033[1m`gettext \"Recompressing:\"`\033[0m $PACKAGE"
2048 separator
2049 mkdir -p $TMP_DIR
2050 gettext "Copying original package..."
2051 cp $PACKAGE_FILE $TMP_DIR
2052 status
2053 cd $TMP_DIR
2054 extract_package
2055 gettext "Recompressing the fs... "
2056 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2057 rm -rf fs
2058 status
2059 gettext "Creating new package... "
2060 find . -print | cpio -o -H newc --quiet > \
2061 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
2062 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
2063 $TOP_DIR/$(basename $PACKAGE_FILE)
2064 status
2065 cd $TOP_DIR
2066 rm -rf $TMP_DIR ;;
2067 list-config)
2068 # List configuration files installed.
2069 if [ "$2" = "--box" ]; then
2070 mkdir -p $TMP_DIR && cd $TMP_DIR
2071 FILES="$INSTALLED/*/volatile.cpio.gz"
2072 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2073 for i in $FILES; do
2074 zcat $i | cpio -idm --quiet > /dev/null
2075 find * -type f 2>/dev/null | while read file; do
2076 if [ ! -e /$file ]; then
2077 echo -en "|--|--|--|`gettext \"File lost\"`"
2078 else
2079 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2080 cmp $file /$file > /dev/null 2>&1 || \
2081 echo -n "$(stat -c "%.16y" /$file)"
2082 fi
2083 echo "|/$file"
2084 done
2085 rm -rf *
2086 done
2087 cd $TOP_DIR
2088 rm -rf $TMP_DIR
2089 else
2090 echo ""
2091 echo -e "\033[1m`gettext \"Configuration files\"`\033[0m"
2092 separator
2093 for i in $INSTALLED/*/volatile.cpio.gz; do
2094 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2095 [ -f "$i" ] || continue
2096 zcat $i | cpio -t --quiet
2097 done | sed 's|^|/|' | sort
2098 separator
2099 echo ""
2100 fi ;;
2101 repack-config)
2102 # Create SliTaz package archive from configuration files.
2103 mkdir -p $TMP_DIR && cd $TMP_DIR
2104 CONFIG_VERSION=1.0
2105 mkdir config-$CONFIG_VERSION
2106 cd config-$CONFIG_VERSION
2107 for i in $INSTALLED/*/volatile.cpio.gz; do
2108 zcat $i | cpio -t --quiet
2109 done > files.list
2110 mkdir fs
2111 cd fs
2112 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2113 mkdir -p etc/tazlito
2114 for i in $INSTALLED/*/receipt; do
2115 EXTRAVERSION=""
2116 . $i
2117 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2118 done > etc/tazlito/config-packages.list
2119 cd ..
2120 echo "etc/tazlito/config-packages.list" >> files.list
2121 cat > receipt <<EOT
2122 # SliTaz package receipt.
2124 PACKAGE="config"
2125 VERSION="$CONFIG_VERSION"
2126 CATEGORY="base-system"
2127 SHORT_DESC="$(gettext "User configuration backup on ")$(date)"
2128 DEPENDS="$(ls $INSTALLED)"
2129 EOT
2130 cd ..
2131 tazpkg pack config-$CONFIG_VERSION
2132 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2133 cd $TOP_DIR
2134 rm -rf $TMP_DIR
2135 ;;
2136 repack)
2137 # Create SliTaz package archive from an installed package.
2138 check_for_package_on_cmdline
2139 check_for_receipt
2140 EXTRAVERSION=""
2141 . $INSTALLED/$PACKAGE/receipt
2142 echo ""
2143 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2144 separator
2145 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2146 eval_gettext "Can't repack \$PACKAGE"; echo
2147 exit 1
2148 fi
2149 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2150 eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; echo
2151 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2152 echo " $i"
2153 done
2154 exit 1
2155 fi
2156 MISSING=""
2157 while read i; do
2158 [ -e "$i" ] && continue
2159 [ -L "$i" ] || MISSING="$MISSING\n $i"
2160 done < $INSTALLED/$PACKAGE/files.list
2161 if [ -n "$MISSING" ]; then
2162 gettext "Can't repack, the following files are lost:"
2163 echo -e "$MISSING"
2164 exit 1
2165 fi
2166 mkdir -p $TMP_DIR && cd $TMP_DIR
2167 FILES="fs.cpio.lzma\n"
2168 for i in $(ls $INSTALLED/$PACKAGE) ; do
2169 [ "$i" = "volatile.cpio.gz" ] && continue
2170 [ "$i" = "modifiers" ] && continue
2171 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
2172 done
2173 ln -s / rootfs
2174 mkdir tmp
2175 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
2176 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2177 mv tmp/rootfs fs
2178 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2179 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2180 { cd fs; cpio -idm --quiet; cd ..; }
2181 fi
2182 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2183 . $INSTALLED/$PACKAGE/receipt
2184 repack_cleanup fs
2185 fi
2186 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
2187 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
2188 md5sum -s -c || {
2189 gettext "Can't repack, md5sum error."; echo
2190 cd $TOP_DIR
2191 rm -rf $TMP_DIR
2192 exit 1
2194 fi
2195 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2196 echo -e "$FILES" | cpio -o -H newc --quiet > \
2197 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2198 cd $TOP_DIR
2199 \rm -R $TMP_DIR
2200 eval_gettext "Package \$PACKAGE repacked successfully."; echo
2201 echo -e "`gettext \"Size\"` : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
2202 echo "" ;;
2203 pack)
2204 # Create SliTaz package archive using cpio and gzip.
2205 check_for_package_on_cmdline
2206 cd $PACKAGE
2207 if [ ! -f "receipt" ]; then
2208 gettext "Receipt is missing. Please read the documentation."; echo
2209 exit 0
2210 else
2211 echo ""
2212 echo -e "\033[1mPacking :\033[0m $PACKAGE"
2213 separator
2214 # Create files.list with redirecting find outpout.
2215 gettext "Creating the list of files..." && cd fs
2216 find . -type f -print > ../files.list
2217 find . -type l -print >> ../files.list
2218 cd .. && sed -i s/'^.'/''/ files.list
2219 status
2220 gettext "Creating md5sum of files..."
2221 while read file; do
2222 [ -L "fs$file" ] && continue
2223 [ -f "fs$file" ] || continue
2224 case "$file" in
2225 /lib/modules/*/modules.*|*.pyc) continue;;
2226 esac
2227 md5sum "fs$file" | sed 's/ fs/ /'
2228 done < files.list > md5sum
2229 status
2230 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
2231 description.txt 2> /dev/null | awk \
2232 '{ sz=$1 } END { print sz }')
2233 # Build cpio archives.
2234 gettext "Compressing the fs... "
2235 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2236 rm -rf fs
2237 status
2238 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2239 md5sum description.txt 2> /dev/null | awk \
2240 '{ sz=$1 } END { print sz }')
2241 gettext "Updating receipt sizes..."
2242 sed -i s/^PACKED_SIZE.*$// receipt
2243 sed -i s/^UNPACKED_SIZE.*$// receipt
2244 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2245 status
2246 gettext "Creating full cpio archive... "
2247 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2248 status
2249 gettext "Restoring original package tree... "
2250 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2251 status
2252 rm fs.cpio.lzma && cd ..
2253 separator
2254 eval_gettext "Package \$PACKAGE compressed successfully."; echo
2255 echo "`gettext \"Size\"` : `du -sh $PACKAGE.tazpkg`"
2256 echo ""
2257 fi ;;
2258 recharge)
2259 # Recharge packages.list from a mirror.
2260 check_root
2261 get_options_list="root forced list rootconfig"
2262 get_options
2263 ARG=$2
2264 if [ "$root" ]; then
2265 LOCALSTATE=$root$LOCALSTATE
2266 [ "${2#--}" != "$2" ] && ARG=$3
2267 fi
2268 if [ "$ARG" = main ]; then
2269 repository_to_recharge=$LOCALSTATE
2270 elif [ "$ARG" ]; then
2271 if [ -d "$LOCALSTATE/undigest/$ARG" ]; then
2272 repository_to_recharge=$LOCALSTATE/undigest/$ARG
2273 else
2274 echo "\$LOCALSTATE/undigest/$ARG `gettext \"doesn't exist.\"`" >&2
2275 exit 1
2276 fi
2277 else
2278 repository_to_recharge="$LOCALSTATE $LOCALSTATE/undigest/*"
2279 fi
2280 for path in $repository_to_recharge; do
2281 [ -f $path/mirror ] || continue
2282 cd $path
2284 # Quietly check if recharging is needed.
2285 [ -f ID ] && mv ID ID.bak
2286 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2287 if [ -f ID ] && fgrep -q `cat ID.bak 2>/dev/null || echo "null"` ID; then
2288 if [ "$path" = "$LOCALSTATE" ]; then
2289 repository_name=Main
2290 else
2291 repository_name="`gettext \"Undigest\"` $(basename $path)"
2292 fi
2293 echo "$repository_name `gettext \"is up to date.\"`"
2294 rm ID.bak
2295 continue
2296 fi
2298 # Don't let ID be a symlink when using local repository.
2299 if [ -f ID ]; then
2300 mv -f ID ID.bak
2301 cat ID.bak > ID
2302 rm ID.bak
2303 fi
2305 echo ""
2306 if [ "$path" != "$LOCALSTATE" ]; then
2307 echo -e "`gettext \"Recharging undigest\"` $(basename $path):"
2308 fi
2310 if [ -f "packages.list" ]; then
2311 gettext "Creating backup of the last packages list..."
2312 for i in wanted.txt depends.txt libraries.txt \
2313 packages.desc packages.md5 packages.txt \
2314 packages.list packages.equiv files.list.lzma \
2315 mirrors; do
2316 mv -f $i $i.bak 2>/dev/null
2317 done
2318 status
2319 fi
2321 for i in desc md5 txt list equiv; do
2322 download_from "$(cat mirror)" packages.$i
2323 done
2325 download_from "$(cat mirror)" files.list.lzma
2327 download_from "$(sed 's|packages/.*||' < mirror)" mirrors
2328 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
2329 suffix=$(head -1 mirror)
2330 suffix=packages${suffix#*/packages}
2331 for i in $(cat mirrors 2> /dev/null); do
2332 fgrep -qs $i mirror || echo $i$suffix >> mirror
2333 done
2334 if [ -f "packages.list.bak" ]; then
2335 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2336 sed -i s/+// packages.diff
2337 echo ""
2338 echo -e "\033[1m`gettext \"Mirrored packages diff\"`\033[0m"
2339 separator
2340 cat packages.diff
2341 new_pkgs=`cat packages.diff | wc -l`
2342 if [ "$new_pkgs" != 0 ]; then
2343 separator
2344 eval_gettext "\$new_pkgs new packages on the mirror."; echo
2345 echo ""
2346 else
2347 gettext "No new packages on the mirror."; echo
2348 echo ""
2349 fi
2350 else
2351 echo -e "
2352 ================================================================================"
2353 gettext \
2354 "Last packages.list is ready to use. Note that next time you recharge the
2355 list, a list of differences will be displayed to show new and upgradeable
2356 packages."
2357 echo ""
2358 fi
2359 done ;;
2360 up|upgrade|--help-up)
2362 # This is the new way to upgrade packages making 'upgrade' and
2363 # upgradeable out-of-date. This new way is much, much more faster!
2364 # Look into installed packages and get data from receipt, it is fast
2365 # and easy to handle vars after using only md5sum to compare packages
2367 # Options available for the command: up
2368 if [ "$COMMAND" == "--help-up" ]; then
2369 usage_up
2370 exit 1
2371 fi
2372 for opt in $@
2373 do
2374 case "$opt" in
2375 --recharge|-r)
2376 tazpkg recharge ;;
2377 --install|-i)
2378 install="y" ;;
2379 --check|-c)
2380 install="n" ;;
2381 esac
2382 done
2383 installed_md5=$LOCALSTATE/installed.md5
2384 look_for_priority
2385 for repo in $priority; do
2386 pkg_list=$repo/packages.list
2387 mtime=`find $pkg_list -mtime +7`
2388 if [ "$mtime" ]; then
2389 if [ "$repo" = "$LOCALSTATE" ]; then
2390 repo_name=main
2391 else
2392 repo_name="${repo##*/}"
2393 fi
2394 eval_gettext "\$pkg_list is older than one week... recharging"; echo
2395 tazpkg recharge $repo_name
2396 fi
2397 done
2398 echo -en "\n\033[1m"
2399 gettext "Package"
2400 echo -en "\033[26G " && gettext "Update type"
2401 echo -e "\033[0m"
2402 separator
2403 cd $INSTALLED
2404 echo "" > $UP_LIST
2405 blocked_count=0
2406 for pkg in *
2407 do
2408 unset VERSION EXTRAVERSION
2409 . $pkg/receipt
2410 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2411 $installed_md5 | awk '{print $1}')
2412 for repo in $priority; do
2413 pkg_desc=$repo/packages.desc
2414 pkg_list=$repo/packages.list
2415 pkg_md5=$repo/packages.md5
2417 if ! fgrep -q "$md5 $PACKAGE-" $pkg_md5; then
2418 # Jump to next repository in priority if pkg doesn't exists
2419 # in this one.
2420 grep -q ^$PACKAGE- $pkg_list || continue
2422 # Skip pkgs listed in $LOCALSTATE/blocked-packages.list
2423 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2424 blocked_count=$(($blocked_count+1))
2425 break
2426 fi
2428 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2429 if [ "$VERSION" == "$new" ]; then
2430 echo -n "$PACKAGE"
2431 echo -e "\\033[26G `gettext \"New build :\"` $md5"
2432 else
2433 echo -n "$PACKAGE"
2434 echo -e "\\033[26G `gettext \"New version :\"` $new"
2435 fi
2436 echo "$PACKAGE" >> $UP_LIST
2437 break
2438 fi
2439 done
2440 done
2441 sed -i /^$/d $UP_LIST
2442 upnb=$(cat $UP_LIST | wc -l)
2443 pkgs=$(ls | wc -l)
2444 if [ "$upnb" = 0 ]; then
2445 install="n"
2446 gettext -e "System is up-to-date...\n\n"
2447 else
2448 separator
2449 echo -en "\033[1m"
2450 if [ "$blocked_count" -gt 0 ]; then
2451 blocks=`eval_gettext " (\$blocked_count blocked)"`
2452 fi
2453 eval_gettext "You have \$upnb available upgrades\$blocks on \$pkgs installed packages"
2454 echo -e "\033[0m\n"
2455 fi
2456 # Pkgs to upgrade ? Skip, let install them all or ask user
2457 [ "$install" == "n" ] && exit 0
2458 if [ "$upnb" -gt 0 ]; then
2459 if [ "$install" == "y" ]; then
2460 continue
2461 else
2462 gettext "Do you wish to install them now: y/n ? "
2463 read install
2464 fi
2465 case "$install" in
2466 y|Y|yes|YES|Yes)
2467 for pkg in $(cat $UP_LIST)
2468 do
2469 echo 'y' | tazpkg get-install $pkg --forced
2470 done
2471 # List is generated each time and must be cleaned so
2472 # tazpkg-notify dont find upgrade anymore.
2473 rm $UP_LIST && touch $UP_LIST ;;
2474 *)
2475 gettext -e "Leaving without any upgrades installed.\n\n"
2476 exit 0 ;;
2477 esac
2478 fi
2479 echo "" ;;
2480 bugs)
2481 # Show known bugs in package(s)
2482 cd $INSTALLED
2483 shift
2484 LIST=$@
2485 [ -n "$LIST" ] || LIST=`ls`
2486 MSG=$(gettext "No known bugs.")
2487 for PACKAGE in $LIST; do
2488 BUGS=""
2489 EXTRAVERSION=""
2490 . $PACKAGE/receipt
2491 if [ -n "$BUGS" ]; then
2492 MSG=$(gettext "Bug list completed")
2493 echo ""
2494 eval_gettext "Bugs in package \$PACKAGE version \$VERSION\$EXTRAVERSION:"; echo
2495 cat <<EOT
2496 $BUGS
2497 EOT
2498 fi
2499 done
2500 echo "$MSG" ;;
2501 check)
2502 # Check installed packages set.
2503 check_root
2505 # Get repositories priority list.
2506 look_for_priority
2508 cd $INSTALLED
2509 for PACKAGE in `ls`; do
2510 if [ ! -f $PACKAGE/receipt ]; then
2511 eval_gettext "The package \$PACKAGE installation has not completed"; echo
2512 continue
2513 fi
2514 DEPENDS=""
2515 EXTRAVERSION=""
2516 . $PACKAGE/receipt
2517 if [ -s $PACKAGE/modifiers ]; then
2518 eval_gettext \
2519 "The package \$PACKAGE \$VERSION\$EXTRAVERSION has been modified by:"; echo
2520 for i in $(cat $PACKAGE/modifiers); do
2521 echo " $i"
2522 done
2523 fi
2524 MSG="$(eval_gettext "Files lost from \$PACKAGE \$VERSION\$EXTRAVERSION :")\n"
2525 while read file; do
2526 [ -e "$file" ] && continue
2527 if [ -L "$file" ]; then
2528 MSG="$MSG $(gettext "target of symlink")"
2529 fi
2530 echo -e "$MSG $file"
2531 MSG=""
2532 done < $PACKAGE/files.list
2533 MSG="$(gettext "Missing dependencies for") $PACKAGE $VERSION$EXTRAVERSION :\n"
2534 for i in $DEPENDS; do
2535 [ -d $i ] && continue
2536 [ -d $(equivalent_pkg $i) ] && continue
2537 echo -e "$MSG $i"
2538 MSG=""
2539 done
2540 MSG="$(gettext "Dependencies loop between") $PACKAGE and :\n"
2541 ALL_DEPS=""
2542 check_for_deps_loop $PACKAGE $DEPENDS
2543 done
2544 gettext "Looking for known bugs... "; echo
2545 tazpkg bugs
2546 if [ "$PACKAGE_FILE" = "--full" ]; then
2547 for file in */md5sum; do
2548 CONFIG_FILES=""
2549 . $(dirname "$file")/receipt
2550 [ -s "$file" ] || continue
2551 while read md5 f; do
2552 [ -f $f ] || continue
2553 for i in $CONFIG_FILES; do
2554 case "$f" in
2555 $i|$i/*) continue 2;;
2556 esac
2557 done
2558 echo "$md5 $f"
2559 done < "$file" | md5sum -c - 2> /dev/null | \
2560 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
2561 done
2562 FILES=" "
2563 for file in $(cat */files.list); do
2564 [ -d "$file" ] && continue
2565 case "$FILES" in *\ $file\ *) continue;; esac
2566 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2567 wc -l) -gt 1 ] || continue
2568 FILES="$FILES$file "
2569 eval_gettext "The following packages provide \$file :"; echo
2570 grep -l "^$(echo $file | grepesc)$" */files.list | while read f
2571 do
2572 pkg=${f%/files.list}
2573 echo -n " $pkg"
2574 if [ -f $pkg/modifiers ]; then
2575 echo -en " (`gettext \"overridden by\"`) $(echo "$(cat $pkg/modifiers)"))"
2576 fi
2577 echo ""
2578 done
2579 done
2580 MSG="$(gettext "No package has installed the following files"):\n"
2581 find /etc /bin /sbin /lib /usr /var/www \
2582 -not -type d 2> /dev/null | while read file; do
2583 case "$file" in *\[*) continue;; esac
2584 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2585 echo -e "$MSG $file"
2586 MSG=""
2587 done
2588 fi
2589 gettext "Check completed."; echo ;;
2590 block)
2591 # Add a pkg name to the list of blocked packages.
2592 check_root
2593 check_for_package_on_cmdline
2594 echo ""
2595 if grep -qs "^$PACKAGE" $BLOCKED; then
2596 eval_gettext "\$PACKAGE is already in the blocked packages list."; echo
2597 echo ""
2598 exit 0
2599 else
2600 eval_gettext "Add \$PACKAGE to : \$BLOCKED..."
2601 echo $PACKAGE >> $BLOCKED
2602 status
2603 # Log this activity
2604 . $INSTALLED/$PACKAGE/receipt
2605 log Blocked
2606 fi
2607 echo "" ;;
2608 unblock)
2609 # Remove a pkg name from the list of blocked packages.
2610 check_root
2611 check_for_package_on_cmdline
2612 echo ""
2613 if grep -qs "^$PACKAGE" $BLOCKED; then
2614 eval_gettext "Removing \$PACKAGE from : \$BLOCKED..."
2615 sed -i s/$PACKAGE/''/ $BLOCKED
2616 sed -i '/^$/d' $BLOCKED
2617 status
2618 # Log this activity
2619 . $INSTALLED/$PACKAGE/receipt
2620 log Unblocked
2621 else
2622 eval_gettext "\$PACKAGE is not in the blocked packages list."; echo
2623 echo ""
2624 exit 0
2625 fi
2626 echo "" ;;
2627 get)
2628 # Downlowd a package with wget.
2629 check_root
2630 check_for_package_on_cmdline
2631 check_for_packages_list
2633 get_options_list="root rootconfig"
2634 get_options
2636 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2637 if [ "$rootconfig" ]; then
2638 if [ "$root" ]; then
2639 CACHE_DIR=$root/$CACHE_DIR
2640 SAVE_CACHE_DIR=$CACHE_DIR
2641 LOCALSTATE=$root/$LOCALSTATE
2642 else
2643 echo "rootconfig needs --root= option used." >&2
2644 exit 1
2645 fi
2646 fi
2648 # Get repositories priority list.
2649 look_for_priority
2651 CURRENT_DIR=$PWD
2652 check_for_package_in_list
2653 cd $CACHE_DIR
2654 if [ -f "$PACKAGE.tazpkg" ]; then
2655 eval_gettext "\$PACKAGE already in the cache : \$CACHE_DIR"; echo
2656 # Check package download was finished
2657 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2658 eval_gettext "Continuing \$PACKAGE download"; echo
2659 download $PACKAGE.tazpkg
2661 if [ "$(md5sum $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.md5)" ]; then
2662 rm -f $PACKAGE.tazpkg
2663 download $PACKAGE.tazpkg
2664 fi
2665 else
2666 download $PACKAGE.tazpkg
2667 fi
2668 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2669 cp -a $PACKAGE_FILE $CURRENT_DIR
2670 ;;
2671 get-install|-gi)
2672 # Download and install a package.
2673 check_root
2674 check_for_package_on_cmdline
2675 check_for_packages_list
2677 get_options_list="root forced list rootconfig"
2678 get_options
2680 DO_CHECK=""
2681 [ "$forced" ] && DO_CHECK=no
2682 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2683 [ "$list" ] && INSTALL_LIST="$list"
2684 if [ "$rootconfig" ]; then
2685 if [ "$root" ]; then
2686 CACHE_DIR=$root/$CACHE_DIR
2687 SAVE_CACHE_DIR=$CACHE_DIR
2688 LOCALSTATE=$root/$LOCALSTATE
2689 else
2690 echo "rootconfig needs --root= option used." >&2
2691 exit 1
2692 fi
2693 fi
2695 # Get repositories priority list.
2696 look_for_priority
2698 AUTOEXEC="no"
2699 if ! check_for_package_in_list check; then
2700 PACKAGE=get-$PACKAGE
2701 AUTOEXEC=$PACKAGE
2702 check_for_package_in_list
2703 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2704 CACHE_DIR="${CACHE_DIR%/*}/get"
2705 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2706 $AUTOEXEC $ROOT
2707 exit 0
2708 fi
2709 fi
2710 # Check if forced install.
2711 if ! [ "$forced" ]; then
2712 check_for_installed_package $ROOT
2713 fi
2714 cd $CACHE_DIR
2715 if [ -f "$PACKAGE.tazpkg" ]; then
2716 eval_gettext "\$PACKAGE already in the cache : \$CACHE_DIR"; echo
2717 # Check package download was finished
2718 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2719 eval_gettext "Continuing \$PACKAGE download"; echo
2720 download $PACKAGE.tazpkg
2722 if [ "$(md5sum $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.md5)" ]; then
2723 rm -f $PACKAGE.tazpkg
2724 download $PACKAGE.tazpkg
2725 fi
2726 else
2727 echo ""
2728 download $PACKAGE.tazpkg
2729 fi
2730 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2731 [ "$rootconfig" ] && LOCALSTATE=${LOCALSTATE#$root}
2732 install_package $ROOT
2733 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2734 update_desktop_database $ROOT
2735 update_mime_database $ROOT ;;
2736 clean-cache|-cc)
2737 # Remove all downloaded packages.
2738 check_root
2739 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2740 echo ""
2741 echo -e "\033[1m`gettext \"Clean cache:\"`\033[0m $CACHE_DIR"
2742 separator
2743 gettext "Cleaning cache directory..."
2744 rm -rf $CACHE_DIR/*
2745 status && separator
2746 eval_gettext "\$files file(s) removed from cache."; echo -e "\n" ;;
2747 list-undigest)
2748 # list undigest URLs.
2749 if [ "$2" = "--box" ]; then
2750 for i in $LOCALSTATE/undigest/*/mirror; do
2751 [ -f $i ] || continue
2752 echo "$(basename $(dirname $i))|$(cat $i)"
2753 done
2754 else
2755 echo ""
2756 echo -e "\033[1m`gettext \"Current undigest(s)\"`\033[0m"
2757 separator
2758 for i in $LOCALSTATE/undigest/*/mirror; do
2759 if [ ! -f $i ]; then
2760 gettext "No undigest mirror found."; echo
2761 exit 1
2762 fi
2763 echo "$(basename $(dirname $i)) $(cat $i)"
2764 done
2765 echo ""
2766 fi ;;
2767 remove-undigest)
2768 # remove undigest URL.
2769 check_root
2770 undigest="$2"
2771 if [ -d $LOCALSTATE/undigest/$2 ]; then
2772 eval_gettext "Remove \$undigest undigest"
2773 echo -n " (`translate_querry y`/`translate_querry N`) ? "
2774 read answer
2775 if [ "$answer" = "$(translate_querry y)" ]; then
2776 eval_gettext "Removing \$undigest undigest..."
2777 rm -rf $LOCALSTATE/undigest/$2
2778 status
2779 rmdir $LOCALSTATE/undigest 2> /dev/null
2780 fi
2781 else
2782 eval_gettext "Undigest \$undigest not found"; echo
2783 fi ;;
2784 add-undigest|setup-undigest)
2785 # Add undigest URL.
2786 check_root
2787 undigest=$2
2788 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2789 if [ -z "$undigest" ]; then
2790 i=1
2791 while [ -d $LOCALSTATE/undigest/$i ]; do
2792 i=$(($i+1))
2793 done
2794 undigest=$i
2795 fi
2796 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2797 eval_gettext "Creating new undigest \$undigest."; echo
2798 mkdir $LOCALSTATE/undigest/$undigest
2799 fi
2800 setup_mirror $LOCALSTATE/undigest/$undigest $3 ;;
2801 setup-mirror)
2802 # Change mirror URL.
2803 check_root
2804 setup_mirror $LOCALSTATE $2 ;;
2805 reconfigure)
2806 # Replay post_install from receipt
2807 check_for_package_on_cmdline
2808 check_root
2809 ROOT=""
2810 while [ -n "$3" ]; do
2811 case "$3" in
2812 --root=*)
2813 ROOT="${3#--root=}/" ;;
2814 *) shift 2
2815 echo -e "\n`gettext \"Unknow option\"` $*.\n" >&2
2816 exit 1 ;;
2817 esac
2818 shift
2819 done
2820 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2821 check_for_receipt $ROOT
2822 # Check for post_install
2823 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2824 . $ROOT$INSTALLED/$PACKAGE/receipt
2825 post_install $ROOT
2826 # Log this activity
2827 [ -n "$ROOT" ] || log Reconfigured
2828 else
2829 echo ""
2830 eval_gettext "Nothing to do for \$PACKAGE."; echo
2831 fi
2832 else
2833 echo ""
2834 eval_gettext "Package \$PACKAGE is not installed."; echo
2835 gettext "Install package with 'tazpkg install' or 'tazpkg get-install'"; echo
2836 echo ""
2837 fi ;;
2838 shell)
2839 # Tazpkg SHell
2840 if test $(id -u) = 0 ; then
2841 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2842 else
2843 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2844 fi
2845 if [ ! "$2" = "--noheader" ]; then
2846 clear
2847 echo ""
2848 echo -e "\033[1m`gettext \"Tazpkg SHell\"`.\033[0m"
2849 separator
2850 gettext "Type 'usage' to list all available commands or 'quit' or 'q' to exit."; echo
2851 echo ""
2852 fi
2853 while true
2854 do
2855 echo -en "$PROMPT"; read cmd
2856 case $cmd in
2857 q|quit)
2858 break ;;
2859 shell)
2860 gettext "You are already running a Tazpkg SHell."; echo ;;
2861 su)
2862 su -c 'exec tazpkg shell --noheader' && break ;;
2863 "")
2864 continue ;;
2865 *)
2866 tazpkg $cmd ;;
2867 esac
2868 done ;;
2869 depends)
2870 # Display dependencies tree
2871 cd $INSTALLED
2872 ALL_DEPS=""
2873 if [ -f $2/receipt ]; then
2874 dep_scan $2 ""
2875 fi ;;
2876 rdepends)
2877 # Display reverse dependencies tree
2878 cd $INSTALLED
2879 ALL_DEPS=""
2880 if [ -f $2/receipt ]; then
2881 rdep_scan $2
2882 fi ;;
2883 convert|-c)
2884 # convert misc package format to .tazpkg
2885 check_for_package_file
2886 [ -n "$TARGET_DIR" -a -s "$TARGET_DIR/files.list.lzma" ] &&
2887 TMPLOCALSTATE="$TARGET_DIR"
2888 if [ "$(dd if=$PACKAGE_FILE bs=8 count=1 skip=1 2> /dev/null)" \
2889 == "debian-b" ]; then
2890 convert_deb
2891 else
2892 case "$PACKAGE_FILE" in
2893 *.deb|*.udeb)
2894 convert_deb;;
2895 *.rpm)
2896 convert_rpm;;
2897 *.tgz)
2898 convert_tgz;;
2899 *.apk|*.pkg.tar.gz)
2900 convert_arch;;
2901 *.ipk|*.opk)
2902 convert_ipk;;
2903 *)
2904 gettext "Unsupported format"; echo ;;
2905 esac
2906 fi ;;
2907 link)
2908 # link a package from another slitaz installation
2909 PACKAGE=$2
2910 if [ ! -d "$TARGET_DIR" -o \
2911 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2912 cat <<EOT
2913 usage: tazpkg link package_name slitaz_root
2914 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2915 your running system ram.
2916 EOT
2917 exit 1
2918 fi
2919 if [ -e "$INSTALLED/$PACKAGE" ]; then
2920 eval_gettext "\$PACKAGE is already installed."; echo
2921 exit 1
2922 fi
2923 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2924 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2925 MISSING=""
2926 for i in $DEPENDS; do
2927 [ -e $INSTALLED/$i ] && continue
2928 MISSING="$MISSING$i "
2929 eval_gettext "Missing : \$i"; echo
2930 done
2931 if [ -n "$MISSING" ]; then
2932 echo ""
2933 gettext "Link all missing dependencies"
2934 echo -n " (`translate_querry y`/`translate_querry N`) ? "
2935 read answer
2936 echo ""
2937 if [ "$answer" = "$(translate_querry y)" ]; then
2938 for i in $MISSING; do
2939 tazpkg link $i $TARGET_DIR
2940 done
2941 else
2942 echo ""
2943 eval_gettext "Leaving dependencies for \$PACKAGE unresolved."; echo
2944 gettext "The package is installed but probably will not work."; echo
2945 echo ""
2946 fi
2947 fi
2948 . $INSTALLED/$PACKAGE/receipt
2949 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2950 pre_install
2951 fi
2952 while read path; do
2953 [ -e $path ] && continue
2954 while true; do
2955 dir=$(dirname $path)
2956 [ -e $dir ] && break
2957 path=$dir
2958 done
2959 ln -s $TARGET_DIR$path $dir
2960 done < $INSTALLED/$PACKAGE/files.list
2961 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2962 post_install
2963 fi ;;
2964 usage|*)
2965 # Print a short help or give usage for an unknown or empty command.
2966 usage ;;
2967 esac
2969 exit 0