tazpkg annotate modules/remove @ rev 955

modules/search: allow search file with dash at start: tazpkg -sf "-spi"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 22 00:02:54 2017 +0200 (2017-12-22)
parents 45d90da42ede
children
rev   line source
al@840 1 #!/bin/sh
al@840 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
al@840 3 # remove - TazPkg module
al@840 4 # Remove packages
al@840 5
al@840 6
al@840 7 # Connect function libraries
al@840 8 . /lib/libtaz.sh
al@840 9
al@840 10 # Get TazPkg working environment
al@840 11 . @@MODULES@@/getenv
al@840 12
al@840 13
al@840 14
al@840 15
al@840 16 # Log activity
al@840 17
al@840 18 log_pkg() {
al@840 19 [ -w "$LOG" ] &&
al@840 20 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)" >> "$LOG"
al@840 21 }
al@840 22
al@840 23
al@844 24 # Block of receipt function callers
al@844 25 # Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
paul@943 26 # Few receipts functions should be patched now.
al@844 27
al@844 28 # Input: $1 = path to the receipt to be processed
al@844 29
al@844 30 call_pre_remove() {
al@844 31 local tmp
al@844 32 if grep -q '^pre_remove()' "$1"; then
al@844 33 action 'Execute pre-remove commands...'
al@844 34 tmp="$(mktemp)"
al@844 35 cp "$1" "$tmp"
al@844 36 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
al@844 37 ( . "$tmp"; pre_remove "$root" )
al@844 38 status
al@844 39 rm "$tmp"
al@844 40 fi
al@844 41 }
al@844 42
al@844 43 call_post_remove() {
al@844 44 local tmp
al@844 45 if grep -q '^post_remove()' "$1"; then
al@844 46 action 'Execute post-remove commands...'
al@844 47 tmp="$(mktemp)"
al@844 48 cp "$1" "$tmp"
al@844 49 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
al@844 50 ( . "$tmp"; post_remove "$root" )
al@844 51 status
al@844 52 rm "$tmp"
al@844 53 fi
al@844 54 }
al@844 55
al@844 56
al@887 57 # return possible name for a virtual package name
al@840 58
al@887 59 virtual_pkg() {
al@887 60 # input: $1 virtual package name
al@887 61 # $2 repository db directory
al@887 62 # output: display possible package name
al@840 63
al@887 64 debug "\nvirtual_pkg('$1', '$2')"
al@887 65 local i
al@887 66 unset IFS
al@887 67 for i in $(grep -hs "^$1=" "$2/packages.equiv" | sed "s/^$1=//"); do
al@887 68 if echo $i | fgrep -q : ; then
al@887 69 # format 'alternative:newname'
al@887 70 # if alternative is installed then substitute newname
al@887 71 if [ -f $INSTALLED/${i%:*}/receipt ]; then
al@887 72 # substitute package dependency
al@887 73 echo ${i#*:}
al@887 74 return
al@887 75 fi
al@887 76 elif ! grep -q "^$1 " "$2/packages.info" || [ -f "$INSTALLED/$i/receipt" ]; then
al@887 77 # unconditional substitution
al@887 78 echo $i
al@887 79 return
al@887 80 fi
al@887 81 done
al@887 82 # the real package name
al@887 83 echo $1
al@887 84 }
al@887 85
al@887 86
al@887 87
al@887 88
al@887 89 for rep in $PRIORITY; do
al@887 90 [ ! -f "$rep/packages.info" ] && continue
al@887 91 PACKAGE="$(virtual_pkg "$1" "$rep")"
al@887 92 [ "$PACKAGE" != "$1" ] && break
al@887 93 done
al@840 94
al@840 95 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
al@840 96 newline; _ 'Package "%s" is not installed.' "$PACKAGE"
al@840 97 exit 1
al@840 98 fi
al@840 99
al@840 100 . "$INSTALLED/$PACKAGE/receipt"
al@840 101
al@840 102 # Info #1: dependent packages (to be processed later)
al@840 103 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " 'index(" " $8 " ", p) { printf " %s\n", $1 }' "$PKGS_DB/installed.info")"
al@840 104
al@840 105 if [ -n "$ALTERED" ]; then
al@840 106 _ 'The following packages depend on package "%s":' "$PACKAGE"
al@840 107 echo "$ALTERED"
al@840 108 fi
al@840 109
al@840 110 # Info #2: changed packages (to be processed later)
al@840 111 REFRESH=$(cd "$INSTALLED"; grep -sl "^$PACKAGE$" */modifiers)
al@840 112
al@840 113 if [ -n "$REFRESH" ]; then
al@840 114 _ 'The following packages have been modified by package "%s":' "$PACKAGE"
al@840 115 for i in $REFRESH; do
al@840 116 echo " ${i%/modifiers}"
al@840 117 done
al@840 118 fi
al@840 119
al@840 120 # Confirmation
pascal@916 121 if [ -n "$noconfirm" ] || im && [ -z "$auto" ]; then
al@840 122 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' "$PACKAGE" "$VERSION$EXTRAVERSION")"
al@840 123 if [ "$?" -ne 0 ]; then
al@840 124 newline; _ 'Uninstallation of package "%s" cancelled.' "$PACKAGE"
al@840 125 exit 0
al@840 126 fi
al@840 127 fi
al@913 128 # We are here: non-interactive mode, or --auto, or --yes, or answer 'y'
al@840 129
al@840 130 # Removing package
al@840 131 title 'Removing package "%s"' "$PACKAGE"
al@840 132
al@926 133 # Unblock package quietly; otherwise: