-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzfs-parse-cmdline
45 lines (40 loc) · 1.23 KB
/
zfs-parse-cmdline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/awk -f
# Returns a set of KEY=val assignments
# - ZFS_ROOT_MODE: "dataset", "import", "import_all", "none"
# - all: import all pools, use the first one with a bootfs property
# - pool: import a specific pool, use bootfs to determine the dataset
# - dataset: import a specific pool, use a specific dataset
# - none: not using zfs for root
# - ZFS_ROOT_POOL: contains the root pool name (used with mode "dataset" and "pool")
# - ZFS_ROOT_DATASET: contains the root dataset name (used with mode "dataset")
$0 ~ /^root=/ {
root = substr($0, 6)
}
END {
if (root == "zfs") {
# import all pools
zfs_root_mode = "all"
} else if (match(root, /^zfs[:=][^\/]+$/)) {
root = substr(root, 5)
# import a specific pool
zfs_root_mode = "pool"
zfs_root_pool = root
} else if (match(root, /^zfs[:=][^\/]+(\/[^\/]+)+$/)) {
root = substr(root, 5)
# use a particular dataset
zfs_root_mode = "dataset"
zfs_root_dataset = root
split(root, items, "/")
zfs_root_pool = items[1]
} else {
zfs_root_mode = "none"
}
printf "ZFS_ROOT_MODE=%s\n", zfs_root_mode
if (zfs_root_pool) {
printf "ZFS_ROOT_POOL=%s\n", zfs_root_pool
}
if (zfs_root_dataset) {
printf "ZFS_ROOT_DATASET=%s\n", zfs_root_dataset
}
}
# vim: ft=awk ts=8 noet: