spk view spk-up @ rev 131

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Mar 03 16:06:46 2014 +0000 (2014-03-03)
parents 8bcd11c1cc91
children 34bfe92ee9f6
line source
1 #!/bin/sh
2 #
3 # Spk-up - Update packages. 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
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 "Recharge the packages lists")
26 --add $(gettext "Install upgrades automatically")
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 for 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 lists from one mirror or all mirrors
49 recharge_lists() {
50 newline
51 boldify $(gettext "Updating packages lists")
52 separator
53 local check="$extradb/*/mirror $PKGS_DB/mirror"
54 if [ "$mirror" ]; then
55 check=$extradb/$mirror/mirror
56 [ "$mirror" == "main" ] && check=$PKGS_DB/mirror
57 fi
58 for mirror in $check; do
59 [ -f "$mirror" ] || continue
60 # Skip local mirror
61 [ ! $(readlink $(dirname $mirror)/packages.desc) ] || continue
62 # Get want a mirror name and download url
63 name=$(basename $(dirname $mirror))
64 url=$(cat $mirror)
65 lists="packages.list packages.md5 packages.desc packages.equiv files.list.lzma"
66 [ "$(dirname $mirror)" == "$PKGS_DB" ] && name="main"
67 [ "$quiet" ] && quiet="-q"
69 gettext "Checking mirror:"; colorize 34 " $name"
70 cd $(dirname $mirror)
72 # ID
73 [ -f "ID" ] || echo "$$" > ID
74 mv ID ID.bak
75 wget -q ${url%/}/ID
76 debug "ID: $(cat ID)"
77 debug "ID.bak: $(cat ID.bak)"
78 if [ $(cat ID) == $(cat ID.bak) ] && [ ! "$forced" ]; then
79 gettext "Mirror is up-to-date"; newline
80 continue
81 fi
83 # Backup and get all lists
84 for list in $lists
85 do
86 [ -f "$list" ] && cp -f $list $list.bak
87 debug "url: ${url%/}/$list"
88 rm -f $list
89 busybox wget $quiet ${url%/}/$list
90 done
91 done
92 separator
93 }
95 # Repo priority: local, extras then official
96 priority() {
97 extras=$(ls $extradb | sed s"/local//")
98 for i in $extras; do
99 extras="$extradb/$i"
100 done
101 [ -d "$extradb/local" ] && local="$extradb/local"
102 echo "$local $extras $PKGS_DB"
103 }
105 # Types: blocked, new build or new version
106 up_type() {
107 # Jump to next repository if pkg doesn't exist in this one.
108 grep -q "^$PACKAGE |" $dbdesc || continue
110 echo -n "$PACKAGE"
111 echo -n $(indent 28 "$VERSION")
113 # Blocked
114 if $(grep -qs "^$PACKAGE" $blocked); then
115 blocked_count=$(($blocked_count + 1))
116 echo -n $(colorize 31 $(indent 48 $(gettext "Blocked")))
117 indent 68 "$reponame"
118 break
119 fi
121 new=$(grep "^$PACKAGE |" $dbdesc | awk '{print $3}')
123 if [ "$VERSION" == "$new" ]; then
124 build_count=$(($build_count + 1))
125 echo -n $(colorize 34 $(indent 48 $(gettext "New build")))
126 else
127 echo -n $(colorize 32 $(indent 48 $(gettext "New") $new))
128 fi
129 indent 68 "$reponame"
130 echo "$PACKAGE" >> $pkgsup
131 }
133 # Check if we have an upgrade for a package
134 check_pkgup() {
135 unset_receipt
136 source_receipt $pkg/receipt
137 localdb=$extradb/local
138 sum=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
139 $installed.$SUM | awk '{print $1}')
141 # Skip up-to-date local packages
142 if [ -d "$localdb" ] && fgrep -q "$sum $PACKAGE-" $localdb/packages.$SUM; then
143 reponame=$(gettext "Local")
144 return 0
145 fi
147 for repo in $(priority); do
148 dbdesc=$repo/packages.desc
149 dbsum=$repo/packages.$SUM
151 # Mirror name
152 case $repo in
153 $PKGS_DB) reponame=$(gettext "Official") ;;
154 $localdb) reponame=$(gettext "Local") ;;
155 *) reponame=$(gettext "Extra") ;;
156 esac
157 # Overwrite: Local has 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 check_root
191 recharge_lists
192 newline && exit 0 ;;
193 --*) continue ;;
194 *)
195 pkg="$arg"
196 system=no
197 check_root
198 [ "$count" == 0 ] && up_headers
199 if is_package_installed $pkg; then
200 count=$(($count +1))
201 cd $installed
202 source_receipt $pkg/receipt
203 check=$(check_pkgup)
204 if [ "$check" != "" ]; then
205 echo "$check"
206 [ "$add" ] && install_up
207 else
208 echo -n "$pkg"
209 echo -n $(indent 28 "$VERSION")
210 echo -n $(colorize 32 $(indent 48 $(gettext "up-to-date")))
211 check_pkgup
212 indent 68 "$reponame"
213 fi
214 fi ;;
215 esac
216 done
218 # Skip system-wide upgrade if some packages was updated individually.
219 if [ "$system" ]; then
220 [ "$add" ] || newline
221 exit 0
222 fi
224 #
225 # Check all mirrors list and upgrade system.
226 #
228 time=$(date +%s)
229 build_count=0
230 blocked_count=0
232 check_root
233 recharge_lists
234 up_headers
235 cd $installed
236 newline > $pkgsup
238 # Check all installed packages
239 for pkg in *
240 do
241 check_pkgup
242 done
244 # Remove empty line and count
245 sed -i /^$/d $pkgsup
246 upnb=$(cat $pkgsup | wc -l)
247 pkgs=$(ls | wc -l)
248 time=$(($(date +%s) - $time))
250 if [ "$upnb" == 0 ] && [ "$blocked_count" == 0 ]; then
251 gettext "System is up-to-date..."; newline
252 fi
253 separator
254 echo -n "$pkgs "; gettext "installed packages scanned in"; echo " ${time}s"
255 newline
257 # Summary
258 boldify $(gettext "Packages upgrade summary")
259 separator
260 gettext "New version :"; colorize 32 " $(($upnb - $build_count))"
261 gettext "New build :"; colorize 34 " $build_count"
262 gettext "Blocked :"; colorize 31 " $blocked_count"
263 separator
264 newline
266 # Pkgs to upgrade ? Skip, let --add/--install them all or ask user
267 if [ "$upnb" -gt 0 ]; then
268 if [ "$add" ] || [ "$install" ]; then
269 continue
270 else
271 gettext "Do you wish to upgrade now"
272 if ! confirm; then
273 gettext "Upgrade cancelled"
274 echo -e "\n" && exit 0
275 fi
276 fi
277 # Install and log all upgrade
278 for pkg in $(cat $pkgsup)
279 do
280 install_up
281 done
282 # List is generated each time and must be cleaned so
283 # tazpkg-notify doesn't find upgrades anymore.
284 rm $pkgsup && touch $pkgsup
285 newline
286 gettext "Handled upgrades:"; colorize 32 " $upnb"
287 newline
288 fi
290 exit 0