tazlito view modules/calc_sizes @ rev 480

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