tazpkg view modules/remove @ rev 846
Remove "busybox" "prefixes" (thanks llev)
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Oct 09 13:14:01 2015 +0300 (2015-10-09) |
parents | a02e36d44d06 |
children | b6daeaa95431 |
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # remove - TazPkg module
4 # Remove packages
7 # Connect function libraries
8 . /lib/libtaz.sh
10 # Get TazPkg working environment
11 . @@MODULES@@/getenv
16 remove_with_path() {
17 # Avoid dirname errors by checking for argument.
18 [ -n "$1" ] || return
20 local dir
21 rm -f $1 2>/dev/null
22 dir="$1"
23 while [ "$dir" != "/" ]; do
24 dir="$(dirname "$dir")"
25 rmdir "$dir" 2>/dev/null || break
26 done
27 }
30 grepesc() {
31 sed 's/\[/\\[/g'
32 }
35 # Log activity
37 log_pkg() {
38 [ -w "$LOG" ] &&
39 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)" >> "$LOG"
40 }
43 # Interactive mode
45 im() { tty -s; }
48 # Block of receipt function callers
49 # Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
50 # Few receipts function should be patched now.
52 # Input: $1 = path to the receipt to be processed
54 call_pre_remove() {
55 local tmp
56 if grep -q '^pre_remove()' "$1"; then
57 action 'Execute pre-remove commands...'
58 tmp="$(mktemp)"
59 cp "$1" "$tmp"
60 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
61 ( . "$tmp"; pre_remove "$root" )
62 status
63 rm "$tmp"
64 fi
65 }
67 call_post_remove() {
68 local tmp
69 if grep -q '^post_remove()' "$1"; then
70 action 'Execute post-remove commands...'
71 tmp="$(mktemp)"
72 cp "$1" "$tmp"
73 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
74 ( . "$tmp"; post_remove "$root" )
75 status
76 rm "$tmp"
77 fi
78 }
83 PACKAGE="$1"
85 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
86 newline; _ 'Package "%s" is not installed.' "$PACKAGE"
87 exit 1
88 fi
90 . "$INSTALLED/$PACKAGE/receipt"
92 # Info #1: dependent packages (to be processed later)
93 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " 'index(" " $8 " ", p) { printf " %s\n", $1 }' "$PKGS_DB/installed.info")"
95 if [ -n "$ALTERED" ]; then
96 _ 'The following packages depend on package "%s":' "$PACKAGE"
97 echo "$ALTERED"
98 fi
100 # Info #2: changed packages (to be processed later)
101 REFRESH=$(cd "$INSTALLED"; grep -sl "^$PACKAGE$" */modifiers)
103 if [ -n "$REFRESH" ]; then
104 _ 'The following packages have been modified by package "%s":' "$PACKAGE"
105 for i in $REFRESH; do
106 echo " ${i%/modifiers}"
107 done
108 fi
110 # Confirmation
111 if im && [ -z "$auto" ]; then
112 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' "$PACKAGE" "$VERSION$EXTRAVERSION")"
113 if [ "$?" -ne 0 ]; then
114 newline; _ 'Uninstallation of package "%s" cancelled.' "$PACKAGE"
115 exit 0
116 fi
117 fi
118 # We are here: non-interactive mode, or --auto, or answer 'y'
120 # Removing package
121 title 'Removing package "%s"' "$PACKAGE"
123 # [1/4] Pre-remove commands
124 call_pre_remove "$INSTALLED/$PACKAGE/receipt"
127 # [2/4] Removing files
128 action 'Removing all files installed...'
129 if [ -f "$INSTALLED/$PACKAGE/modifiers" ]; then
130 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do
131 for mod in $(cat "$INSTALLED/$PACKAGE/modifiers"); do
132 [ -f "$INSTALLED/$mod/files.list" ] && \
133 [ $(grep "^$(echo $file | grepesc)$" "$INSTALLED/$mod/files.list" | wc -l) -gt 1 ] && \
134 continue 2
135 done
136 [ -n "$debug" ] && echo "remove_with_path $root$file"
137 remove_with_path $root$file
138 done
139 else
140 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do
141 [ -n "$debug" ] && echo "remove_with_path $root$file"
142 remove_with_path $root$file
143 done
144 fi
145 status
147 # [3/4] Post-remove commands
148 call_post_remove "$INSTALLED/$PACKAGE/receipt"
150 # [4/4] Remove package receipt and remove it from databases
151 action 'Removing package receipt...'
152 rm -rf "$INSTALLED/$PACKAGE"
153 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" "$PKGS_DB/installed.$SUM"
154 sed -i "/^$PACKAGE /d" "$PKGS_DB/installed.info"
155 status
157 footer "$(_ 'Package "%s" (%s) removed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
159 # Log this activity
160 log_pkg Removed
162 # Stop if non-interactive mode and no --auto option
163 if ! im && [ -z "$auto" ]; then exit 0; fi
165 # Process dependent packages
166 if [ -n "$ALTERED" ]; then
167 if [ -n "$auto" ]; then
168 answer=0
169 else
170 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' "$PACKAGE")"
171 answer=$?
172 fi
173 if [ "$answer" -eq 0 ]; then
174 for i in $ALTERED; do
175 if [ -d "$INSTALLED/$i" ]; then
176 tazpkg remove $i
177 fi
178 done
179 fi
180 fi
182 # Process changed packages
183 if [ -n "$REFRESH" ]; then
184 if [ -n "$auto" ]; then
185 answer=0
186 else
187 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' "$PACKAGE")"
188 answer=$?
189 fi
190 if [ "$answer" -eq 0 ]; then
191 for i in $REFRESH; do
192 if [ "$(wc -l < "$INSTALLED/$i")" -gt 1 ]; then
193 _ 'Check %s for reinstallation' "$INSTALLED/$i"
194 continue
195 fi
196 rm -r "$INSTALLED/$i"
197 tazpkg get-install ${i%/modifiers} --forced
198 done
199 fi
200 fi