xref: /freebsd/release/scripts/mtree-to-plist.awk (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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		if ($1 ~ /^\/boot\/dtb\//) {
27			tags="package=dtb"
28		} else {
29			tags="package=kernel"
30			if (_kernconf != "") {
31				tags=tags""_kernconf
32			}
33		}
34	}
35	if (length(tags) == 0)
36		next
37	if (tags ~ /package=/) {
38		ext = pkgname = pkgend = ""
39		split(tags, a, ",");
40		for (i in a) {
41			if (a[i] ~ /^package=/) {
42				pkgname=a[i]
43				if ($1 ~ /^\/boot\//) {
44					if (kernel != "" && $1 ~ /^\/boot\/dtb\//)
45						pkgname="dtb"
46					else
47						pkgname="bootloader"
48				}
49				gsub(/package=/, "", pkgname)
50			} else if (a[i] == "config") {
51				type="config"
52			} else if (a[i] == "development" || a[i] == "debug" || a[i] == "docs") {
53				pkgend=a[i]
54			} else {
55				if (ext != "")
56					ext=ext"-"a[i]
57				else
58					ext=a[i]
59			}
60		}
61		if (ext != "") {
62			pkgname=pkgname"-"ext
63		}
64		if (pkgend != "") {
65			if (pkgend == "docs") {
66				pkgname=pkgend
67			} else {
68				pkgname=pkgname"-"pkgend
69			}
70		}
71	} else {
72		print "No packages specified in line: $0"
73		next
74	}
75	if (kernel != "" && pkgname != "dtb") {
76		output="kernel"
77		if (_kernconf != "") {
78			output=output"."_kernconf
79		}
80		if ($1 ~ /^\/usr\/lib\/debug\/boot/) {
81			output=output"-dbg.plist"
82		} else {
83			output=output".plist"
84		}
85	} else {
86		output=pkgname".plist"
87	}
88
89	print "@"type"("uname","gname","mode","flags") " $1 > output
90}
91