tazpkg view tazpkg @ rev 580

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