spk view spk-rm @ rev 68
bunch of improvments to download
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 18 21:24:30 2012 +0200 (2012-05-18) |
parents | 917a909ee92b |
children | 0cb21eb5cf20 |
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 boldify $(gettext "Removing"; echo " $pkg")
54 separator
55 [ "$verbose" ] && echo "DB: $installed"
57 # Reverse deps
58 for i in $(ls $installed); do
59 [ -f $installed/$i/receipt ] || continue
60 unset_receipt
61 . $installed/$i/receipt
62 case " $(echo $DEPENDS) " in
63 *\ $pkg\ *) altered="$altered $i" ;;
64 esac
65 done
66 unset_receipt
67 . $installed/$pkg/receipt
69 if [ "$altered" ]; then
70 gettext "The following packages depend on"; colorize " $pkg" 31
71 for i in $altered; do
72 echo " $(colorize "$i" 32)"
73 done
74 fi
76 # Reverse deps are displayed, confirm uninstall.
77 if [ "$confirm" ]; then
78 gettext "Confirm uninstallation of:"; echo -n " $pkg"
79 if ! confirm; then
80 gettext "Uninstallation cancelled"
81 echo -e "\n" && continue
82 fi
83 fi
85 # Handle pre_remove
86 if grep -q ^pre_remove $installed/$PACKAGE/receipt; then
87 pre_remove $root
88 fi
90 # Remove all files
91 fileslist=$installed/$PACKAGE/files.list
92 gettext "Removing installed files:"
93 echo -n " $(wc -l $fileslist | cut -d " " -f 1)"
94 [ "$verbose" ] && newline
95 for file in $(cat $fileslist)
96 do
97 if [ "$verbose" ]; then
98 gettext "Removing:"; echo -n " ${root}${file}"
99 fi
100 remove_file ${root}${file}
101 [ "$verbose" ] && status
102 done
103 [ ! "$verbose" ] && status
105 # Handle post_remove
106 if grep -q ^post_remove $installed/$PACKAGE/receipt; then
107 post_remove $root
108 fi
110 # Remove package receipt.
111 gettext "Removing package receipt..."
112 rm -rf $installed/$PACKAGE
113 sed -i "/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg/"d $installed.$SUM
114 status
116 separator
118 # Do we have packages depending on $pkg to remove ?
119 if [ "$altered" ]; then
120 if [ "$confirm" ]; then
121 gettext "Remove packages depending on:"; echo -n " $pkg"
122 if ! confirm; then
123 gettext "Keeping packages..."; newline
124 newline && continue
125 fi
126 fi
127 for i in $altered; do
128 if [ -d "$installed/$i" ]; then
129 spk-rm $i --root=$root
130 fi
131 done
132 else
133 newline
134 fi
135 }
137 #
138 # Commands and exit
139 #
141 case "$1" in
142 ""|*usage|*help) usage ;;
143 esac
145 #
146 # Handle packages
147 #
149 : ${count=0}
150 check_root
152 for pkg in $@
153 do
154 # Skip options
155 case "$pkg" in
156 --*) continue
157 esac
158 # Be sure package is installed
159 if [ ! -f "$installed/$pkg/receipt" ]; then
160 echo -n "$(boldify "$pkg") "
161 gettext "package is not installed"; newline
162 continue
163 fi
164 count=$(($count + 1))
165 [ "$count" == 1 ] && newline
166 remove
167 log "Removed package: $pkg"
168 done
170 # Show all new counted packages in verbose mode
171 if [ "$verbose" ]; then
172 gettext "Removed packages:"; colorize " $count" 34
173 fi
175 exit 0