tazpkg view tazpkg @ rev 517

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