@@ -11,7 +11,22 @@ formatter.timeStyle = .long
11
11
12
12
let stdout = FileHandle . standardOutput
13
13
14
- stdout. print ( " +zfs-pool-importer " )
14
+ let command = ProcessInfo . processInfo. arguments. first? . split ( separator: " / " ) . last ?? " zfs_pool_importer "
15
+ let arguments = ProcessInfo . processInfo. arguments. dropFirst ( )
16
+ let sbin = arguments. first. flatMap {
17
+ arg in // elementary (and inflexible) parsing of a single possible command line option
18
+ var dir = ObjCBool ( false )
19
+ guard arg. hasPrefix ( " --sbindir " ) ,
20
+ let rawPath = arg. split ( separator: " = " ) . last. map ( String . init) ,
21
+ FileManager . default. fileExists ( atPath: rawPath, isDirectory: & dir) ,
22
+ dir. boolValue == true
23
+ else { return nil }
24
+ return URL ( fileURLWithPath: rawPath, isDirectory: true ) . path. appending ( " / " )
25
+ } ?? " /usr/local/zfs/bin/ "
26
+
27
+ let zpool = sbin + " zpool "
28
+
29
+ stdout. print ( " + \( command) " )
15
30
stdout. print ( formatter. string ( from: Date ( ) ) )
16
31
17
32
formatter. dateStyle = . none
@@ -42,8 +57,7 @@ stdout.print("\(invariantDisksCookie) was\(found ? "" : "n't") found in \(String
42
57
Thread . sleep ( forTimeInterval: 10 )
43
58
stdout. print ( " \( formatter. string ( from: Date ( ) ) ) : running zpool import -a " )
44
59
45
- let code = launch ( command: " /usr/local/zfs/bin/zpool " ,
46
- arguments: [ " import " , " -a " , " -d " , " /var/run/disk/by-id " ] )
60
+ let code = launch ( command: zpool, arguments: [ " import " , " -a " , " -d " , " /var/run/disk/by-id " ] )
47
61
48
62
stdout. print ( " \( formatter. string ( from: Date ( ) ) ) : zpool import returned with exit code \( code) " )
49
63
@@ -62,6 +76,6 @@ catch {
62
76
formatter. dateStyle = . medium
63
77
formatter. timeStyle = . long
64
78
stdout. print ( formatter. string ( from: Date ( ) ) )
65
- stdout. print ( " -zfs-pool-importer " )
79
+ stdout. print ( " - \( command ) " )
66
80
67
81
exit ( code)
0 commit comments