tazpkg view tazpkg @ rev 588

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