spk annotate spk-rm @ rev 92
spk-up: small cosmetic fix
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 25 16:01:20 2012 +0200 (2012-05-25) |
parents | 17e896f1d41d |
children | 0df5690de5fd |
rev | line source |
---|---|
pankso@8 | 1 #!/bin/sh |
pankso@8 | 2 # |
pankso@8 | 3 # Spk-rm - Remove SliTaz packages. Read the README before adding or |
pankso@8 | 4 # modifing any code in spk! |
pankso@8 | 5 # |
pankso@8 | 6 # Copyright (C) SliTaz GNU/Linux - BSD License |
pankso@8 | 7 # Author: See AUTHORS files |
pankso@8 | 8 # |
pankso@19 | 9 . /usr/lib/slitaz/libspk.sh |
pankso@8 | 10 |
pankso@8 | 11 # |
pankso@8 | 12 # Functions |
pankso@8 | 13 # |
pankso@8 | 14 |
pankso@8 | 15 # Help and usage |
pankso@8 | 16 usage() { |
pankso@8 | 17 name=$(basename $0) |
pankso@8 | 18 cat << EOT |
pankso@8 | 19 |
pankso@10 | 20 $(boldify $(gettext "Usage:")) $name [packages|--options] |
pankso@8 | 21 |
mojo@79 | 22 $(gettext "Remove installed packages and their dependencies") |
pankso@15 | 23 |
pankso@8 | 24 $(boldify $(gettext "Options:")) |
pankso@13 | 25 --confirm $(gettext "Ask before removing any packages") |
pankso@30 | 26 --root= $(gettext "Set the root file system path") |
pankso@13 | 27 --verbose $(gettext "Be more verbose when removing files") |
pankso@8 | 28 |
pankso@8 | 29 $(boldify $(gettext "Examples:")) |
pankso@13 | 30 $name package1 package2 packagesN |
pankso@13 | 31 $name package1 --confirm --verbose |
pankso@8 | 32 |
pankso@8 | 33 EOT |
pankso@8 | 34 exit 0 |
pankso@8 | 35 } |
pankso@8 | 36 |
pankso@13 | 37 # Avoid dirname errors by checking for argument anf then remove file and |
pankso@13 | 38 # empty directory. Usage: remove_file file |
pankso@13 | 39 remove_file() { |
pankso@13 | 40 [ "$1" ] || return |
pankso@13 | 41 local dir |
pankso@13 | 42 rm -f $1 2>/dev/null |
pankso@13 | 43 dir="$1" |
pankso@13 | 44 while [ "$dir" != "/" ]; do |
pankso@13 | 45 dir="$(dirname $dir)" |
pankso@13 | 46 rmdir $dir 2> /dev/null || break |
pankso@13 | 47 done |
pankso@13 | 48 } |
pankso@13 | 49 |
pankso@13 | 50 # Remove a single package |
pankso@13 | 51 remove() { |
pankso@13 | 52 altered="" |
meshca@70 | 53 boldify $(gettext "Removing") $pkg |
pankso@41 | 54 separator |
pankso@41 | 55 [ "$verbose" ] && echo "DB: $installed" |
pankso@41 | 56 |
pankso@41 | 57 # Reverse deps |
pankso@41 | 58 for i in $(ls $installed); do |
pankso@17 | 59 [ -f $installed/$i/receipt ] || continue |
pankso@13 | 60 unset_receipt |
pankso@17 | 61 . $installed/$i/receipt |
meshca@70 | 62 case " $DEPENDS " in |
pankso@13 | 63 *\ $pkg\ *) altered="$altered $i" ;; |
pankso@13 | 64 esac |
pankso@13 | 65 done |
pankso@13 | 66 unset_receipt |
pankso@17 | 67 . $installed/$pkg/receipt |
pankso@13 | 68 |
pankso@39 | 69 if [ "$altered" ]; then |
meshca@69 | 70 gettext "The following packages depend on"; colorize 31 " $pkg" |
pankso@13 | 71 for i in $altered; do |
meshca@69 | 72 echo " $(colorize 32 $i)" |
pankso@13 | 73 done |
pankso@13 | 74 fi |
pankso@13 | 75 |
pankso@39 | 76 # Reverse deps are displayed, confirm uninstall. |
pankso@39 | 77 if [ "$confirm" ]; then |
pankso@39 | 78 gettext "Confirm uninstallation of:"; echo -n " $pkg" |
pankso@39 | 79 if ! confirm; then |
pankso@39 | 80 gettext "Uninstallation cancelled" |
pankso@39 | 81 echo -e "\n" && continue |
pankso@13 | 82 fi |
pankso@13 | 83 fi |
pankso@13 | 84 |
pankso@13 | 85 # Handle pre_remove |
pankso@17 | 86 if grep -q ^pre_remove $installed/$PACKAGE/receipt; then |
pankso@13 | 87 pre_remove $root |
pankso@13 | 88 fi |
pankso@13 | 89 |
pankso@13 | 90 # Remove all files |
pankso@41 | 91 fileslist=$installed/$PACKAGE/files.list |
pankso@78 | 92 gettext "Installed files:" |
pankso@41 | 93 echo -n " $(wc -l $fileslist | cut -d " " -f 1)" |
pankso@13 | 94 [ "$verbose" ] && newline |
pankso@41 | 95 for file in $(cat $fileslist) |
pankso@40 | 96 do |
pankso@40 | 97 if [ "$verbose" ]; then |
pankso@40 | 98 gettext "Removing:"; echo -n " ${root}${file}" |
pankso@40 | 99 fi |
pankso@40 | 100 remove_file ${root}${file} |
pankso@40 | 101 [ "$verbose" ] && status |
pankso@40 | 102 done |
pankso@17 | 103 [ ! "$verbose" ] && status |
pankso@13 | 104 |
pankso@13 | 105 # Handle post_remove |
pankso@17 | 106 if grep -q ^post_remove $installed/$PACKAGE/receipt; then |
pankso@13 | 107 post_remove $root |
pankso@13 | 108 fi |
pankso@13 | 109 |
pankso@13 | 110 # Remove package receipt. |
pankso@13 | 111 gettext "Removing package receipt..." |
pankso@17 | 112 rm -rf $installed/$PACKAGE |
pankso@51 | 113 sed -i "/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg/"d $installed.$SUM |
pankso@13 | 114 status |
pankso@13 | 115 |
pankso@53 | 116 separator |
pankso@39 | 117 |
pankso@39 | 118 # Do we have packages depending on $pkg to remove ? |
pankso@39 | 119 if [ "$altered" ]; then |
pankso@13 | 120 if [ "$confirm" ]; then |
pankso@40 | 121 gettext "Remove packages depending on:"; echo -n " $pkg" |
pankso@39 | 122 if ! confirm; then |
pankso@40 | 123 gettext "Keeping packages..."; newline |
pankso@39 | 124 newline && continue |
pankso@39 | 125 fi |
pankso@39 | 126 fi |
pankso@39 | 127 for i in $altered; do |
pankso@39 | 128 if [ -d "$installed/$i" ]; then |
pankso@39 | 129 spk-rm $i --root=$root |
pankso@39 | 130 fi |
pankso@39 | 131 done |
pankso@53 | 132 else |
pankso@53 | 133 newline |
pankso@39 | 134 fi |
pankso@13 | 135 } |
pankso@13 | 136 |
pankso@8 | 137 # |
pankso@10 | 138 # Commands and exit |
pankso@8 | 139 # |
pankso@8 | 140 |
pankso@8 | 141 case "$1" in |
pankso@15 | 142 ""|*usage|*help) usage ;; |
pankso@8 | 143 esac |
pankso@10 | 144 |
pankso@10 | 145 # |
pankso@10 | 146 # Handle packages |
pankso@10 | 147 # |
pankso@10 | 148 |
pankso@19 | 149 : ${count=0} |
pankso@10 | 150 check_root |
pankso@10 | 151 |
pankso@10 | 152 for pkg in $@ |
pankso@10 | 153 do |
pankso@13 | 154 # Skip options |
pankso@13 | 155 case "$pkg" in |
pankso@13 | 156 --*) continue |
pankso@13 | 157 esac |
pankso@13 | 158 # Be sure package is installed |
pankso@17 | 159 if [ ! -f "$installed/$pkg/receipt" ]; then |
meshca@71 | 160 echo -n "$(boldify $pkg) " |
pankso@13 | 161 gettext "package is not installed"; newline |
pankso@13 | 162 continue |
pankso@13 | 163 fi |
pankso@10 | 164 count=$(($count + 1)) |
pankso@13 | 165 [ "$count" == 1 ] && newline |
pankso@13 | 166 remove |
pankso@39 | 167 log "Removed package: $pkg" |
pankso@10 | 168 done |
pankso@56 | 169 |
pankso@56 | 170 # Show all new counted packages in verbose mode |
pankso@56 | 171 if [ "$verbose" ]; then |
meshca@69 | 172 gettext "Removed packages:"; colorize 34 " $count" |
pankso@56 | 173 fi |
pankso@56 | 174 |
pankso@8 | 175 exit 0 |