spk view spk-rm @ rev 115

Successfully converted a arch package\!
author Christian Mesh <meshca@clarkson.edu>
date Sat Jun 09 16:38:58 2012 -0500 (2012-06-09)
parents cab731b9a98c
children 254bf0179a7e
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 their 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 and 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 local altered
53 boldify $(gettext "Removing") $pkg
54 separator
55 [ "$verbose" ] && echo "DB: $installed"
57 # Reverse deps
58 for i in $(ls $installed); do
59 is_package_installed $i || continue
60 unset_receipt
61 source_receipt $installed/$i/receipt
62 case " $DEPENDS " in
63 *\ $pkg\ *) altered="$altered $i" ;;
64 esac
65 done
66 unset_receipt
67 source_receipt $installed/$pkg/receipt
69 if [ "$altered" ]; then
70 gettext "The following packages depend on"; colorize 31 " $pkg"
71 for i in $altered; do
72 echo " $(colorize 32 $i)"
73 done
74 fi
76 # Reverse deps are displayed, confirm uninstall.
77 if [ "$confirm" ]; then
78 echo $(gettext "Confirm uninstallation of:") " $pkg"
79 if ! confirm; then
80 gettext "Uninstallation cancelled"
81 newline && 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 "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 echo $(gettext "Removing packages depending on:") $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 ! is_package_installed $pkg; 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 34 " $count"
173 fi
175 exit 0