spk view spk-up @ rev 92

spk-up: small cosmetic fix
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 25 16:01:20 2012 +0200 (2012-05-25)
parents 75dbce631b42
children f59ca5e10f5e
line source
1 #!/bin/sh
2 #
3 # Spk-up - Update 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 "Update packages lists and upgrade the system")
24 $(boldify $(gettext "Options:"))
25 --list $(gettext "Recharges the packages lists")
26 --add $(gettext "Install upgrade automaticaly")
27 --forced $(gettext "Force recharging the lists")
28 --mirror= $(gettext "Specify a mirror to check")
30 $(boldify $(gettext "Examples:"))
31 $name package1 package2
32 $name --list --forced --mirror=main
34 EOT
35 exit 0
36 }
38 # Headers fo system or packages update
39 up_headers() {
40 newline
41 boldify $(gettext "Package") \
42 $(echo -n $(indent 28 $(gettext "Version"))) \
43 $(echo -n $(indent 48 $(gettext "Status"))) \
44 $(echo -n $(indent 68 $(gettext "Mirror")))
45 separator
46 }
48 # Recharges all list from one mirror or all mirrors
49 recharge_lists() {
50 check_root
51 newline
52 boldify $(gettext "Updating packages lists")
53 separator
54 check="$extradb/*/mirror $PKGS_DB/mirror"
55 if [ "$mirror" ]; then
56 check=$extradb/$mirror/mirror
57 [ "$mirror" == "main" ] && check=$PKGS_DB/mirror
58 fi
59 for mirror in $check; do
60 [ -f "$mirror" ] || continue
61 # Skip local mirror
62 [ ! $(readlink $(dirname $mirror)/packages.desc) ] || continue
63 # Get want a mirror name and download url
64 name=$(basename $(dirname $mirror))
65 url=$(cat $mirror)
66 lists="packages.list packages.md5 packages.desc packages.equiv files.list.lzma"
67 [ "$(dirname $mirror)" == "$PKGS_DB" ] && name="main"
68 [ "$quiet" ] && quiet="-q"
70 gettext "Checking mirror:"; colorize 34 " $name"
71 cd $(dirname $mirror)
73 # ID
74 [ -f "ID" ] || echo "$$" > ID
75 mv ID ID.bak
76 wget -q ${url%/}/ID
77 debug "ID: $(cat ID)"
78 debug "ID.bak: $(cat ID.bak)"
79 if [ $(cat ID) == $(cat ID.bak) ] && [ ! "$forced" ]; then
80 gettext "Mirror is up-to-date"; newline
81 continue
82 fi
84 # Backup and get all lists
85 for list in $lists
86 do
87 [ -f "$list" ] && cp -f $list $list.bak
88 debug "url: ${url%/}/$list"
89 rm -f $list
90 busybox wget $quiet ${url%/}/$list
91 done
92 done
93 separator
94 }
96 # Repo priority: local, extras then official
97 priority() {
98 extras=$(ls $extradb | sed s"/local//")
99 for i in $extras; do
100 extras="$extradb/$i"
101 done
102 [ -d "$extradb/local" ] && local="$extradb/local"
103 echo "$local $extras $PKGS_DB"
104 }
106 # Types: blocked, new build or new version
107 up_type() {
108 # Jump to next repository if pkg doesn't exists in this one.
109 grep -q "^$PACKAGE |" $dbdesc || continue
111 echo -n "$PACKAGE"
112 echo -n $(indent 28 "$VERSION")
114 # Blocked
115 if $(grep -qs "^$PACKAGE" $blocked); then
116 blocked_count=$(($blocked_count + 1))
117 echo -n $(colorize 31 $(indent 48 $(gettext "Blocked")))
118 indent 68 "$reponame"
119 break
120 fi
122 new=$(grep "^$PACKAGE |" $dbdesc | awk '{print $3}')
124 if [ "$VERSION" == "$new" ]; then
125 build_count=$(($build_count + 1))
126 echo -n $(colorize 34 $(indent 48 $(gettext "New build")))
127 else
128 echo -n $(colorize 32 $(indent 48 $(gettext "New") $new))
129 fi
130 indent 68 "$reponame"
131 echo "$PACKAGE" >> $pkgsup
132 }
134 # Check if we have an upgrade for a package
135 check_pkgup() {
136 unset_receipt
137 . $pkg/receipt
138 localdb=$extradb/local
139 sum=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
140 $installed.$SUM | awk '{print $1}')
142 # Skip up-to-date local packages
143 if [ -d "$localdb" ] && fgrep -q "$sum $PACKAGE-" $localdb/packages.$SUM; then
144 reponame=$(gettext "Local")
145 return 0
146 fi
148 for repo in $(priority); do
149 dbdesc=$repo/packages.desc
150 dbsum=$repo/packages.$SUM
152 # Mirror name
153 case $repo in
154 $PKGS_DB) reponame=$(gettext "Official") ;;
155 *) reponame=$(gettext "Extra") ;;
156 esac
157 # Overwrite: Local have priority
158 if [ -d "$localdb" ] && fgrep -q "$sum $PACKAGE-" $localdb/packages.$SUM; then
159 reponame=$(gettext "Local")
160 fi
162 # Sum match or not ?
163 if ! fgrep -q "$sum $PACKAGE-" $dbsum; then
164 up_type
165 break
166 fi
167 done
168 }
170 # Log and install an upgradable package.
171 install_up() {
172 mirrored_pkg $pkg
173 vers=$(echo "$mirrored" | awk '{print $3}')
174 mkdir -p $logdir/$pkg
175 echo "$(date '+%Y-%m-%d %H:%M') : Upgrade to $vers" >> $logdir/$pkg/up.log
176 spk-add $pkg --forced
177 }
179 #
180 # Handle packages and --options
181 #
183 count=0
185 for arg in $@
186 do
187 case "$arg" in
188 *usage|*help) usage ;;
189 --list)
190 recharge_lists
191 newline && exit 0 ;;
192 --*) continue ;;
193 *)
194 pkg=$arg
195 system=no
196 [ "$count" == 0 ] && up_headers
197 if [ -f "$installed/$pkg/receipt" ]; then
198 count=$(($count +1))
199 cd $installed
200 . $pkg/receipt
201 check=$(check_pkgup)
202 if [ "$check" != "" ]; then
203 echo "$check"
204 [ "$add" ] && install_up
205 else
206 echo -n "$pkg"
207 echo -n $(indent 28 "$VERSION")
208 echo -n $(colorize 32 $(indent 48 $(gettext "up-to-date")))
209 check_pkgup
210 indent 68 "$reponame"
211 fi
212 fi ;;
213 esac
214 done
216 # Skip system-wide upgrade if some packages was updated individually.
217 if [ "$system" ]; then
218 [ "$add" ] || newline
219 exit 0
220 fi
222 #
223 # Check all mirrors list and upgrade system.
224 #
226 time=$(date +%s)
227 build_count=0
228 blocked_count=0
230 recharge_lists
231 up_headers
232 cd $installed
233 newline > $pkgsup
235 # Check all installed packages
236 for pkg in *
237 do
238 check_pkgup
239 done
241 # Remove empty line and count
242 sed -i /^$/d $pkgsup
243 upnb=$(cat $pkgsup | wc -l)
244 pkgs=$(ls | wc -l)
245 time=$(($(date +%s) - $time))
247 if [ "$upnb" == 0 ] && [ "$blocked_count" == 0 ]; then
248 gettext "System is up-to-date..."; newline
249 fi
250 separator
251 echo -n "$pkgs "; gettext "installed packages scanned in"; echo " ${time}s"
252 newline
254 # Summary
255 boldify $(gettext "Packages upgrade summary")
256 separator
257 gettext "New version :"; colorize 32 " $(($upnb - $build_count))"
258 gettext "New build :"; colorize 34 " $build_count"
259 gettext "Blocked :"; colorize 31 " $blocked_count"
260 separator
261 newline
263 # Pkgs to upgrade ? Skip, let --add/--install them all or ask user
264 if [ "$upnb" -gt 0 ]; then
265 if [ "$add" ] || [ "$install" ]; then
266 continue
267 else
268 gettext "Do you wish to upgrade now"
269 if ! confirm; then
270 gettext "Upgrade cancelled"
271 echo -e "\n" && exit 0
272 fi
273 fi
274 # Install and log all upgrade
275 for pkg in $(cat $pkgsup)
276 do
277 install_up
278 done
279 # List is generated each time and must be cleaned so
280 # tazpkg-notify dont find upgrade anymore.
281 rm $pkgsup && touch $pkgsup
282 newline
283 gettext "Handeled upgrades:"; colorize 32 " $upnb"
284 newline
285 fi
287 exit 0