tazpkg annotate modules/upgrade @ rev 840

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