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:
|
al@926
|
134 # 1. We can no longer install the package one more time - because it is blocked
|
al@926
|
135 # 2. We can no longer unblock the package - because it is not installed
|
al@926
|
136 tazpkg -u "$PACKAGE" --nowarning | grep -v '^$'
|
al@926
|
137
|
al@887
|
138 # [1/5] Pre-remove commands
|
al@844
|
139 call_pre_remove "$INSTALLED/$PACKAGE/receipt"
|
al@844
|
140
|
al@840
|
141
|
al@887
|
142 # [2/5] Removing files
|
al@840
|
143 action 'Removing all files installed...'
|
al@857
|
144
|
al@857
|
145 # NOTE: package 'faenza-icon-theme' install time: 12s; removing time ~ 11min on my system o_O
|
al@860
|
146 # After optimization: 3s! (Long) for-loops are (big) evil ;)
|
al@857
|
147
|
al@857
|
148 # NOTE: many packages contains filenames with spaces:
|
al@857
|
149 # lzcat /var/lib/tazpkg/files.list.lzma | awk -F" " '{if(NF>2)print $1}' | sed 's|:$||' | uniq
|
al@857
|
150 # Redefine IFS to only-new-line field separator:
|
al@857
|
151 IFS=$'\n'
|
al@857
|
152
|
al@857
|
153 files2remove="$(mktemp)"
|
al@857
|
154
|
al@857
|
155 debug '\nDetermine which files to remove...'
|
al@840
|
156 if [ -f "$INSTALLED/$PACKAGE/modifiers" ]; then
|
al@857
|
157 debug ' (modifiers detected)'
|
al@857
|
158
|
al@857
|
159 mods="$(mktemp)"
|
al@857
|
160 for mod in $(cat "$INSTALLED/$PACKAGE/modifiers"); do
|
al@857
|
161 cat "$INSTALLED/$mod/files.list" >> "$mods" 2>/dev/null
|
al@840
|
162 done
|
al@857
|
163
|
al@857
|
164 awk -vroot="$root" -vfl="$INSTALLED/$PACKAGE/files.list" '
|
al@857
|
165 {
|
al@857
|
166 if (FILENAME == fl)
|
al@857
|
167 f[$0] = 1;
|
al@857
|
168 else
|
al@857
|
169 f[$0] = "";
|
al@857
|
170 }
|
al@857
|
171 END {
|
al@857
|
172 for (i in f) {
|
al@857
|
173 if (f[i] == 1) printf "%s%s\n", root, i;
|
al@857
|
174 }
|
al@857
|
175 }' "$INSTALLED/$PACKAGE/files.list" "$mods" > "$files2remove"
|
al@857
|
176 rm "$mods"
|
al@840
|
177 else
|
al@857
|
178 debug ' (modifiers not detected)'
|
al@857
|
179
|
al@857
|
180 awk -vroot="$root" '{ printf "%s%s\n", root, $0; }' \
|
al@857
|
181 "$INSTALLED/$PACKAGE/files.list" > "$files2remove"
|
al@857
|
182 fi
|
al@857
|
183
|
al@857
|
184 debug 'Removing files...'
|
al@857
|
185 xargs rm -f < "$files2remove"
|
al@857
|
186
|
al@860
|
187 debug 'Removing folders...'
|
al@857
|
188 awk '
|
al@857
|
189 BEGIN {
|
al@857
|
190 FS = "/"; OFS = "/";
|
al@857
|
191 }
|
al@857
|
192 {
|
al@857
|
193 # removing filename beyond the last "/"
|
al@857
|
194 $NF = "";
|
al@857
|
195 if (! a[$0]) {
|
al@857
|
196 a[$0] = 1; print;
|
al@857
|
197 }
|
al@860
|
198 }' "$files2remove" | xargs rmdir -p 2>/dev/null
|
al@857
|
199
|
al@860
|
200 rm "$files2remove"
|
al@857
|
201 unset IFS
|
al@857
|
202
|
al@840
|
203 status
|
al@840
|
204
|
al@887
|
205 # [3/5] Post-remove commands
|
al@844
|
206 call_post_remove "$INSTALLED/$PACKAGE/receipt"
|
al@931
|
207 # restore Busybox applets
|
al@931
|
208 . @@MODULES@@/bb restore
|
al@931
|
209
|
al@840
|
210
|
al@887
|
211 # [4/5] Update system databases
|
al@920
|
212 fl="$INSTALLED/$PACKAGE/files.list"; upd=0
|
al@887
|
213
|
al@929
|
214 fgrep /usr/share/applications/ "$fl" | fgrep -q .desktop && udesk='yes'
|
al@929
|
215 fgrep -q /usr/share/mime "$fl" && umime='yes'
|
al@929
|
216 fgrep -q /usr/share/icon/hicolor "$fl" && uicon='yes'
|
al@929
|
217 fgrep /usr/share/glib-2.0/schemas "$fl" | fgrep -q .xml && uschm='yes'
|
al@929
|
218 fgrep /usr/lib/gdk-pixbuf "$fl" | fgrep -q .so && upixb='yes'
|
al@929
|
219 if fgrep -q /lib/modules "$fl"; then
|
al@929
|
220 ukrnl='yes'
|
al@929
|
221 if fgrep -q /kernel/fs/ "$fl"; then
|
al@929
|
222 ukrnlfs='yes'
|
al@929
|
223 fi
|
al@929
|
224 fi
|
al@887
|
225
|
al@887
|
226 if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then
|
al@887
|
227 action 'Update system databases...'
|
al@887
|
228 upd=1
|
al@887
|
229 fi
|
al@887
|
230
|
al@887
|
231 # package 'desktop-file-utils'
|
al@887
|
232 [ -n "$udesk" ] && chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
|
al@887
|
233 # package 'shared-mime-info'
|
al@887
|
234 [ -n "$umime" ] && chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
|
al@887
|
235 # packages 'gtk+', 'gtk+3'
|
al@887
|
236 [ -n "$uicon" ] && chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
|
al@887
|
237 # package 'glib'
|
al@897
|
238 # hide messages like next because they are unresolved (we may to patch glib to hide them, almost the same)
|
al@897
|
239 # warning: Schema '*' has path '*'. Paths starting with '/apps/', '/desktop/' or '/system/' are deprecated.
|
al@897
|
240 [ -n "$uschm" ] && chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas 2>&1 | fgrep -v '/apps/'
|
al@887
|
241 # package 'gdk-pixbuf'
|
al@887
|
242 [ -n "$upixb" ] && chroot "$root/" /usr/bin/gdk-pixbuf-query-loaders --update-cache
|
al@929
|
243
|
al@929
|
244 if [ -n "$ukrnlfs" ]; then
|
al@929
|
245 for i in $(awk -F/ '{if($6=="fs" && $8~$7)print $7}' "$fl" | sort -u); do
|
al@929
|
246 grep -i "/^$i\$/d" "$root/etc/filesystems"
|
al@929
|
247 done
|
al@929
|
248 fi
|
al@887
|
249 # packages 'busybox', 'kmod', 'depmod'
|
al@887
|
250 [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a
|
al@887
|
251
|
al@887
|
252 [ "$upd" -eq 1 ] && status
|
al@887
|
253
|
al@887
|
254
|
al@887
|
255 # [5/5] Remove package receipt and remove it from databases
|
al@840
|
256 action 'Removing package receipt...'
|
al@840
|
257 rm -rf "$INSTALLED/$PACKAGE"
|
al@840
|
258 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" "$PKGS_DB/installed.$SUM"
|
al@840
|
259 sed -i "/^$PACKAGE /d" "$PKGS_DB/installed.info"
|
al@840
|
260 status
|
al@840
|
261
|
al@840
|
262 footer "$(_ 'Package "%s" (%s) removed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
|
al@840
|
263
|
al@840
|
264 # Log this activity
|
al@840
|
265 log_pkg Removed
|
al@840
|
266
|
al@840
|
267 # Stop if non-interactive mode and no --auto option
|
al@840
|
268 if ! im && [ -z "$auto" ]; then exit 0; fi
|
al@840
|
269
|
al@840
|
270 # Process dependent packages
|
al@840
|
271 if [ -n "$ALTERED" ]; then
|
al@840
|
272 if [ -n "$auto" ]; then
|
al@840
|
273 answer=0
|
al@840
|
274 else
|
al@840
|
275 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' "$PACKAGE")"
|
al@840
|
276 answer=$?
|
al@840
|
277 fi
|
al@840
|
278 if [ "$answer" -eq 0 ]; then
|
al@840
|
279 for i in $ALTERED; do
|
al@840
|
280 if [ -d "$INSTALLED/$i" ]; then
|
al@840
|
281 tazpkg remove $i
|
al@840
|
282 fi
|
al@840
|
283 done
|
al@840
|
284 fi
|
al@840
|
285 fi
|
al@840
|
286
|
al@840
|
287 # Process changed packages
|
al@840
|
288 if [ -n "$REFRESH" ]; then
|
al@840
|
289 if [ -n "$auto" ]; then
|
al@840
|
290 answer=0
|
al@840
|
291 else
|
al@840
|
292 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' "$PACKAGE")"
|
al@840
|
293 answer=$?
|
al@840
|
294 fi
|
al@840
|
295 if [ "$answer" -eq 0 ]; then
|
al@840
|
296 for i in $REFRESH; do
|
al@840
|
297 if [ "$(wc -l < "$INSTALLED/$i")" -gt 1 ]; then
|
al@849
|
298 _ 'Package "%s" was modified by "%s" and other packages. It will not be reinstalled.' \
|
al@849
|
299 "${i%/modifiers}" "$PACKAGE"
|
al@849
|
300 _ 'Check "%s" for reinstallation.' "$INSTALLED/$i"
|
al@849
|
301
|
al@840
|
302 continue
|
al@840
|
303 fi
|
al@840
|
304 rm -r "$INSTALLED/$i"
|
al@840
|
305 tazpkg get-install ${i%/modifiers} --forced
|
al@840
|
306 done
|
al@840
|
307 fi
|
al@840
|
308 fi
|
al@840
|
309
|