spk view spk-rm @ rev 40

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