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