tazpkg view tazpkg @ rev 582

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