tazpkg annotate modules/remove @ rev 840
Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Aug 28 16:10:34 2015 +0300 (2015-08-28) |
parents | |
children | d6cbd0c5f273 |
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 remove_with_path() { |
al@840 | 17 # Avoid dirname errors by checking for argument. |
al@840 | 18 [ -n "$1" ] || return |
al@840 | 19 |
al@840 | 20 local dir |
al@840 | 21 rm -f $1 2>/dev/null |
al@840 | 22 dir="$1" |
al@840 | 23 while [ "$dir" != "/" ]; do |
al@840 | 24 dir="$(dirname "$dir")" |
al@840 | 25 rmdir "$dir" 2>/dev/null || break |
al@840 | 26 done |
al@840 | 27 } |
al@840 | 28 |
al@840 | 29 |
al@840 | 30 grepesc() { |
al@840 | 31 sed 's/\[/\\[/g' |
al@840 | 32 } |
al@840 | 33 |
al@840 | 34 |
al@840 | 35 # Log activity |
al@840 | 36 |
al@840 | 37 log_pkg() { |
al@840 | 38 [ -w "$LOG" ] && |
al@840 | 39 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)" >> "$LOG" |
al@840 | 40 } |
al@840 | 41 |
al@840 | 42 |
al@840 | 43 # Interactive mode |
al@840 | 44 |
al@840 | 45 im() { tty -s; } |
al@840 | 46 |
al@840 | 47 |
al@840 | 48 |
al@840 | 49 |
al@840 | 50 PACKAGE="$1" |
al@840 | 51 |
al@840 | 52 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then |
al@840 | 53 newline; _ 'Package "%s" is not installed.' "$PACKAGE" |
al@840 | 54 exit 1 |
al@840 | 55 fi |
al@840 | 56 |
al@840 | 57 . "$INSTALLED/$PACKAGE/receipt" |
al@840 | 58 |
al@840 | 59 # Info #1: dependent packages (to be processed later) |
al@840 | 60 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " 'index(" " $8 " ", p) { printf " %s\n", $1 }' "$PKGS_DB/installed.info")" |
al@840 | 61 |
al@840 | 62 if [ -n "$ALTERED" ]; then |
al@840 | 63 _ 'The following packages depend on package "%s":' "$PACKAGE" |
al@840 | 64 echo "$ALTERED" |
al@840 | 65 fi |
al@840 | 66 |
al@840 | 67 # Info #2: changed packages (to be processed later) |
al@840 | 68 REFRESH=$(cd "$INSTALLED"; grep -sl "^$PACKAGE$" */modifiers) |
al@840 | 69 |
al@840 | 70 if [ -n "$REFRESH" ]; then |
al@840 | 71 _ 'The following packages have been modified by package "%s":' "$PACKAGE" |
al@840 | 72 for i in $REFRESH; do |
al@840 | 73 echo " ${i%/modifiers}" |
al@840 | 74 done |
al@840 | 75 fi |
al@840 | 76 |
al@840 | 77 # Confirmation |
al@840 | 78 if im && [ -z "$auto" ]; then |
al@840 | 79 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' "$PACKAGE" "$VERSION$EXTRAVERSION")" |
al@840 | 80 if [ "$?" -ne 0 ]; then |
al@840 | 81 newline; _ 'Uninstallation of package "%s" cancelled.' "$PACKAGE" |
al@840 | 82 exit 0 |
al@840 | 83 fi |
al@840 | 84 fi |
al@840 | 85 # We are here: non-interactive mode, or --auto, or answer 'y' |
al@840 | 86 |
al@840 | 87 # Removing package |
al@840 | 88 title 'Removing package "%s"' "$PACKAGE" |
al@840 | 89 |
al@840 | 90 # [1/4] Pre-remove commands |
al@840 | 91 if grep -q ^pre_remove "$INSTALLED/$PACKAGE/receipt"; then |
al@840 | 92 action 'Execution of pre-remove commands...' |
al@840 | 93 pre_remove |
al@840 | 94 status |
al@840 | 95 fi |
al@840 | 96 |
al@840 | 97 # [2/4] Removing files |
al@840 | 98 action 'Removing all files installed...' |
al@840 | 99 if [ -f "$INSTALLED/$PACKAGE/modifiers" ]; then |
al@840 | 100 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do |
al@840 | 101 for mod in $(cat "$INSTALLED/$PACKAGE/modifiers"); do |
al@840 | 102 [ -f "$INSTALLED/$mod/files.list" ] && \ |
al@840 | 103 [ $(grep "^$(echo $file | grepesc)$" "$INSTALLED/$mod/files.list" | wc -l) -gt 1 ] && \ |
al@840 | 104 continue 2 |
al@840 | 105 done |
al@840 | 106 [ -n "$debug" ] && echo "remove_with_path $root$file" |
al@840 | 107 remove_with_path $root$file |
al@840 | 108 done |
al@840 | 109 else |
al@840 | 110 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do |
al@840 | 111 [ -n "$debug" ] && echo "remove_with_path $root$file" |
al@840 | 112 remove_with_path $root$file |
al@840 | 113 done |
al@840 | 114 fi |
al@840 | 115 status |
al@840 | 116 |
al@840 | 117 # [3/4] Post-remove commands |
al@840 | 118 if grep -q ^post_remove "$INSTALLED/$PACKAGE/receipt"; then |
al@840 | 119 action 'Execution of post-remove commands...' |
al@840 | 120 post_remove |
al@840 | 121 status |
al@840 | 122 fi |
al@840 | 123 |
al@840 | 124 # [4/4] Remove package receipt and remove it from databases |
al@840 | 125 action 'Removing package receipt...' |
al@840 | 126 rm -rf "$INSTALLED/$PACKAGE" |
al@840 | 127 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" "$PKGS_DB/installed.$SUM" |
al@840 | 128 sed -i "/^$PACKAGE /d" "$PKGS_DB/installed.info" |
al@840 | 129 status |
al@840 | 130 |
al@840 | 131 footer "$(_ 'Package "%s" (%s) removed.' "$PACKAGE" "$VERSION$EXTRAVERSION")" |
al@840 | 132 |
al@840 | 133 # Log this activity |
al@840 | 134 log_pkg Removed |
al@840 | 135 |
al@840 | 136 # Stop if non-interactive mode and no --auto option |
al@840 | 137 if ! im && [ -z "$auto" ]; then exit 0; fi |
al@840 | 138 |
al@840 | 139 # Process dependent packages |
al@840 | 140 if [ -n "$ALTERED" ]; then |
al@840 | 141 if [ -n "$auto" ]; then |
al@840 | 142 answer=0 |
al@840 | 143 else |
al@840 | 144 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' "$PACKAGE")" |
al@840 | 145 answer=$? |
al@840 | 146 fi |
al@840 | 147 if [ "$answer" -eq 0 ]; then |
al@840 | 148 for i in $ALTERED; do |
al@840 | 149 if [ -d "$INSTALLED/$i" ]; then |
al@840 | 150 tazpkg remove $i |
al@840 | 151 fi |
al@840 | 152 done |
al@840 | 153 fi |
al@840 | 154 fi |
al@840 | 155 |
al@840 | 156 # Process changed packages |
al@840 | 157 if [ -n "$REFRESH" ]; then |
al@840 | 158 if [ -n "$auto" ]; then |
al@840 | 159 answer=0 |
al@840 | 160 else |
al@840 | 161 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' "$PACKAGE")" |
al@840 | 162 answer=$? |
al@840 | 163 fi |
al@840 | 164 if [ "$answer" -eq 0 ]; then |
al@840 | 165 for i in $REFRESH; do |
al@840 | 166 if [ "$(wc -l < "$INSTALLED/$i")" -gt 1 ]; then |
al@840 | 167 _ 'Check %s for reinstallation' "$INSTALLED/$i" |
al@840 | 168 continue |
al@840 | 169 fi |
al@840 | 170 rm -r "$INSTALLED/$i" |
al@840 | 171 tazpkg get-install ${i%/modifiers} --forced |
al@840 | 172 done |
al@840 | 173 fi |
al@840 | 174 fi |
al@840 | 175 |