xref: /freebsd/release/scripts/mtree-to-plist.awk (revision 6966ac055c3b7a39266fb982493330df7a097997)
1#!/usr/bin/awk
2/^[^#]/ {
3	gsub(/^\./,"", $1)
4	uname = gname = mode = flags = tags = type = ""
5	for (i=2; i<=NF; i++) {
6		if ($i ~ /^uname=/) {
7			uname=$i
8			gsub(/uname=/, "", uname)
9		} else if ($i ~ /^gname=/) {
10			gname=$i
11			gsub(/gname=/, "", gname)
12		} else if ($i ~ /^mode=/) {
13			mode=$i
14			gsub(/mode=/,"", mode)
15		} else if ($i ~ /^flags=/) {
16			flags=$i
17			gsub(/flags=/, "", flags)
18		} else if ($i ~ /^tags=/) {
19			tags=$i
20			gsub(/tags=/, "", tags)
21		} else if ($i ~ /^type=dir/) {
22			type="dir"
23		}
24	}
25	if (kernel != "") {
26		tags="package=kernel"
27		if (_kernconf != "") {
28			tags=tags""_kernconf
29		}
30	}
31	if ($1 ~ /^\/boot\//) {
32		tags="package=bootloader"
33	}
34	if (length(tags) == 0)
35		next
36	if (tags ~ /package=/) {
37		ext = pkgname = pkgend = ""
38		split(tags, a, ",");
39		for (i in a) {
40			if (a[i] ~ /^package=/) {
41				pkgname=a[i]
42				gsub(/package=/, "", pkgname)
43			} else if (a[i] == "config") {
44				type="config"
45			} else if (a[i] == "development" || a[i] == "profile" || a[i] == "debug" || a[i] == "docs") {
46				pkgend=a[i]
47			} else {
48				if (ext != "")
49					ext=ext"-"a[i]
50				else
51					ext=a[i]
52			}
53		}
54		if (ext != "") {
55			pkgname=pkgname"-"ext
56		}
57		if (pkgend != "") {
58			if (pkgend == "docs") {
59				pkgname=pkgend
60			} else {
61				pkgname=pkgname"-"pkgend
62			}
63		}
64	} else {
65		print "No packages specified in line: $0"
66		next
67	}
68	if (kernel != "") {
69		output="kernel"
70		if (_kernconf != "") {
71			output=output"."_kernconf
72		}
73		if ($1 ~ /^\/usr\/lib\/debug\/boot/) {
74			output=output"-debug.plist"
75		} else {
76			output=output".plist"
77		}
78	} else {
79		output=pkgname".plist"
80	}
81
82	print "@"type"("uname","gname","mode","flags") " $1 > output
83}
84