spk view spk @ rev 137

spk-find: fix count
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 30 18:34:55 2014 +0200 (2014-03-30)
parents ee5a53b16e51
children 4f34d6addbf3
line source
1 #!/bin/sh
2 #
3 # Spk - The SliTaz Packages toolset. Read the README before adding or
4 # modifying 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
10 #. lib/libspk.sh
12 #
13 # Functions
14 #
16 VERSION=1.0
18 # Help and usage
19 usage() {
20 name=$(basename $0)
21 cat << EOT
23 $(boldify $(gettext "Usage:")) $name [packages|--options]
25 $(gettext "SliTaz Packages toolset v$VERSION")
27 $(boldify $(gettext "Commands:"))
28 info $(gettext "Display path, mirror and other stats")
29 activity $(gettext "Display packages activities")
30 clean $(gettext "Clean cache and temporary files")
32 $(boldify $(gettext "Options:"))
33 --add $(gettext "Install packages if mirrored")
34 --rm $(gettext "Remove installed packages")
35 --get $(gettext "Download packages specified on cmdline")
36 --block $(gettext "Add packages to the blocked list")
37 --unblock $(gettext "Remove packages from the blocked list")
38 --log $(gettext "Show package install and upgrade log")
39 --cache $(gettext "Used with --get to download in cache")
40 --forced $(gettext "Force packages reinstall or download")
41 --root= $(gettext "Set the root file system path")
42 --debug $(gettext "Display some useful debug information")
44 $(boldify $(gettext "Examples:"))
45 $name package1 package2 packageN
46 $name package package2 --block
48 EOT
49 exit 0
50 }
52 #
53 # Commands and exit
54 #
56 case "$1" in
57 ""|*usage|*help) usage ;;
58 info)
59 cache="$(du -sh $CACHE_DIR | awk '{print $1 " " $2}')"
60 extra=$(ls $extradb | wc -l)
61 newline
62 boldify "Spk info"
63 separator
64 gettext "Architecture :"; echo " $SLITAZ_ARCH"
65 gettext "Database :"; echo " $installed"
66 gettext "Cache info :"; echo " $cache"
67 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
68 gettext "Extra mirrors :"; echo " $extra"
69 count_installed
70 count_mirrored
71 separator && newline
72 exit 0 ;;
73 activity)
74 # --lines=NB
75 : ${lines=18}
76 newline
77 boldify "Spk Activity"
78 separator
79 cat $activity | tail -n $lines
80 separator && newline
81 exit 0 ;;
82 clean)
83 newline
84 boldify "Spk Clean"
85 separator
86 size=$(du -sh $CACHE_DIR | awk '{print $1}')
87 gettext "Cleaning cache:"; echo -n " $CACHE_DIR ($size)"
88 rm -rf $CACHE_DIR/* && status
89 gettext "Cleaning tmp :"; echo -n " $(dirname $tmpdir)"
90 rm -rf $(dirname $tmpdir) && status
91 separator && newline
92 exit 0 ;;
93 esac
95 #
96 # Handle packages: spk package1 ... packageN
97 #
99 #debug "cmdline: $@"
100 count=0
102 for pkg in $@
103 do
104 # Handle general: --options
105 case " $@ " in
106 *\ --get\ *)
107 # We want: package-version.tazpkg
108 package_full=$(full_package $pkg)
109 mirrored_pkg $pkg
110 [ "$mirrored" ] || continue
111 [ "$count" == 0 ] && newline
112 count=$(($count + 1))
113 download $package_full $mirror
114 unset_mirrored
115 if [ ! "$cache" ]; then
116 gettext "Moving package to current directory..."
117 mv -f "$CACHE_DIR/$package_full" .
118 status
119 fi
120 newline && continue ;;
121 esac
122 # Installed ?
123 if [ -d "$installed/$pkg" ]; then
124 # Handle: --options
125 case " $@ " in
126 *\ --block\ *)
127 check_root
128 [ -d "$installed/$pkg" ] || continue
129 if grep -qs ^${pkg}$ $blocked; then
130 echo $(boldify $pkg) $(gettext "is already blocked")
131 else
132 gettext "Blocking package:"; echo -n " $pkg"
133 echo $pkg >> $blocked
134 log "Blocked package: $pkg" && status
135 fi
136 continue ;;
137 *\ --unblock\ *)
138 check_root
139 [ -d "$installed/$pkg" ] || continue
140 if grep -qs ^${pkg}$ $blocked; then
141 gettext "Unblocking package:"; echo -n " $pkg"
142 sed -i /"^${pkg}$"/d $blocked
143 log "Unblocked package: $pkg" && status
144 else
145 echo $(boldify $pkg) $(gettext "is not blocked")
146 fi
147 continue ;;
148 *\ --rm\ *)
149 is_package_installed $pkg || continue
150 spk-rm $pkg --count=$count
151 count=$(($count + 1))
152 continue ;;
153 *\ --log\ *)
154 # Display package's log
155 if [ -f "$logdir/$pkg/install.log" ]; then
156 count=$(($count + 1))
157 [ "$count" == "1" ] && newline
158 colorize 36 $(gettext "Install log for:"; echo " $pkg")
159 separator
160 cat $logdir/$pkg/install.log
161 else
162 gettext "Any install log for:"; boldify " $pkg"
163 fi
164 if [ -f "$logdir/$pkg/up.log" ]; then
165 colorize 36 $(gettext "Upgrade log for:"; echo " $pkg")
166 separator
167 cat $logdir/$pkg/up.log
168 else
169 colorize 36 $(gettext "Any upgrade log for:"; echo " $pkg")
170 newline
171 fi
172 continue ;;
173 *\ --extract\ *)
174 newline
175 echo $(boldify $(gettext "Extracting:")) $pkg
176 separator ;;
177 *\ --forced\ *)
178 spk-add --forced $pkg --count=$count
179 count=$(($count + 1))
180 continue ;;
181 esac
182 count=$(($count + 1))
183 [ "$count" == 1 ] && newline
184 unset_receipt
185 source_receipt $installed/$pkg/receipt
186 boldify $(gettext "Package") $pkg
187 separator
188 gettext "Status :"; colorize 32 " installed"
189 receipt_info
190 separator && newline
191 continue
192 fi
193 # Mirrored ?
194 mirrored_pkg $pkg
195 if [ "$mirrored" ]; then
196 # Handle mirrored: --options
197 case " $@ " in
198 *\ --add\ *)
199 spk-add $pkg --count=$count
200 count=$(($count + 1))
201 continue ;;
202 esac
203 count=$(($count + 1))
204 [ "$count" == 1 ] && newline
205 boldify $(gettext "Package") $pkg
206 separator
207 gettext "Status :"; colorize 31 " not installed"
208 gettext "Version :"; echo "$mirrored" | cut -d '|' -f 2
209 gettext "Short desc :"; echo "$mirrored" | cut -d '|' -f 3
210 gettext "Category :"; echo "$mirrored" | cut -d '|' -f 4
211 separator && newline
212 continue
213 fi
214 unset mirrored
215 # Skip options such as --confirm or unknown package
216 case "$pkg" in
217 --*) continue ;;
218 *) gettext "WARNING: Unknown package"; echo ": $pkg"
219 esac
220 done
221 exit 0