tazpkg view modules/install @ rev 970

Modules "get" and "install": fix cookmode again
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 26 18:53:08 2018 +0200 (2018-11-26)
parents ed2904dae9f2
children 9d683c983e2e
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # install - TazPkg module
4 # Install packages
7 # Connect function libraries
8 . /lib/libtaz.sh
9 . /usr/lib/slitaz/libpkg.sh
12 # Get TazPkg working environment
13 . @@MODULES@@/getenv
14 # $CACHE_DIR will change, it based on unchanged value of $SAVE_CACHE_DIR
15 SAVE_CACHE_DIR="$CACHE_DIR"
18 . @@MODULES@@/find-depends
23 # Log TazPkg activity
25 log_pkg() {
26 debug "\nlog_pkg('$1')\n PACKAGE='$PACKAGE'\n VERSION='$VERSION'\n EXTRAVERSION='$EXTRAVERSION'"
28 local extra
30 [ "$1" == 'Installed' ] && \
31 extra=" - $(fgrep " $PACKAGE-$VERSION" "$PKGS_DB/installed.$SUM" | awk '{print $1}')"
32 debug " extra='$extra'"
34 [ -w "$LOG" ] &&
35 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
36 }
39 # get an already installed package from packages.equiv
41 equivalent_pkg() {
42 # input: $1 = dependency package name (like "nano");
43 # $2 = package path/name for which dependency tested
44 local i rep rules rule out
46 if [ -n "$local" ]; then
47 # Search for virtual packages
48 if [ -n "$cookmode" ]; then
49 pi="/home/slitaz/packages/packages-$SLITAZ_ARCH.info"
50 [ -e "$pi" ] || pi='/home/slitaz/packages/packages.info'
51 else
52 pi="$(dirname "$2")/packages.info"
53 fi
55 [ -f "$pi" ] &&
56 out=$(awk -F$'\t' -vpkg="$1" '{
57 # if package name or provided package name matched
58 if ($1 == pkg || index(" " $10 " ", " " pkg " ")) { print $1 }
59 }' "$pi")
60 for i in $out; do
61 # If package installed
62 [ -f "$PKGS_DB/installed/$i/receipt" ] && out="$i" && break
63 unset out
64 done
65 else
66 rules=$(for rep in $PRIORITY; do
67 grep -hs "^$1=" "$rep/packages.equiv"
68 done | sed "s|^$1=||")
69 debug " >rules='$rules'"
71 for rule in $rules; do
72 debug " >rule='$rule'"
73 case $rule in
74 *:*)
75 debug '-- x:x'
76 # format 'alternative:newname'
77 # if alternative is installed then substitute newname
78 out="${rule#*:}"
79 awk -F$'\t' -vp="${rule%:*}" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
80 debug '-- x:x /'
81 ;;
82 *)
83 debug '-- x'
84 # unconditional substitution
85 out="$rule"
86 awk -F$'\t' -vp="$rule" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
87 debug '-- x /'
88 ;;
89 esac
90 unset out
91 done
92 fi
93 debug '--'
94 # if not found in packages.equiv then no substitution
95 echo "${out:-$1}"
96 }
99 # Check and install all missing deps.
100 # Auto install or ask user then install all missing deps from local dir, CD-ROM,
101 # media or from the mirror.
103 install_all_deps() {
104 # input: $1 = package file to check/install missing dependencies
105 # ROOT READY
106 # dep: equivalent_pkg.
108 debug "\ninstall_all_deps('$1')"
110 local TMP_DIR DEPENDS num missing_packages equiv pkg answer dir found pkgfile
112 # Check for missing deps listed in a receipt packages.
114 # Get the receipt's variable DEPENDS
115 DEPENDS=$(
116 TMP_DIR=$(mktemp -d); cd "$TMP_DIR"
117 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
118 . ./receipt; echo $DEPENDS
119 rm -rf "$TMP_DIR"
120 )
122 unset num missing_packages
123 for depend in $DEPENDS; do
124 debug " depend='$depend'"
125 equiv=$(equivalent_pkg $depend "$1")
126 debug " equiv='$equiv'\n"
127 if [ ! -d "$INSTALLED/$equiv" ]; then
128 missing_packages="$missing_packages $equiv"
129 num=$((num+1))
130 elif [ ! -f "$INSTALLED/$equiv/receipt" ]; then
131 [ -z "$quiet" ] && _ 'WARNING! Dependency loop between "%s" and "%s".' "$PACKAGE" "$equiv"
132 fi
133 done
135 # Nothing to install, exit function
136 [ -z "$num" ] && return
139 title "$(_ 'Tracking dependencies for package "%s"' "$PACKAGE")"
141 # Individual messages for each missing package
142 [ -z "$quiet" ] && \
143 for pkg in $missing_packages; do
144 _ 'Missing package "%s"' "$pkg"
145 done
147 footer "$(_p \
148 '%s missing package to install.' \
149 '%s missing packages to install.' "$num" \
150 "$num")"
153 if [ "$AUTO_INSTALL_DEPS" == 'yes' ] || [ -n "$quiet" ]; then
154 # Quietly not displaying anything. Assume 'yes' unless '--noconfirm' is provided
155 answer=0
156 [ -n "$noconfirm" ] && answer=1
157 else
158 # Display question; wait for answer or print auto-answer
159 newline
160 confirm "$(_ 'Install all missing dependencies? (y/N)')"
161 answer=$?
162 newline
163 fi
164 debug " answer='$answer'"
166 dir="$(dirname "$1")"
167 debug " dir='$dir'"
169 # We can install packages from /home/boot/packages at boot time
170 # Also we can prefer local packages over mirrored/cached using '--local' option
171 [ "$dir" == '/home/boot/packages' ] && local='yes'
172 debug " local='$local'"
174 # "--nodeps" option prevents to install dependencies
175 if [ "$answer" -eq 0 -a -z "$nodeps" ]; then
176 debug " let's install missing packages"
177 for pkg in $missing_packages; do
178 debug " pkg='$pkg'"
179 [ -d "$INSTALLED/$pkg" ] && continue
180 # Package not installed
182 found='0'; namever=''; pkgfile=''
183 # Prefer local packages
184 if [ -n "$local" ]; then
185 [ -z "$quiet" ] && _ 'Checking if package "%s" exists in local list...' "$pkg"
186 [ -n "$cookmode" ] && dir='/home/slitaz/packages'
188 pi="$dir/packages-$SLITAZ_ARCH.info"
189 [ -e "$pi" ] || pi="$dir/packages.info"
191 # Find local package
192 if [ -f "$pi" ]; then
193 # Packages database exists (should be everfresh!)
195 # Find local package
196 namever=$(awk -F$'\t' -vpkg="$pkg" '{
197 if ($1 == pkg) { printf("%s-%s", $1, $2); exit; }
198 }' "$pi") # <namever> = <package_name>-<package_version>
200 # Find local provided package
201 [ -n "$namever" ] ||
202 namever=$(awk -F$'\t' -vpkg="$pkg" '{
203 if (index(" " $10 " ", " " pkg " ")) { printf("%s-%s", $1, $2); exit; }
204 }' "$pi") # <namever> = <package_name>-<package_version>
206 # Package file may be in form <namever>-<arch>.tazpkg or <namever>-any.tazpkg, so find one
207 if [ -n "$namever" ]; then
208 pkgfile=$(find "$dir" -name "$namever-$SLITAZ_ARCH.tazpkg")
209 [ -n "$pkgfile" ] ||
210 pkgfile=$(find "$dir" -name "$namever-any.tazpkg")
211 fi
213 [ -n "$pkgfile" ] && found='1'
214 else
215 # Packages DB missing, proceed to sniff packages
216 tempd="$(mktemp -d)"; cd "$tempd"
217 for pkgfile in $dir/$pkg-*-$SLITAZ_ARCH.tazpkg $dir/$pkg-*-any.tazpkg; do
218 [ -e "$pkgfile" ] || continue
219 # Extract receipt from each matched package
220 cpio -F "$pkgfile" -i receipt >/dev/null 2>&1
221 name=$(. ./receipt; echo $PACKAGE)
222 [ "$name" == "$pkg" ] && found='1' && break
223 # Install the first matched package: normally there is only one package
224 # with the $PACKAGE matched in the receipt
225 rm receipt
226 done
227 rm -r "$tempd"
228 fi
229 fi
230 debug " found='$found'"
232 if [ "$found" -eq 1 ]
233 then tazpkg install "$pkgfile"
234 else tazpkg get-install "$pkg"
235 fi
236 done
237 else
238 # Answered 'No' to install dependencies, or '--nodeps' option given
239 newline
240 _ 'Leaving dependencies for package "%s" unresolved.' "$PACKAGE"
241 _ 'The package will be installed but will probably not work.'
242 newline
243 fi
244 }
247 # Extract a package with cpio and gzip/lzma.
249 extract_package() {
250 # input: $1 - path to package to be extracted; package should be in the current dir
251 # ROOT INDEPENDENT
252 action 'Extracting package...'
254 # Extract "outer layer": cpio; remove the original package file
255 cpio -idm --quiet < "$1" && rm -f "$1"
257 # "Inner layer" may vary
258 if [ -f fs.cpio.lzma ]; then
259 # "Plain" cpio.lzma
260 unlzma < fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
261 elif [ -f fs.cpio.gz ]; then
262 # "Fast" cpio.gz (used to pack-then-install process in most of get-packages)
263 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
264 fi
266 status
267 }
270 # Print short package description
272 print_short_description() {
273 # TODO: undigest repo support? priority...
274 # ROOT READY
275 local short_desc=''
277 # Try to find localized short description
278 for LC in $LANG ${LANG%_*}; do
279 [ -e "$PKGS_DB/packages-desc.$LC" ] &&
280 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $2; exit}' "$PKGS_DB/packages-desc.$LC")
281 done
283 # Try to find short description for mirrored package
284 if [ -z "$short_desc" ]; then
285 pi="$PKGS_DB/packages-$SLITAZ_ARCH.info"
286 [ -e "$pi" ] || pi="$PKGS_DB/packages.info"
288 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $4; exit}' "$pi")
289 fi
291 [ -z "$short_desc" ] && short_desc="$SHORT_DESC"
293 longline "$short_desc"
294 }
297 grepesc() {
298 sed 's/\[/\\[/g'
299 }
304 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
306 # Block of receipt function callers
307 # Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
308 # Few receipts functions should be patched now.
310 # Input: $1 = path to the receipt to be processed
312 # Pre-install commands
313 call_pre_install() {
314 local tmp
315 if grep -q '^pre_install()' "$1"; then
316 action 'Execute pre-install commands...'
317 tmp="$(mktemp)"
318 cp "$1" "$tmp"
319 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
320 ( . "$tmp"; pre_install "$root" )
321 status
322 rm "$tmp"
323 fi
325 }
326 # Post-install commands
327 call_post_install() {
328 local tmp
329 if grep -q '^post_install()' "$1"; then
330 action 'Execute post-install commands...'
331 tmp="$(mktemp)"
332 cp "$1" "$tmp"
333 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
334 ( . "$tmp"; post_install "$root" )
335 status
336 rm "$tmp"
337 fi
338 }
341 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
344 # This function installs a package in the rootfs.
346 install_package() {
347 # input: $1 = path to package to be installed
348 # dep: install_all_deps, print_short_description, extract_package, grepesc.
350 debug "\ninstall_package('$1')"
351 local dir
353 PACKAGE_FILE="$1"
354 TMP_DIR="$(mktemp -d)"
356 # Get receipt's variables and functions
357 { cd "$TMP_DIR"; cpio --quiet -i receipt < "$PACKAGE_FILE" >/dev/null 2>&1; }
358 # Why next code? "Bad" receipt sourcing can redefine some vital TazPkg variables.
359 (
360 . "$TMP_DIR/receipt"
361 cat > "$TMP_DIR/receipt.var" <<EOT
362 PACKAGE="$PACKAGE"
363 VERSION="$VERSION"
364 EXTRAVERSION="$EXTRAVERSION"
365 CATEGORY="$CATEGORY"
366 SHORT_DESC="${SHORT_DESC//\"/\"}"
367 WEB_SITE="$WEB_SITE"
368 TAGS="$TAGS"
369 DEPENDS="$DEPENDS"
370 CONFIG_FILES="$CONFIG_FILES"
371 PACKED_SIZE="$PACKED_SIZE"
372 UNPACKED_SIZE="$UNPACKED_SIZE"
373 EOT
374 rm "$TMP_DIR/receipt"
375 )
376 . "$TMP_DIR/receipt.var"
379 # Make sure folder exists on new installs or upgrades
380 mkdir -p "$INSTALLED/$PACKAGE"
382 # Keep "modifiers" and "files.list" on upgrade
383 find "$INSTALLED/$PACKAGE" -type f \( ! -name modifiers ! -name files.list \) -delete
385 # Update "installed.md5"
386 # TODO: discontinue using 'installed.md5'
387 touch "$PKGS_DB/installed.$SUM"
388 sed -i "/ $(basename "$PACKAGE_FILE")$/d" "$PKGS_DB/installed.$SUM" 2>/dev/null
389 cd "$(dirname "$PACKAGE_FILE")"
390 $CHECKSUM "$(basename "$PACKAGE_FILE")" >> "$PKGS_DB/installed.$SUM"
392 # Resolve package dependencies before package installation
393 install_all_deps "$PACKAGE_FILE"
396 # TODO: why this list-processed in the $PKGS_DB?
397 #[ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> "$PKGS_DB/$INSTALL_LIST-processed"
399 # Special mode for using in cookutils: clearly show whether freshly used package or cached one
400 if [ -n "$cookmode" ]; then
401 f=${PACKAGE_FILE%/*}; f=${f%/*}; f=${f##*/}
402 if [ "$f" == "$(cat /etc/slitaz-release)" ]; then
403 _ 'Installing (web/cache): %s' "$(basename $PACKAGE_FILE .tazpkg)"
404 else
405 _ 'Installing (pkg/local): %s' "$(basename $PACKAGE_FILE .tazpkg)"
406 fi
407 fi
409 if [ -n "$sequence" ]; then
410 title 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence"
411 else
412 title 'Installation of package "%s"' "$PACKAGE"
413 fi
415 if [ -z "$quiet" ]; then
416 print_short_description "$PACKAGE"
417 separator '-'
418 fi
420 action 'Copying package...'
421 cp "$PACKAGE_FILE" "$TMP_DIR"
422 status
424 cd "$TMP_DIR"
425 extract_package "$(basename "$PACKAGE_FILE")"
427 # Include temporary receipt to get the right variables
428 . "$TMP_DIR/receipt.var"
430 cd "$INSTALLED"
433 # Get files to remove if upgrading
434 # IFS here modified temporarily for processing filenames with spaces
435 IFS=$'\n'
436 if [ -f "$PACKAGE/files.list" ]; then
437 while read file; do
438 grep -q "^$(echo "$file" | grepesc)$" "$TMP_DIR/files.list" && continue
439 for i in $(cat "$PACKAGE/modifiers" 2>/dev/null;
440 fgrep -sl "$PACKAGE" */modifiers | cut -d/ -f1); do
441 grep -qs "^$(echo "$file" | grepesc)$" "$i/files.list" && continue 2
442 done
443 echo "$file"
444 done < "$PACKAGE/files.list" > "$TMP_DIR/files2remove.list"
445 fi
446 unset IFS
449 # Remember modified packages
450 action 'Remember modified packages...'
451 {
452 check=false
453 # TODO: why '[' the special?
454 # FIXME: we have files with spaces in our packages!
455 for i in $(fgrep -v [ $TMP_DIR/files.list); do
456 [ -e "$root$i" ] || continue
457 [ -d "$root$i" ] && continue
458 echo "- $i"
459 check=true
460 done ;
461 $check && \
462 for i in *; do
463 [ "$i" == "$PACKAGE" ] && continue
464 [ -s "$i/files.list" ] || continue
465 awk "{ printf \"$i %s\\n\",\$1 }" < "$i/files.list"
466 done;
467 } | awk '
468 {
469 if ($1 == "-" || file[$2] != "") {
470 file[$2] = file[$2] " " $1
471 if ($1 != "-") {
472 if (pkg[$1] == "") all = all " " $1
473 pkg[$1] = pkg[$1] " " $2
474 }
475 }
476 }
477 END {
478 for (i = split(all, p, " "); i > 0; i--)
479 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
480 printf "%s %s\n",p[i],f[j];
481 }
482 ' | while read dir file; do
483 if grep -qs "^$dir$" "$PACKAGE/modifiers"; then
484 # Do not overload an overloaded file !
485 rm "$TMP_DIR/$file" 2>/dev/null
486 continue
487 fi
488 grep -qs "^$PACKAGE$" "$dir/modifiers" && continue
489 if [ -s "$dir/volatile.cpio.gz" ]; then
490 # We can modify backed up files without notice
491 zcat "$dir/volatile.cpio.gz" | cpio -t --quiet | \
492 grep -q "^${file#/}$" && continue
493 fi
494 echo "$PACKAGE" >> "$dir/modifiers"
495 done
496 status
499 cd "$TMP_DIR"
500 # Copy receipt, etc.
501 for file in receipt files.list description.txt $CHECKSUM; do
502 [ -f "$file" ] && cp "$file" "$INSTALLED/$PACKAGE"
503 done
506 # Pre-install commands
507 call_pre_install "$INSTALLED/$PACKAGE/receipt"
510 if [ -n "$CONFIG_FILES" ]; then
511 # Save "official" configuration files
512 action 'Saving configuration files...'
513 debug "\n"
515 cd fs
516 local config_file
517 for config_file in $CONFIG_FILES; do
518 debug " config_file: '$config_file'"
519 find ${config_file#/} -type f 2>/dev/null
520 done | cpio -o -H newc --quiet | gzip -9 > "$INSTALLED/$PACKAGE/volatile.cpio.gz"
521 cd ..
523 if [ -z "$newconf" ]; then
524 debug " no '--newconf': clean official config files"
525 # Keep user configuration files: remove "official" from fs tree
526 for config_file in $CONFIG_FILES; do
527 for config_file_official in $(find "fs$config_file" ! -type d 2>/dev/null | sed 's|^fs||'); do
528 if [ -e "$root$config_file_official" ]; then
529 debug " official '$config_file_official' will be skipped"
530 rm "fs$config_file_official"
531 else
532 debug " official '$config_file_official' will be written"
533 fi
534 done
535 done
536 fi
537 # always '[ Done ]' status, unless '--newconf' is passed or not
538 :; status
539 fi
542 if [ -n "$(ls fs/* 2>/dev/null)" ]; then
543 action 'Installing package...'
545 debug '\n resolving destination links in source'
546 IFS=$'\n'
547 for dir in $(find fs -type d | sed 's|^fs||;/^$/d'); do
548 if ldir=$(readlink -n $root$dir); then
549 debug " * mv 'fs$dir'\n -> 'fs${dir%/*}/$ldir'"
550 mkdir -p "fs${dir%/*}/${ldir%/*}"
551 mv "fs$dir" "fs${dir%/*}/$ldir"
552 fi
553 done
554 unset IFS
556 debug ' copying folders and files to destination'
557 cp -af fs/* "$root/"
558 status
559 fi
562 if [ -s files2remove.list ]; then
563 action 'Removing old files...'
564 while read file; do
565 dir="$root$file"
566 # Remove specified file
567 rm -f "$dir"
568 # Recursive remove non-empty up-dirs
569 while [ "$dir" != "$root/" ]; do
570 dir=$(dirname "$dir")
571 rmdir "$dir" 2>/dev/null || break
572 done
573 done < files2remove.list
574 :; status
575 fi
578 # Remove the temporary random directory.
579 action "Removing all tmp files..."
580 cd ..; rm -rf "$TMP_DIR"
581 status
584 # Post install commands
585 call_post_install "$INSTALLED/$PACKAGE/receipt"
590 # Update system databases
591 # Updating DBs is important process, so not to hide such errors (localized):
592 # chroot: can't execute '/usr/bin/***': No such file or directory
594 local fl="$INSTALLED/$PACKAGE/files.list" upd=0 udesk umime uicon uschm ukrnl ukrnlfs
596 fgrep /usr/share/applications/ "$fl" | fgrep -q .desktop && udesk='yes'
597 fgrep -q /usr/share/mime "$fl" && umime='yes'
598 fgrep -q /usr/share/icon/hicolor "$fl" && uicon='yes'
599 fgrep /usr/share/glib-2.0/schemas "$fl" | fgrep -q .xml && uschm='yes'
600 fgrep /usr/lib/gdk-pixbuf "$fl" | fgrep -q .so && upixb='yes'
601 if fgrep -q /lib/modules "$fl"; then
602 ukrnl='yes'
603 if fgrep -q /kernel/fs/ "$fl"; then
604 ukrnlfs='yes'
605 fi
606 fi
608 if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then
609 action 'Update system databases...'
610 upd=1
611 fi
613 # package 'desktop-file-utils'
614 [ -n "$udesk" ] && chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
615 # package 'shared-mime-info'
616 [ -n "$umime" ] && chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
617 # packages 'gtk+', 'gtk+3'
618 [ -n "$uicon" ] && chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
619 # package 'glib'
620 # hide messages like next because they are unresolved (we may to patch glib to hide them, almost the same)
621 # warning: Schema '*' has path '*'. Paths starting with '/apps/', '/desktop/' or '/system/' are deprecated.
622 [ -n "$uschm" ] && chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas 2>&1 | fgrep -v '/apps/'
623 # package 'gdk-pixbuf'
624 [ -n "$upixb" ] && chroot "$root/" /usr/bin/gdk-pixbuf-query-loaders --update-cache
626 if [ -n "$ukrnlfs" ]; then
627 for i in $(awk -F/ '{if($6=="fs" && $8~$7)print $7}' "$fl" | sort -u); do
628 touch "$root/etc/filesystems"
629 grep -q "^$i\$" "$root/etc/filesystems" || echo "$i" >> "$root/etc/filesystems"
630 done
631 fi
632 # packages 'busybox', 'kmod', 'depmod'
633 [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a
635 [ "$upd" -eq 1 ] && status
640 # Update installed.info ----------------------------------------------------
641 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
643 # Remove newlines from some receipts
644 DEPENDS=$(echo $DEPENDS)
645 PKG_SUM="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.$SUM" | cut -d' ' -f1)"
647 # Calculate "release checksum": md5sum of file containing md5sums of:
648 # a) all files, b) receipt, and c) description.txt.
649 rsumf=$(mktemp)
650 cp $INSTALLED/$PACKAGE/md5sum $rsumf
651 md5sum $INSTALLED/$PACKAGE/receipt | sed 's| [^ ]*/| |' >> $rsumf
652 [ -e "$INSTALLED/$PACKAGE/description.txt" ] &&
653 md5sum $INSTALLED/$PACKAGE/description.txt | sed 's| [^ ]*/| |' >> $rsumf
654 RSUM=$(md5sum $rsumf | awk '{print $1}')
655 rm $rsumf
657 ii="$PKGS_DB/installed.info"
659 # Remove old entry
660 sed -i "/^$PACKAGE /d" "$ii"
662 cat >> "$ii" <<EOT
663 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $PKG_SUM
664 EOT
666 TEMP_FILE="$(mktemp)"
667 sort "$ii" > "$TEMP_FILE"; mv -f "$TEMP_FILE" "$ii"; chmod a+r "$ii"; unset ii
668 # --------------------------------------------------------------------------
670 cd "$CUR_DIR"
671 footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
673 # Log this activity
674 log_pkg Installed
676 # Remove package from upgrade list
677 [ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
678 }
683 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
686 PACKAGE=$(
687 tmp_dir=$(mktemp -d); cd "$tmp_dir"
688 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
689 . ./receipt; echo $PACKAGE
690 rm -rf "$tmp_dir"
691 )
693 if grep -qs "^$PACKAGE$" "$BLOCKED"; then
694 _ 'Package "%s" blocked.' "$PACKAGE"
695 exit 1
696 fi
698 if [ -z "$forced" ]; then
699 # Check if a package is already installed
700 debug "\ncheck for installed package '$PACKAGE'"
702 awk -F$'\t' -vpv="$PACKAGE" '$1==pv { exit 1 }' "$PKGS_DB/installed.info"
704 if [ "$?" -eq 1 ]; then
705 if [ -z "$quiet" ]; then
706 newline
707 _ '"%s" package is already installed.' "$(colorize 34 "$PACKAGE")"
708 longline "$(_ 'You can use the --forced option to force installation.')"
709 newline
710 fi
711 exit 1
712 fi
713 fi
715 install_package "$(realpath "$1")"