tazpkg view modules/install @ rev 968

Modules "get" and "install": initial support for Cooker contain two architectures packages in one "packages" folder
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 26 12:33:58 2018 +0200 (2018-11-26)
parents 3817dcb25419
children f079c87ba419
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.info'
50 [ -e "$pi" ] || pi="/home/slitaz/packages/packages-$SLITAZ_ARCH.info"
51 else
52 pi="$(dirname "$2")/packages.info"
53 fi
54 [ -f "$pi" ] &&
55 out=$(awk -F$'\t' -vpkg="$1" '{
56 # if package name or provided package name matched
57 if ($1 == pkg || index(" " $10 " ", " " pkg " ")) { print $1 }
58 }' "$pi")
59 for i in $out; do
60 # If package installed
61 [ -f "$PKGS_DB/installed/$i/receipt" ] && out="$i" && break
62 unset out
63 done
64 else
65 rules=$(for rep in $PRIORITY; do
66 grep -hs "^$1=" "$rep/packages.equiv"
67 done | sed "s|^$1=||")
68 debug " >rules='$rules'"
70 for rule in $rules; do
71 debug " >rule='$rule'"
72 case $rule in
73 *:*)
74 debug '-- x:x'
75 # format 'alternative:newname'
76 # if alternative is installed then substitute newname
77 out="${rule#*:}"
78 awk -F$'\t' -vp="${rule%:*}" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
79 debug '-- x:x /'
80 ;;
81 *)
82 debug '-- x'
83 # unconditional substitution
84 out="$rule"
85 awk -F$'\t' -vp="$rule" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
86 debug '-- x /'
87 ;;
88 esac
89 unset out
90 done
91 fi
92 debug '--'
93 # if not found in packages.equiv then no substitution
94 echo "${out:-$1}"
95 }
98 # Check and install all missing deps.
99 # Auto install or ask user then install all missing deps from local dir, CD-ROM,
100 # media or from the mirror.
102 install_all_deps() {
103 # input: $1 = package file to check/install missing dependencies
104 # ROOT READY
105 # dep: equivalent_pkg.
107 debug "\ninstall_all_deps('$1')"
109 local TMP_DIR DEPENDS num missing_packages equiv pkg answer dir found pkgfile
111 # Check for missing deps listed in a receipt packages.
113 # Get the receipt's variable DEPENDS
114 DEPENDS=$(
115 TMP_DIR=$(mktemp -d); cd "$TMP_DIR"
116 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
117 . ./receipt; echo $DEPENDS
118 rm -rf "$TMP_DIR"
119 )
121 unset num missing_packages
122 for depend in $DEPENDS; do
123 debug " depend='$depend'"
124 equiv=$(equivalent_pkg $depend "$1")
125 debug " equiv='$equiv'\n"
126 if [ ! -d "$INSTALLED/$equiv" ]; then
127 missing_packages="$missing_packages $equiv"
128 num=$((num+1))
129 elif [ ! -f "$INSTALLED/$equiv/receipt" ]; then
130 [ -z "$quiet" ] && _ 'WARNING! Dependency loop between "%s" and "%s".' "$PACKAGE" "$equiv"
131 fi
132 done
134 # Nothing to install, exit function
135 [ -z "$num" ] && return
138 title "$(_ 'Tracking dependencies for package "%s"' "$PACKAGE")"
140 # Individual messages for each missing package
141 [ -z "$quiet" ] && \
142 for pkg in $missing_packages; do
143 _ 'Missing package "%s"' "$pkg"
144 done
146 footer "$(_p \
147 '%s missing package to install.' \
148 '%s missing packages to install.' "$num" \
149 "$num")"
152 if [ "$AUTO_INSTALL_DEPS" == 'yes' ] || [ -n "$quiet" ]; then
153 # Quietly not displaying anything. Assume 'yes' unless '--noconfirm' is provided
154 answer=0
155 [ -n "$noconfirm" ] && answer=1
156 else
157 # Display question; wait for answer or print auto-answer
158 newline
159 confirm "$(_ 'Install all missing dependencies? (y/N)')"
160 answer=$?
161 newline
162 fi
163 debug " answer='$answer'"
165 dir="$(dirname "$1")"
166 debug " dir='$dir'"
168 # We can install packages from /home/boot/packages at boot time
169 # Also we can prefer local packages over mirrored/cached using '--local' option
170 [ "$dir" == '/home/boot/packages' ] && local='yes'
171 debug " local='$local'"
173 # "--nodeps" option prevents to install dependencies
174 if [ "$answer" -eq 0 -a -z "$nodeps" ]; then
175 debug " let's install missing packages"
176 for pkg in $missing_packages; do
177 debug " pkg='$pkg'"
178 [ -d "$INSTALLED/$pkg" ] && continue
179 # Package not installed
181 found='0'; namever=''; pkgfile=''
182 # Prefer local packages
183 if [ -n "$local" ]; then
184 [ -z "$quiet" ] && _ 'Checking if package "%s" exists in local list...' "$pkg"
185 [ -n "$cookmode" ] && dir='/home/slitaz/packages'
186 pi="$dir/packages.info"
187 [ -e "$pi" ] || pi="$dir/packages-$SLITAZ_ARCH.info"
188 # Find local package
189 if [ -f "$pi" ]; then
190 # Packages database exists (should be everfresh!)
192 # Find local package
193 namever=$(awk -F$'\t' -vpkg="$pkg" '{
194 if ($1 == pkg) { printf("%s-%s", $1, $2); exit; }
195 }' "$pi") # <namever> = <package_name>-<package_version>
197 # Find local provided package
198 [ -n "$namever" ] ||
199 namever=$(awk -F$'\t' -vpkg="$pkg" '{
200 if (index(" " $10 " ", " " pkg " ")) { printf("%s-%s", $1, $2); exit; }
201 }' "$pi") # <namever> = <package_name>-<package_version>
203 # Package file may be in form <namever>.tazpkg or <namever>-<arch>.tazpkg, so find one
204 [ -n "$namever" ] && pkgfile=$(find "$dir" -name "$namever*.tazpkg")
205 [ -n "$pkgfile" ] && found='1'
206 else
207 # Packages DB missing, proceed to sniff packages
208 tempd="$(mktemp -d)"; cd "$tempd"
209 for pkgfile in $dir/$pkg-*.tazpkg; do
210 [ -e "$pkgfile" ] || continue
211 # Extract receipt from each matched package
212 cpio -F "$pkgfile" -i receipt >/dev/null 2>&1
213 name=$(. ./receipt; echo $PACKAGE)
214 [ "$name" == "$pkg" ] && found='1' && break
215 # Install the first matched package: normally there is only one package
216 # with the $PACKAGE matched in the receipt
217 rm receipt
218 done
219 rm -r "$tempd"
220 fi
221 fi
222 debug " found='$found'"
224 if [ "$found" -eq 1 ]
225 then tazpkg install "$pkgfile"
226 else tazpkg get-install "$pkg"
227 fi
228 done
229 else
230 # Answered 'No' to install dependencies, or '--nodeps' option given
231 newline
232 _ 'Leaving dependencies for package "%s" unresolved.' "$PACKAGE"
233 _ 'The package will be installed but will probably not work.'
234 newline
235 fi
236 }
239 # Extract a package with cpio and gzip/lzma.
241 extract_package() {
242 # input: $1 - path to package to be extracted; package should be in the current dir
243 # ROOT INDEPENDENT
244 action 'Extracting package...'
246 # Extract "outer layer": cpio; remove the original package file
247 cpio -idm --quiet < "$1" && rm -f "$1"
249 # "Inner layer" may vary
250 if [ -f fs.cpio.lzma ]; then
251 # "Plain" cpio.lzma
252 unlzma < fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
253 elif [ -f fs.cpio.gz ]; then
254 # "Fast" cpio.gz (used to pack-then-install process in most of get-packages)
255 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
256 fi
258 status
259 }
262 # Print short package description
264 print_short_description() {
265 # TODO: undigest repo support? priority...
266 # ROOT READY
267 local short_desc=''
269 # Try to find localized short description
270 for LC in $LANG ${LANG%_*}; do
271 [ -e "$PKGS_DB/packages-desc.$LC" ] &&
272 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $2; exit}' "$PKGS_DB/packages-desc.$LC")
273 done
275 # Try to find short description for mirrored package
276 if [ -z "$short_desc" ]; then
277 if [ -e "$PKGS_DB/packages.info" ]; then
278 pi="$PKGS_DB/packages.info"
279 else
280 "$PKGS_DB/packages-$SLITAZ_ARCH.info"
281 fi
282 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $4; exit}' "$pi")
283 fi
285 [ -z "$short_desc" ] && short_desc="$SHORT_DESC"
287 longline "$short_desc"
288 }
291 grepesc() {
292 sed 's/\[/\\[/g'
293 }
298 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
300 # Block of receipt function callers
301 # Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
302 # Few receipts functions should be patched now.
304 # Input: $1 = path to the receipt to be processed
306 # Pre-install commands
307 call_pre_install() {
308 local tmp
309 if grep -q '^pre_install()' "$1"; then
310 action 'Execute pre-install commands...'
311 tmp="$(mktemp)"
312 cp "$1" "$tmp"
313 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
314 ( . "$tmp"; pre_install "$root" )
315 status
316 rm "$tmp"
317 fi
319 }
320 # Post-install commands
321 call_post_install() {
322 local tmp
323 if grep -q '^post_install()' "$1"; then
324 action 'Execute post-install commands...'
325 tmp="$(mktemp)"
326 cp "$1" "$tmp"
327 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
328 ( . "$tmp"; post_install "$root" )
329 status
330 rm "$tmp"
331 fi
332 }
335 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
338 # This function installs a package in the rootfs.
340 install_package() {
341 # input: $1 = path to package to be installed
342 # dep: install_all_deps, print_short_description, extract_package, grepesc.
344 debug "\ninstall_package('$1')"
345 local dir
347 PACKAGE_FILE="$1"
348 TMP_DIR="$(mktemp -d)"
350 # Get receipt's variables and functions
351 { cd "$TMP_DIR"; cpio --quiet -i receipt < "$PACKAGE_FILE" >/dev/null 2>&1; }
352 # Why next code? "Bad" receipt sourcing can redefine some vital TazPkg variables.
353 (
354 . "$TMP_DIR/receipt"
355 cat > "$TMP_DIR/receipt.var" <<EOT
356 PACKAGE="$PACKAGE"
357 VERSION="$VERSION"
358 EXTRAVERSION="$EXTRAVERSION"
359 CATEGORY="$CATEGORY"
360 SHORT_DESC="${SHORT_DESC//\"/\"}"
361 WEB_SITE="$WEB_SITE"
362 TAGS="$TAGS"
363 DEPENDS="$DEPENDS"
364 CONFIG_FILES="$CONFIG_FILES"
365 PACKED_SIZE="$PACKED_SIZE"
366 UNPACKED_SIZE="$UNPACKED_SIZE"
367 EOT
368 rm "$TMP_DIR/receipt"
369 )
370 . "$TMP_DIR/receipt.var"
373 # Make sure folder exists on new installs or upgrades
374 mkdir -p "$INSTALLED/$PACKAGE"
376 # Keep "modifiers" and "files.list" on upgrade
377 find "$INSTALLED/$PACKAGE" -type f \( ! -name modifiers ! -name files.list \) -delete
379 # Update "installed.md5"
380 # TODO: discontinue using 'installed.md5'
381 touch "$PKGS_DB/installed.$SUM"
382 sed -i "/ $(basename "$PACKAGE_FILE")$/d" "$PKGS_DB/installed.$SUM" 2>/dev/null
383 cd "$(dirname "$PACKAGE_FILE")"
384 $CHECKSUM "$(basename "$PACKAGE_FILE")" >> "$PKGS_DB/installed.$SUM"
386 # Resolve package dependencies before package installation
387 install_all_deps "$PACKAGE_FILE"
390 # TODO: why this list-processed in the $PKGS_DB?
391 #[ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> "$PKGS_DB/$INSTALL_LIST-processed"
393 # Special mode for using in cookutils: clearly show whether freshly used package or cached one
394 if [ -n "$cookmode" ]; then
395 f=${PACKAGE_FILE%/*}; f=${f%/*}; f=${f##*/}
396 if [ "$f" == "$(cat /etc/slitaz-release)" ]; then
397 _ 'Installing (web/cache): %s' "$(basename $PACKAGE_FILE .tazpkg)"
398 else
399 _ 'Installing (pkg/local): %s' "$(basename $PACKAGE_FILE .tazpkg)"
400 fi
401 fi
403 if [ -n "$sequence" ]; then
404 title 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence"
405 else
406 title 'Installation of package "%s"' "$PACKAGE"
407 fi
409 if [ -z "$quiet" ]; then
410 print_short_description "$PACKAGE"
411 separator '-'
412 fi
414 action 'Copying package...'
415 cp "$PACKAGE_FILE" "$TMP_DIR"
416 status
418 cd "$TMP_DIR"
419 extract_package "$(basename "$PACKAGE_FILE")"
421 # Include temporary receipt to get the right variables
422 . "$TMP_DIR/receipt.var"
424 cd "$INSTALLED"
427 # Get files to remove if upgrading
428 # IFS here modified temporarily for processing filenames with spaces
429 IFS=$'\n'
430 if [ -f "$PACKAGE/files.list" ]; then
431 while read file; do
432 grep -q "^$(echo "$file" | grepesc)$" "$TMP_DIR/files.list" && continue
433 for i in $(cat "$PACKAGE/modifiers" 2>/dev/null;
434 fgrep -sl "$PACKAGE" */modifiers | cut -d/ -f1); do
435 grep -qs "^$(echo "$file" | grepesc)$" "$i/files.list" && continue 2
436 done
437 echo "$file"
438 done < "$PACKAGE/files.list" > "$TMP_DIR/files2remove.list"
439 fi
440 unset IFS
443 # Remember modified packages
444 action 'Remember modified packages...'
445 {
446 check=false
447 # TODO: why '[' the special?
448 # FIXME: we have files with spaces in our packages!
449 for i in $(fgrep -v [ $TMP_DIR/files.list); do
450 [ -e "$root$i" ] || continue
451 [ -d "$root$i" ] && continue
452 echo "- $i"
453 check=true
454 done ;
455 $check && \
456 for i in *; do
457 [ "$i" == "$PACKAGE" ] && continue
458 [ -s "$i/files.list" ] || continue
459 awk "{ printf \"$i %s\\n\",\$1 }" < "$i/files.list"
460 done;
461 } | awk '
462 {
463 if ($1 == "-" || file[$2] != "") {
464 file[$2] = file[$2] " " $1
465 if ($1 != "-") {
466 if (pkg[$1] == "") all = all " " $1
467 pkg[$1] = pkg[$1] " " $2
468 }
469 }
470 }
471 END {
472 for (i = split(all, p, " "); i > 0; i--)
473 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
474 printf "%s %s\n",p[i],f[j];
475 }
476 ' | while read dir file; do
477 if grep -qs "^$dir$" "$PACKAGE/modifiers"; then
478 # Do not overload an overloaded file !
479 rm "$TMP_DIR/$file" 2>/dev/null
480 continue
481 fi
482 grep -qs "^$PACKAGE$" "$dir/modifiers" && continue
483 if [ -s "$dir/volatile.cpio.gz" ]; then
484 # We can modify backed up files without notice
485 zcat "$dir/volatile.cpio.gz" | cpio -t --quiet | \
486 grep -q "^${file#/}$" && continue
487 fi
488 echo "$PACKAGE" >> "$dir/modifiers"
489 done
490 status
493 cd "$TMP_DIR"
494 # Copy receipt, etc.
495 for file in receipt files.list description.txt $CHECKSUM; do
496 [ -f "$file" ] && cp "$file" "$INSTALLED/$PACKAGE"
497 done
500 # Pre-install commands
501 call_pre_install "$INSTALLED/$PACKAGE/receipt"
504 if [ -n "$CONFIG_FILES" ]; then
505 # Save "official" configuration files
506 action 'Saving configuration files...'
507 debug "\n"
509 cd fs
510 local config_file
511 for config_file in $CONFIG_FILES; do
512 debug " config_file: '$config_file'"
513 find ${config_file#/} -type f 2>/dev/null
514 done | cpio -o -H newc --quiet | gzip -9 > "$INSTALLED/$PACKAGE/volatile.cpio.gz"
515 cd ..
517 if [ -z "$newconf" ]; then
518 debug " no '--newconf': clean official config files"
519 # Keep user configuration files: remove "official" from fs tree
520 for config_file in $CONFIG_FILES; do
521 for config_file_official in $(find "fs$config_file" ! -type d 2>/dev/null | sed 's|^fs||'); do
522 if [ -e "$root$config_file_official" ]; then
523 debug " official '$config_file_official' will be skipped"
524 rm "fs$config_file_official"
525 else
526 debug " official '$config_file_official' will be written"
527 fi
528 done
529 done
530 fi
531 # always '[ Done ]' status, unless '--newconf' is passed or not
532 :; status
533 fi
536 if [ -n "$(ls fs/* 2>/dev/null)" ]; then
537 action 'Installing package...'
539 debug '\n resolving destination links in source'
540 IFS=$'\n'
541 for dir in $(find fs -type d | sed 's|^fs||;/^$/d'); do
542 if ldir=$(readlink -n $root$dir); then
543 debug " * mv 'fs$dir'\n -> 'fs${dir%/*}/$ldir'"
544 mkdir -p "fs${dir%/*}/${ldir%/*}"
545 mv "fs$dir" "fs${dir%/*}/$ldir"
546 fi
547 done
548 unset IFS
550 debug ' copying folders and files to destination'
551 cp -af fs/* "$root/"
552 status
553 fi
556 if [ -s files2remove.list ]; then
557 action 'Removing old files...'
558 while read file; do
559 dir="$root$file"
560 # Remove specified file
561 rm -f "$dir"
562 # Recursive remove non-empty up-dirs
563 while [ "$dir" != "$root/" ]; do
564 dir=$(dirname "$dir")
565 rmdir "$dir" 2>/dev/null || break
566 done
567 done < files2remove.list
568 :; status
569 fi
572 # Remove the temporary random directory.
573 action "Removing all tmp files..."
574 cd ..; rm -rf "$TMP_DIR"
575 status
578 # Post install commands
579 call_post_install "$INSTALLED/$PACKAGE/receipt"
584 # Update system databases
585 # Updating DBs is important process, so not to hide such errors (localized):
586 # chroot: can't execute '/usr/bin/***': No such file or directory
588 local fl="$INSTALLED/$PACKAGE/files.list" upd=0 udesk umime uicon uschm ukrnl ukrnlfs
590 fgrep /usr/share/applications/ "$fl" | fgrep -q .desktop && udesk='yes'
591 fgrep -q /usr/share/mime "$fl" && umime='yes'
592 fgrep -q /usr/share/icon/hicolor "$fl" && uicon='yes'
593 fgrep /usr/share/glib-2.0/schemas "$fl" | fgrep -q .xml && uschm='yes'
594 fgrep /usr/lib/gdk-pixbuf "$fl" | fgrep -q .so && upixb='yes'
595 if fgrep -q /lib/modules "$fl"; then
596 ukrnl='yes'
597 if fgrep -q /kernel/fs/ "$fl"; then
598 ukrnlfs='yes'
599 fi
600 fi
602 if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then
603 action 'Update system databases...'
604 upd=1
605 fi
607 # package 'desktop-file-utils'
608 [ -n "$udesk" ] && chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
609 # package 'shared-mime-info'
610 [ -n "$umime" ] && chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
611 # packages 'gtk+', 'gtk+3'
612 [ -n "$uicon" ] && chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
613 # package 'glib'
614 # hide messages like next because they are unresolved (we may to patch glib to hide them, almost the same)
615 # warning: Schema '*' has path '*'. Paths starting with '/apps/', '/desktop/' or '/system/' are deprecated.
616 [ -n "$uschm" ] && chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas 2>&1 | fgrep -v '/apps/'
617 # package 'gdk-pixbuf'
618 [ -n "$upixb" ] && chroot "$root/" /usr/bin/gdk-pixbuf-query-loaders --update-cache
620 if [ -n "$ukrnlfs" ]; then
621 for i in $(awk -F/ '{if($6=="fs" && $8~$7)print $7}' "$fl" | sort -u); do
622 touch "$root/etc/filesystems"
623 grep -q "^$i\$" "$root/etc/filesystems" || echo "$i" >> "$root/etc/filesystems"
624 done
625 fi
626 # packages 'busybox', 'kmod', 'depmod'
627 [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a
629 [ "$upd" -eq 1 ] && status
634 # Update installed.info ----------------------------------------------------
635 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
637 # Remove newlines from some receipts
638 DEPENDS=$(echo $DEPENDS)
639 PKG_SUM="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.$SUM" | cut -d' ' -f1)"
641 # Calculate "release checksum": md5sum of file containing md5sums of:
642 # a) all files, b) receipt, and c) description.txt.
643 rsumf=$(mktemp)
644 cp $INSTALLED/$PACKAGE/md5sum $rsumf
645 md5sum $INSTALLED/$PACKAGE/receipt | sed 's| [^ ]*/| |' >> $rsumf
646 [ -e "$INSTALLED/$PACKAGE/description.txt" ] &&
647 md5sum $INSTALLED/$PACKAGE/description.txt | sed 's| [^ ]*/| |' >> $rsumf
648 RSUM=$(md5sum $rsumf | awk '{print $1}')
649 rm $rsumf
651 ii="$PKGS_DB/installed.info"
653 # Remove old entry
654 sed -i "/^$PACKAGE /d" "$ii"
656 cat >> "$ii" <<EOT
657 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $PKG_SUM
658 EOT
660 TEMP_FILE="$(mktemp)"
661 sort "$ii" > "$TEMP_FILE"; mv -f "$TEMP_FILE" "$ii"; chmod a+r "$ii"; unset ii
662 # --------------------------------------------------------------------------
664 cd "$CUR_DIR"
665 footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
667 # Log this activity
668 log_pkg Installed
670 # Remove package from upgrade list
671 [ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
672 }
677 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
680 PACKAGE=$(
681 tmp_dir=$(mktemp -d); cd "$tmp_dir"
682 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
683 . ./receipt; echo $PACKAGE
684 rm -rf "$tmp_dir"
685 )
687 if grep -qs "^$PACKAGE$" "$BLOCKED"; then
688 _ 'Package "%s" blocked.' "$PACKAGE"
689 exit 1
690 fi
692 if [ -z "$forced" ]; then
693 # Check if a package is already installed
694 debug "\ncheck for installed package '$PACKAGE'"
696 awk -F$'\t' -vpv="$PACKAGE" '$1==pv { exit 1 }' "$PKGS_DB/installed.info"
698 if [ "$?" -eq 1 ]; then
699 if [ -z "$quiet" ]; then
700 newline
701 _ '"%s" package is already installed.' "$(colorize 34 "$PACKAGE")"
702 longline "$(_ 'You can use the --forced option to force installation.')"
703 newline
704 fi
705 exit 1
706 fi
707 fi
709 install_package "$(realpath "$1")"