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