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