rev |
line source |
al@836
|
1 #!/bin/sh
|
al@836
|
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
|
al@836
|
3 # upgrade - TazPkg module
|
al@836
|
4 # Check for upgrades and make system up-to-date
|
al@836
|
5
|
al@836
|
6
|
al@836
|
7 # Options:
|
al@836
|
8
|
al@836
|
9 # Environment variables:
|
al@836
|
10 # root Root of the packages DB
|
al@836
|
11 # check Only check for upgrades
|
al@836
|
12 # install Check and install all upgraded packages
|
al@836
|
13
|
al@836
|
14
|
al@836
|
15 # Connect function libraries
|
al@836
|
16 . /lib/libtaz.sh
|
al@836
|
17
|
al@836
|
18
|
al@836
|
19
|
al@836
|
20
|
al@836
|
21 # Get TazPkg working environment
|
al@836
|
22 # ------------------------------
|
al@836
|
23
|
al@836
|
24 [ ! -d "$root/etc/slitaz" ] && mkdir -p "$root/etc/slitaz"
|
al@836
|
25 [ ! -e "$root/etc/slitaz/slitaz.conf" ] && cp /etc/slitaz/slitaz.conf "$root/etc/slitaz"
|
al@836
|
26 [ ! -e "$root/etc/slitaz/tazpkg.conf" ] && cp /etc/slitaz/tazpkg.conf "$root/etc/slitaz"
|
al@836
|
27 [ ! -e "$root/etc/slitaz-release" ] && echo 'cooking' > "$root/etc/slitaz-release"
|
al@836
|
28
|
al@836
|
29 # Read configuration
|
al@836
|
30 if [ -n "$root" ]; then
|
al@836
|
31 # Patch external conf files to correctly handle --root value
|
al@836
|
32 slitaz_conf=$(mktemp); cp "$root/etc/slitaz/slitaz.conf" $slitaz_conf
|
al@836
|
33 tazpkg_conf=$(mktemp); cp "$root/etc/slitaz/tazpkg.conf" $tazpkg_conf
|
al@836
|
34 sed -i "s| /| $root/|g; s|\"/|\"$root/|g" $slitaz_conf $tazpkg_conf
|
al@836
|
35 . $slitaz_conf; . $tazpkg_conf; rm $slitaz_conf $tazpkg_conf
|
al@836
|
36 else
|
al@836
|
37 . /etc/slitaz/slitaz.conf; . /etc/slitaz/tazpkg.conf
|
al@836
|
38 fi
|
al@836
|
39
|
al@836
|
40
|
al@836
|
41
|
al@836
|
42
|
al@836
|
43 # Functions
|
al@836
|
44 # ---------
|
al@836
|
45
|
al@836
|
46 # Get repositories priority using $PKGS_DB/priority.
|
al@836
|
47 # In this file undigest repos are called by their names and main mirror
|
al@836
|
48 # by 'main'. Sort order: priority
|
al@836
|
49
|
al@836
|
50 look_for_priority() {
|
al@836
|
51 [ -s "$PKGS_DB/priority" ] && priority=$(cat $PKGS_DB/priority)
|
al@836
|
52
|
al@836
|
53 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
|
al@836
|
54 if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ $PKGS_DB/priority; then
|
al@836
|
55 priority=$(echo -e "$priority\n$rep")
|
al@836
|
56 fi
|
al@836
|
57 done
|
al@836
|
58
|
al@836
|
59 priority=$(echo "$priority" | sed '/^$/d' | \
|
al@836
|
60 while read line; do
|
al@836
|
61 case $line in
|
al@836
|
62 (main) echo $PKGS_DB;;
|
al@836
|
63 (*) echo $PKGS_DB/undigest/$line;;
|
al@836
|
64 esac
|
al@836
|
65 done)
|
al@836
|
66 }
|
al@836
|
67
|
al@836
|
68
|
al@836
|
69
|
al@836
|
70
|
al@836
|
71 time="$(date +%s)"
|
al@836
|
72
|
al@836
|
73 # Recharge packages databases (if necessary) (respects "root" value)
|
al@836
|
74 tazpkg recharge >&2
|
al@836
|
75
|
al@836
|
76 echo -n > $UP_LIST
|
al@836
|
77 blocked_counter=$(mktemp)
|
al@836
|
78 tmp_up_list=$(mktemp)
|
al@836
|
79
|
al@836
|
80 look_for_priority
|
al@836
|
81 repo_number=1
|
al@836
|
82 for repo in $priority; do
|
al@836
|
83 if [ "$repo" == "$PKGS_DB" ]; then
|
al@836
|
84 repo_name='Main'
|
al@836
|
85 else
|
al@836
|
86 repo_name="$(basename "$repo")"
|
al@836
|
87 fi
|
al@836
|
88
|
al@836
|
89 [ ! -f "$repo/packages.info" ] && continue
|
al@836
|
90 {
|
al@836
|
91 cat $BLOCKED | awk '{printf "%s\t%s\n", $1, "b"}';
|
al@836
|
92 cat $PKGS_DB/installed.info | awk -F$'\t' '{printf "%s\t%s\t%s\t%s\n", $1, "i", $2, $9}';
|
al@836
|
93 cat $repo/packages.info | awk -F$'\t' '{printf "%s\t%s\t%s\t%s\n", $1, "p", $2, $9}'
|
al@836
|
94 } | sort -t$'\t' -k1,1 | awk -F$'\t' \
|
al@836
|
95 -vnewbuild="$(_ 'New build')" -vcolornewbuild="$(emsg '<c 34>')" \
|
al@836
|
96 -vnewver='→ ' -vcolornewver="$(emsg '<c 32>')" \
|
al@836
|
97 -vblocked=" ($(_ 'Blocked'))" -vcolorblocked="$(emsg '<c 31>')" \
|
al@836
|
98 -vcolor0="$(emsg '</c>')" \
|
al@836
|
99 -vreponum=$repo_number -vreponame=$repo_name \
|
al@836
|
100 -vuplist="$UP_LIST" -vblocked_counter="$blocked_counter" \
|
al@836
|
101 '{
|
al@836
|
102
|
al@836
|
103 if ($1 != p) {
|
al@836
|
104 if (vi && vp) {
|
al@836
|
105 bb = (b=="") ? "i" : "b"
|
al@836
|
106 if ("" vi != vp) { # important: compare as strings
|
al@836
|
107 startc = (b=="") ? colornewver : colorblocked;
|
al@836
|
108 printf "%s\t%s\t%s\t%s\t%s%s%s%s%s\t%s\n", p, vi, reponum, reponame, startc, newver, vp, b, color0, bb;
|
al@836
|
109 print p >> uplist;
|
al@836
|
110 if (b!="") printf 1 >> blocked_counter;
|
al@836
|
111 } else if (mi != mp) {
|
al@836
|
112 startc = (b=="") ? colornewbuild : colorblocked;
|
al@836
|
113 printf "%s\t%s\t%s\t%s\t%s%s%s%s\t%s\n", p, vi, reponum, reponame, startc, newbuild, b, color0, bb;
|
al@836
|
114 print p >> uplist;
|
al@836
|
115 if (b!="") printf 1 >> blocked_counter;
|
al@836
|
116 }
|
al@836
|
117 }
|
al@836
|
118 p = $1; b = b1 = b2 = vi = mi = vp = mp = "";
|
al@836
|
119 }
|
al@836
|
120 if ($2 == "b") { b = blocked; b1 = bl1; b2 = bl2; }
|
al@836
|
121 if ($2 == "i") { vi = $3; mi = $4; }
|
al@836
|
122 if ($2 == "p") { vp = $3; mp = $4; }
|
al@836
|
123 }' >> $tmp_up_list
|
al@836
|
124
|
al@836
|
125 repo_number=$((repo_number + 1))
|
al@836
|
126
|
al@836
|
127 done
|
al@836
|
128
|
al@836
|
129 case "$output" in
|
al@836
|
130 html)
|
al@836
|
131 cat <<EOT
|
al@836
|
132 <table class="wide zebra">
|
al@836
|
133 <thead>
|
al@836
|
134 <tr><td>$(_ 'Package')</td><td>$(_ 'Repository')</td><td>$(_ 'Version')</td><td>$(_ 'Status')</td></tr>
|
al@836
|
135 </thead>
|
al@836
|
136 <tbody>
|
al@836
|
137 EOT
|
al@836
|
138 sort -t$'\t' -k1,3 $tmp_up_list | awk -F$'\t' '{
|
al@836
|
139 if($4=="Main"){repoicon="slitaz"}else{repoicon="web"}
|
al@836
|
140 if($6=="b"){pkgicon="pkgib"}else{pkgicon="pkgi"}
|
al@836
|
141
|
al@836
|
142 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\"/>", $1;
|
al@836
|
143 printf "<a data-icon=\"%s\" href=\"?info=%s\">%s</a></td>", pkgicon, $1, $1;
|
al@836
|
144 printf "<td><span data-icon=\"%s\">%s</span></td>", repoicon, $4;
|
al@836
|
145 printf "<td>%s</td>", $2;
|
al@836
|
146 printf "<td>%s</td></tr>\n", $5;
|
al@836
|
147 }'
|
al@836
|
148 echo '</tbody></table>' ;;
|
al@836
|
149 *)
|
al@836
|
150 emsg "<n>$(_ 'Package')<i 26>$(_ 'Repository')<i 38>$(_ 'Version')<i 49>$(_ 'Status')<->"
|
al@836
|
151 sort -t$'\t' -k1,3 $tmp_up_list | awk -F$'\t' \
|
al@836
|
152 '{printf "%-24s %-11s %-10s %s\n", $1, $4, $2, $5}';;
|
al@836
|
153 esac
|
al@836
|
154
|
al@836
|
155 sed -i /^$/d $UP_LIST
|
al@836
|
156 upnb=$(wc -l < $UP_LIST)
|
al@836
|
157 pkgs=$(wc -l < $PKGS_DB/installed.info)
|
al@836
|
158 time=$(($(date +%s) - $time))
|
al@836
|
159 if [ "$upnb" -eq 0 ]; then
|
al@836
|
160 install="n"
|
al@836
|
161 _ 'System is up-to-date...'
|
al@836
|
162 fi
|
al@836
|
163
|
al@836
|
164 if [ "$upnb" -ne 0 ]; then
|
al@836
|
165 blocked_count="$(wc -m < $blocked_counter)"
|
al@836
|
166
|
al@836
|
167 blocked="$(_p \
|
al@836
|
168 '%s blocked' \
|
al@836
|
169 '%s blocked' $blocked_count \
|
al@836
|
170 $blocked_count)"
|
al@836
|
171
|
al@836
|
172 footer "$(_p \
|
al@836
|
173 'You have %s available upgrade (%s)' \
|
al@836
|
174 'You have %s available upgrades (%s)' $upnb \
|
al@836
|
175 $upnb "$blocked")"
|
al@836
|
176 fi
|
al@836
|
177 emsg "$(_p \
|
al@836
|
178 '%s installed package scanned in %ds' \
|
al@836
|
179 '%s installed packages scanned in %ds' $pkgs \
|
al@836
|
180 "<c 32>$pkgs</c>" $time)"
|
al@836
|
181
|
al@836
|
182
|
al@836
|
183 # Clean
|
al@836
|
184 rm $blocked_counter $tmp_up_list
|
al@836
|
185
|
al@836
|
186 # Pkgs to upgrade ? Skip, let install them all, or ask user
|
al@836
|
187 [ -n "$check" ] && exit 0
|
al@836
|
188 if [ "$upnb" -gt 0 ]; then
|
al@836
|
189 if [ -n "$install" ]; then
|
al@836
|
190 answer=0
|
al@836
|
191 else
|
al@836
|
192 confirm "$(_ 'Do you wish to install them now? (y/N)')"
|
al@836
|
193 answer=$?
|
al@836
|
194 fi
|
al@836
|
195 case "$answer" in
|
al@836
|
196 0)
|
al@836
|
197 for pkg in $(cat $UP_LIST); do
|
al@836
|
198 echo 'y' | tazpkg -gi "$pkg" --forced #--reason="upgrade"
|
al@836
|
199 done
|
al@836
|
200 # List is generated each time and must be cleaned so
|
al@836
|
201 # tazpkg-notify doesn't find upgrades anymore.
|
al@836
|
202 rm $UP_LIST; touch $UP_LIST ;;
|
al@836
|
203 *)
|
al@836
|
204 _ 'Leaving without any upgrades installed.'
|
al@836
|
205 newline
|
al@836
|
206 exit 0 ;;
|
al@836
|
207 esac
|
al@836
|
208 fi
|
al@836
|
209 newline
|