spk view spk-up @ rev 153

Fix and and simpify CONFIG_FILES management
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 25 03:48:55 2014 +0200 (2014-04-25)
parents 34bfe92ee9f6
children a0bdc170c51e
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 case "$SLITAZ_ARCH" in
139 arm*|x86_64)
140 pkgfile="$PACKAGE-${VERSION}$EXTRAVERSION-$SLITAZ_ARCH.tazpkg" ;;
141 *)
142 pkgfile="$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" ;;
143 esac
144 sum=$(fgrep " $pkgfile" $installed.$SUM | awk '{print $1}')
146 # Skip up-to-date local packages
147 if [ -d "$localdb" ] && fgrep -q "$sum $PACKAGE-" $localdb/packages.$SUM; then
148 reponame=$(gettext "Local")
149 return 0
150 fi
152 for repo in $(priority); do
153 dbdesc=$repo/packages.desc
154 dbsum=$repo/packages.$SUM
156 # Mirror name
157 case $repo in
158 $PKGS_DB) reponame=$(gettext "Official") ;;
159 $localdb) reponame=$(gettext "Local") ;;
160 *) reponame=$(gettext "Extra") ;;
161 esac
162 # Overwrite: Local has priority
163 #if [ -d "$localdb" ] && fgrep -q "$sum $PACKAGE-" $localdb/packages.$SUM; then
164 #reponame=$(gettext "Local")
165 #fi
167 # Sum match or not ?
168 if ! fgrep -q "$sum $PACKAGE-" $dbsum; then
169 up_type
170 break
171 fi
172 done
173 }
175 # Log and install an upgradable package.
176 install_up() {
177 mirrored_pkg $pkg
178 vers=$(echo "$mirrored" | awk '{print $3}')
179 mkdir -p $logdir/$pkg
180 echo "$(date '+%Y-%m-%d %H:%M') : Upgrade to $vers" >> $logdir/$pkg/up.log
181 spk-add $pkg --forced
182 }
184 #
185 # Handle packages and --options
186 #
188 count=0
190 for arg in $@
191 do
192 case "$arg" in
193 *usage|*help) usage ;;
194 --list)
195 check_root
196 recharge_lists
197 newline && exit 0 ;;
198 --*) continue ;;
199 *)
200 pkg="$arg"
201 system=no
202 check_root
203 [ "$count" == 0 ] && up_headers
204 if is_package_installed $pkg; then
205 count=$(($count +1))
206 cd $installed
207 source_receipt $pkg/receipt
208 check=$(check_pkgup)
209 if [ "$check" != "" ]; then
210 echo "$check"
211 [ "$add" ] && install_up
212 else
213 echo -n "$pkg"
214 echo -n $(indent 28 "$VERSION")
215 echo -n $(colorize 32 $(indent 48 $(gettext "up-to-date")))
216 check_pkgup
217 indent 68 "$reponame"
218 fi
219 fi ;;
220 esac
221 done
223 # Skip system-wide upgrade if some packages was updated individually.
224 if [ "$system" ]; then
225 [ "$add" ] || newline
226 exit 0
227 fi
229 #
230 # Check all mirrors list and upgrade system.
231 #
233 time=$(date +%s)
234 build_count=0
235 blocked_count=0
237 check_root
238 recharge_lists
239 up_headers
240 cd $installed
241 newline > $pkgsup
243 # Check all installed packages
244 for pkg in *
245 do
246 check_pkgup
247 done
249 # Remove empty line and count
250 sed -i /^$/d $pkgsup
251 upnb=$(cat $pkgsup | wc -l)
252 pkgs=$(ls | wc -l)
253 time=$(($(date +%s) - $time))
255 if [ "$upnb" == 0 ] && [ "$blocked_count" == 0 ]; then
256 gettext "System is up-to-date..."; newline
257 fi
258 separator
259 echo -n "$pkgs "; gettext "installed packages scanned in"; echo " ${time}s"
260 newline
262 # Summary
263 boldify $(gettext "Packages upgrade summary")
264 separator
265 gettext "New version :"; colorize 32 " $(($upnb - $build_count))"
266 gettext "New build :"; colorize 34 " $build_count"
267 gettext "Blocked :"; colorize 31 " $blocked_count"
268 separator
269 newline
271 # Pkgs to upgrade ? Skip, let --add/--install them all or ask user
272 if [ "$upnb" -gt 0 ]; then
273 if [ "$add" ] || [ "$install" ]; then
274 continue
275 else
276 gettext "Do you wish to upgrade now"
277 if ! confirm; then
278 gettext "Upgrade cancelled"
279 echo -e "\n" && exit 0
280 fi
281 fi
282 # Clean up cache first
283 spk clean
284 # Install and log all upgrade
285 for pkg in $(cat $pkgsup)
286 do
287 install_up
288 done
289 # List is generated each time and must be cleaned so
290 # tazpkg-notify doesn't find upgrades anymore.
291 rm $pkgsup && touch $pkgsup
292 newline
293 gettext "Handled upgrades:"; colorize 32 " $upnb"
294 newline
295 fi
297 exit 0