tazpkg view 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
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; }
50 PACKAGE="$1"
52 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
53 newline; _ 'Package "%s" is not installed.' "$PACKAGE"
54 exit 1
55 fi
57 . "$INSTALLED/$PACKAGE/receipt"
59 # Info #1: dependent packages (to be processed later)
60 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " 'index(" " $8 " ", p) { printf " %s\n", $1 }' "$PKGS_DB/installed.info")"
62 if [ -n "$ALTERED" ]; then
63 _ 'The following packages depend on package "%s":' "$PACKAGE"
64 echo "$ALTERED"
65 fi
67 # Info #2: changed packages (to be processed later)
68 REFRESH=$(cd "$INSTALLED"; grep -sl "^$PACKAGE$" */modifiers)
70 if [ -n "$REFRESH" ]; then
71 _ 'The following packages have been modified by package "%s":' "$PACKAGE"
72 for i in $REFRESH; do
73 echo " ${i%/modifiers}"
74 done
75 fi
77 # Confirmation
78 if im && [ -z "$auto" ]; then
79 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' "$PACKAGE" "$VERSION$EXTRAVERSION")"
80 if [ "$?" -ne 0 ]; then
81 newline; _ 'Uninstallation of package "%s" cancelled.' "$PACKAGE"
82 exit 0
83 fi
84 fi
85 # We are here: non-interactive mode, or --auto, or answer 'y'
87 # Removing package
88 title 'Removing package "%s"' "$PACKAGE"
90 # [1/4] Pre-remove commands
91 if grep -q ^pre_remove "$INSTALLED/$PACKAGE/receipt"; then
92 action 'Execution of pre-remove commands...'
93 pre_remove
94 status
95 fi
97 # [2/4] Removing files
98 action 'Removing all files installed...'
99 if [ -f "$INSTALLED/$PACKAGE/modifiers" ]; then
100 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do
101 for mod in $(cat "$INSTALLED/$PACKAGE/modifiers"); do
102 [ -f "$INSTALLED/$mod/files.list" ] && \
103 [ $(grep "^$(echo $file | grepesc)$" "$INSTALLED/$mod/files.list" | wc -l) -gt 1 ] && \
104 continue 2
105 done
106 [ -n "$debug" ] && echo "remove_with_path $root$file"
107 remove_with_path $root$file
108 done
109 else
110 for file in $(cat "$INSTALLED/$PACKAGE/files.list"); do
111 [ -n "$debug" ] && echo "remove_with_path $root$file"
112 remove_with_path $root$file
113 done
114 fi
115 status
117 # [3/4] Post-remove commands
118 if grep -q ^post_remove "$INSTALLED/$PACKAGE/receipt"; then
119 action 'Execution of post-remove commands...'
120 post_remove
121 status
122 fi
124 # [4/4] Remove package receipt and remove it from databases
125 action 'Removing package receipt...'
126 rm -rf "$INSTALLED/$PACKAGE"
127 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" "$PKGS_DB/installed.$SUM"
128 sed -i "/^$PACKAGE /d" "$PKGS_DB/installed.info"
129 status
131 footer "$(_ 'Package "%s" (%s) removed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
133 # Log this activity
134 log_pkg Removed
136 # Stop if non-interactive mode and no --auto option
137 if ! im && [ -z "$auto" ]; then exit 0; fi
139 # Process dependent packages
140 if [ -n "$ALTERED" ]; then
141 if [ -n "$auto" ]; then
142 answer=0
143 else
144 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' "$PACKAGE")"
145 answer=$?
146 fi
147 if [ "$answer" -eq 0 ]; then
148 for i in $ALTERED; do
149 if [ -d "$INSTALLED/$i" ]; then
150 tazpkg remove $i
151 fi
152 done
153 fi
154 fi
156 # Process changed packages
157 if [ -n "$REFRESH" ]; then
158 if [ -n "$auto" ]; then
159 answer=0
160 else
161 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' "$PACKAGE")"
162 answer=$?
163 fi
164 if [ "$answer" -eq 0 ]; then
165 for i in $REFRESH; do
166 if [ "$(wc -l < "$INSTALLED/$i")" -gt 1 ]; then
167 _ 'Check %s for reinstallation' "$INSTALLED/$i"
168 continue
169 fi
170 rm -r "$INSTALLED/$i"
171 tazpkg get-install ${i%/modifiers} --forced
172 done
173 fi
174 fi