tazlito annotate modules/calc_sizes @ rev 416

Separate module "calc_sizes", tweak Makefile
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Feb 24 22:02:58 2016 +0200 (2016-02-24)
parents
children 9d0d7bf20e90
rev   line source
al@416 1 #!/usr/bin/awk -f
al@416 2 # calc_sizes - module of TazLito - SliTaz Live Tool.
al@416 3
al@416 4 # Calculate sizes (estimated) and real packages number (including all dependencies)
al@416 5 # using given extracted flavor and current mirrors.
al@416 6 #
al@416 7 # Input: <unpacked flavor dir> <flavor name> [<output full list file>]
al@416 8 # Output in human readable form:
al@416 9 # <unpacked size> <packed size> <size of ISO> <number of packages>
al@416 10 # File $1/err output: unknown packages
al@416 11 # File $1/warn output: warnings about missing packages
al@416 12 # TODO: use 'equivalent packages' rules
al@416 13
al@416 14 BEGIN {
al@416 15 FS = "\t";
al@416 16 K = 1024; M = K * 1024; G = M * 1024;
al@416 17 dir = ARGV[1]; flavor = ARGV[2]; outfile = ARGV[3];
al@416 18
al@416 19 # Get listing of dir
al@416 20 "ls " dir " | tr '\n' ' '" | getline lsdir;
al@416 21
al@416 22 # Calculate rootfs_p, rootfs_u, and rootcd_u
al@416 23 if (index(lsdir, flavor ".rootfs")) {
al@416 24 "wc -c < " dir "/" flavor ".rootfs" | getline rootfs_p;
al@416 25 "zcat " dir "/" flavor ".rootfs|wc -c" | getline rootfs_u;
al@416 26 }
al@416 27 if (index(lsdir, flavor ".rootcd"))
al@416 28 "zcat " dir "/" flavor ".rootcd | wc -c" | getline rootcd_u;
al@416 29
al@416 30 errfile = dir "/err";
al@416 31 warnfile = dir "/warn";
al@416 32 system("rm " errfile " " warnfile " " outfile " 2>/dev/null");
al@416 33
al@416 34 root = ENVIRON["root"];
al@416 35
al@416 36 # Get list of 'packages.info' lists using priority
al@416 37 pkgdb = root "/var/lib/tazpkg";
al@416 38 "ls " pkgdb " | tr '\n' ' '" | getline lsdir;
al@416 39 if (! index(lsdir, "packages.info"))
al@416 40 "tazpkg recharge --root=" root " >/dev/null 2>&1";
al@416 41 if (index(lsdir, "priority"))
al@416 42 "cat " pkgdb "/priority | tr '\n' ' '" | getline loop;
al@416 43 loop = loop "main";
al@416 44 if (index(lsdir, "undigest"))
al@416 45 "ls " pkgdb "/undigest | tr '\n' ' '" | getline undigest;
al@416 46 loop = loop " " undigest;
al@416 47 split(loop, repos, / +/);
al@416 48 ARGC = 1;
al@416 49 for (i in repos) {
al@416 50 if (repos[i] && ! arr[repos[i]]) {
al@416 51 arr[repos[i]] = 1;
al@416 52 if (repos[i] == "main")
al@416 53 pi = pkgdb "/packages.info";
al@416 54 else
al@416 55 pi = pkgdb "/undigest/" repos[i] "/packages.info";
al@416 56 if (!system("test -e "pi)) {
al@416 57 ARGV[ARGC] = pi;
al@416 58 ARGC ++;
al@416 59 }
al@416 60 }
al@416 61 }
al@416 62 ARGV[ARGC] = dir "/" flavor ".pkglist"; ARGC ++;
al@416 63 }
al@416 64
al@416 65 # Convert human-readable format to bytes
al@416 66 function h2b(h) {
al@416 67 if (h ~ "K") return h * K;
al@416 68 if (h ~ "M") return h * M;
al@416 69 if (h ~ "G") return h * G;
al@416 70 return h;
al@416 71 }
al@416 72
al@416 73 # Convert bytes to human-readable format
al@416 74 function b2h(b, p) {
al@416 75 if (b >= G) { b /= G; p = "G"; }
al@416 76 else if (b >= M) { b /= M; p = "M"; }
al@416 77 else { b /= K; p = "K"; }
al@416 78 if (b >= 100) return sprintf( "%d%s", b, p);
al@416 79 else return sprintf("%.1f%s", b, p);
al@416 80 }
al@416 81
al@416 82 # Mark package with its dependencies (to be processed later)
al@416 83 function mark_deps(pkg, localdepend, localdepends) {
al@416 84 if (sizes[pkg]) {
al@416 85 if (! pkgs[pkg]) {
al@416 86 pkgs[pkg] = sizes[pkg];
al@416 87
al@416 88 if (depends[pkg]) {
al@416 89 split(depends[pkg], localdepends, " ");
al@416 90 # Recursive call
al@416 91 for (localdepend in localdepends)
al@416 92 mark_deps(localdepends[localdepend]);
al@416 93 }
al@416 94 }
al@416 95 } else {
al@416 96 printf " %s\n", $1 >> errfile;
al@416 97 }
al@416 98 }
al@416 99
al@416 100 # Calculate unpacked and packed sizes of /boot
al@416 101 function calc(pkg, size_u, size_p) {
al@416 102 if (pkgs[pkg]) {
al@416 103 boot_u += h2b(size_u);
al@416 104 boot_p += h2b(size_p);
al@416 105 }
al@416 106 }
al@416 107
al@416 108 # main loop
al@416 109 {
al@416 110 if (FILENAME ~ ".info") {
al@416 111 # Step #1: fill arrays "sizes" and "depends"
al@416 112 if (! sizes[$1]) {
al@416 113 sizes[$1] = $7;
al@416 114 depends[$1] = $8;
al@416 115 }
al@416 116 } else {
al@416 117 # Step #2: mark packages and its dependencies
al@416 118 mark_deps($1);
al@416 119 }
al@416 120 }
al@416 121
al@416 122 END {
al@416 123 # Calculate sums for all marked packages and its deps
al@416 124 for (pkg in pkgs) {
al@416 125 num_pkgs ++;
al@416 126 split(pkgs[pkg], s, " ");
al@416 127 size_packed += h2b(s[1]);
al@416 128 size_unpacked += h2b(s[2]);
al@416 129 if (outfile) print pkg >> outfile;
al@416 130 }
al@416 131 # Add files placed in flavor.rootfs
al@416 132 size_packed += rootfs_p;
al@416 133 size_unpacked += rootfs_u;
al@416 134
al@416 135 # Check critical packages: "syslinux" and one of the packages containing "vmlinuz*"
al@416 136 if (! pkgs["syslinux"]) printf " * Syslinux\n" >> warnfile;
al@416 137 if (! pkgs["linux"] && ! pkgs["linux-without-modules"] && \
al@416 138 ! pkgs["linux64"] && ! pkgs["linux64-without-modules"] && \
al@416 139 ! pkgs["linux-libre"] && ! pkgs["linux-libre-without-modules"] && \
al@416 140 ! pkgs["linux-uml"]) printf " * Linux kernel\n" >> warnfile;
al@416 141
al@416 142 # Calculate unpacked and packed sizes of /boot
al@416 143 calc("syslinux", "156K", "120K" );
al@416 144 calc("gpxe", "196K", "188K" );
al@416 145 calc("ipxe", "316K", "312K" );
al@416 146 calc("memtest", "52K", "48K" );
al@416 147 calc("memtest-serial", "52K", "48K" );
al@416 148 calc("slitaz-configs-base", "36K", "28K" );
al@416 149 calc("linux", "2.8M", "2.8M" );
al@416 150 calc("linux-without-modules", "12.6M", "12.8M");
al@416 151 calc("linux64", "3.0M", "3.0M" );
al@416 152 calc("linux64-without-modules", "13.2M", "13.4M");
al@416 153 calc("linux-libre", "2.3M", "2.3M" );
al@416 154 calc("linux-libre-without-modules", "6.9M", "6.9M" );
al@416 155 calc("linux-uml", "3.0M", "1.1M" );
al@416 156
al@416 157 # /boot is moved away from rootfs
al@416 158 size_packed -= boot_p;
al@416 159 size_unpacked -= boot_u;
al@416 160
al@416 161 # Add rootcd payload and /boot content sizes
al@416 162 size_iso = size_packed + rootcd_u + boot_u;
al@416 163
al@416 164 printf "%s %s ", b2h(size_unpacked), b2h(size_packed);
al@416 165 printf "%s %d\n", b2h(size_iso), num_pkgs;
al@416 166 }