tazlito annotate modules/calc_sizes @ rev 481

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