tazpkg view modules/upgrade @ rev 884
Module 'check': fix to work with $root; start to add tests
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sat Dec 05 16:14:14 2015 +0200 (2015-12-05) |
parents | 0560ba4306a1 |
children | d2e1b7133079 |
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # upgrade - TazPkg module
4 # Check for upgrades and make system up-to-date
7 # Environment variables:
8 # root Root of the packages DB
9 # check Only check for upgrades
10 # install Check and install all upgraded packages
13 # Connect function libraries
14 . /lib/libtaz.sh
16 # Get TazPkg working environment
17 . @@MODULES@@/getenv
20 time="$(date +%s)"
22 # Recharge packages databases (if necessary) (respects already exported "root" value)
23 tazpkg recharge >&2
25 echo -n > "$UP_LIST"
26 blocked_counter=$(mktemp)
27 tmp_up_list=$(mktemp)
29 repo_number=1
30 for repo in $PRIORITY; do
31 if [ "$repo" == "$PKGS_DB" ]; then
32 repo_name='Main'
33 else
34 repo_name="$(basename "$repo")"
35 fi
37 [ ! -f "$repo/packages.info" ] && continue
38 {
39 cat "$BLOCKED" | awk '{printf "%s\t%s\n", $1, "b"}'
40 cat "$PKGS_DB/installed.info" | awk -F$'\t' '{printf "%s\t%s\t%s\t%s\n", $1, "i", $2, $9}'
41 cat "$repo/packages.info" | awk -F$'\t' '{printf "%s\t%s\t%s\t%s\n", $1, "p", $2, $9}'
42 } | sort -t$'\t' -k1,1 | awk -F$'\t' \
43 -vnewbuild="$(_ 'New build')" -vcolornewbuild="$(emsg '<c 34>')" \
44 -vnewver='→ ' -vcolornewver="$(emsg '<c 32>')" \
45 -vblocked=" ($(_ 'Blocked'))" -vcolorblocked="$(emsg '<c 31>')" \
46 -vcolor0="$(emsg '</c>')" \
47 -vreponum="$repo_number" -vreponame="$repo_name" \
48 -vuplist="$UP_LIST" -vblocked_counter="$blocked_counter" \
49 '{
51 if ($1 != p) {
52 if (vi && vp) {
53 bb = (b=="") ? "i" : "b"
54 if ("" vi != vp) { # important: compare as strings
55 startc = (b=="") ? colornewver : colorblocked;
56 printf "%s\t%s\t%s\t%s\t", p, vi, reponum, reponame;
57 printf "%s%s%s%s%s\t%s\n", startc, newver, vp, b, color0, bb;
58 if (b=="")
59 print p >> uplist;
60 else
61 printf 1 >> blocked_counter;
62 } else if (mi != mp) {
63 startc = (b=="") ? colornewbuild : colorblocked;
64 printf "%s\t%s\t%s\t%s\t", p, vi, reponum, reponame;
65 printf "%s%s%s%s\t%s\n", startc, newbuild, b, color0, bb;
66 if (b=="")
67 print p >> uplist;
68 else
69 printf 1 >> blocked_counter;
70 }
71 }
72 p = $1; b = b1 = b2 = vi = mi = vp = mp = "";
73 }
74 if ($2 == "b") { b = blocked; b1 = bl1; b2 = bl2; }
75 if ($2 == "i") { vi = $3; mi = $4; }
76 if ($2 == "p") { vp = $3; mp = $4; }
77 }' >> "$tmp_up_list"
79 repo_number=$((repo_number + 1))
81 done
83 case "$output" in
84 html)
85 cat <<EOT
86 <table class="wide zebra">
87 <thead>
88 <tr><td>$(_ 'Package')</td><td>$(_ 'Repository')</td><td>$(_ 'Version')</td><td>$(_ 'Status')</td></tr>
89 </thead>
90 <tbody>
91 EOT
92 sort -t$'\t' -k1,3 "$tmp_up_list" | awk -F$'\t' '{
93 if($4=="Main"){repo_icon="slitaz"}else{repo_icon="web"}
94 if($6=="b"){data_icon="pkgib"}else{data_icon="pkgi"}
96 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\"/>", $1;
97 printf "<a data-icon=\"%s\" href=\"?info=%s\">%s</a></td>", data_icon, $1, $1;
98 printf "<td><span data-icon=\"%s\">%s</span></td>", repo_icon, $4;
99 printf "<td>%s</td>", $2;
100 printf "<td>%s</td></tr>\n", $5;
101 }'
102 echo '</tbody></table>' ;;
103 *)
104 emsg "<n>$(_ 'Package')<i 26>$(_ 'Repository')<i 38>$(_ 'Version')<i 49>$(_ 'Status')<->"
105 sort -t$'\t' -k1,3 "$tmp_up_list" | awk -F$'\t' \
106 '{printf "%-24s %-11s %-10s %s\n", $1, $4, $2, $5}';;
107 esac
109 sed -i /^$/d "$UP_LIST"
110 upnb=$(wc -l < "$UP_LIST")
111 pkgs=$(wc -l < "$PKGS_DB/installed.info")
112 time=$(($(date +%s) - $time))
113 if [ "$upnb" -eq 0 ]; then
114 install="n"
115 _ 'System is up-to-date...'
116 else
117 blocked_count=$(wc -m < "$blocked_counter")
119 blocked=$(_p \
120 '%s blocked' \
121 '%s blocked' "$blocked_count" \
122 "$blocked_count")
124 footer "$(_p \
125 'You have %s available upgrade (%s)' \
126 'You have %s available upgrades (%s)' "$upnb" \
127 "$upnb" "$blocked")"
128 fi
129 emsg "$(_p \
130 '%s installed package scanned in %ds' \
131 '%s installed packages scanned in %ds' "$pkgs" \
132 "<c 32>$pkgs</c>" "$time")"
135 # Clean
136 rm "$blocked_counter" "$tmp_up_list"
138 # Pkgs to upgrade ? Skip, let install them all, or ask user
139 [ -n "$check" ] && exit 0
141 if [ "$upnb" -gt 0 ]; then
142 if [ -n "$install" ]; then
143 answer=0
144 else
145 confirm "$(_ 'Do you wish to install them now? (y/N)')"
146 answer=$?
147 fi
148 case "$answer" in
149 0)
150 for pkg in $(cat "$UP_LIST"); do
151 echo 'y' | tazpkg -gi "$pkg" --forced #--reason="upgrade"
152 done
153 # List is generated each time and must be cleaned so
154 # tazpkg-notify doesn't find upgrades anymore.
155 rm "$UP_LIST"; touch "$UP_LIST" ;;
156 *)
157 _ 'Leaving without any upgrades installed.'
158 newline
159 exit 0 ;;
160 esac
161 fi
162 newline