-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmetadata.go
More file actions
52 lines (41 loc) · 1.17 KB
/
metadata.go
File metadata and controls
52 lines (41 loc) · 1.17 KB
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
46
47
48
49
50
51
52
package main
import (
"os"
"github.com/rn/iso9660wrap"
"github.com/spf13/cobra"
)
// WriteMetadataISO writes a metadata ISO file in a format usable by pkg/metadata
func WriteMetadataISO(path string, content []byte) error {
outfh, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer func() { _ = outfh.Close() }()
return iso9660wrap.WriteBuffer(outfh, content, "config")
}
func metadataCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "create an ISO with metadata",
Long: `Create an ISO file with metadata in it.
Provided metadata will be written to '/config' in the ISO.
This is compatible with the linuxkit/metadata package.`,
Args: cobra.ExactArgs(2),
Example: "linuxkit metadata create file.iso \"metadata\"",
RunE: func(cmd *cobra.Command, args []string) error {
isoImage := args[0]
metadata := args[1]
return WriteMetadataISO(isoImage, []byte(metadata))
},
}
return cmd
}
func metadataCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "metadata",
Short: "manage ISO metadata",
Long: `Manage ISO metadata.`,
}
cmd.AddCommand(metadataCreateCmd())
return cmd
}