add support for using xorriso to create the cdrom iso (#9919)
This commit is contained in:
parent
bcd3c33e49
commit
53331644a6
|
@ -57,12 +57,13 @@ type CDConfig struct {
|
||||||
// directory itself or its contents will be at the CD root.
|
// directory itself or its contents will be at the CD root.
|
||||||
//
|
//
|
||||||
// Use of this option assumes that you have a command line tool installed
|
// Use of this option assumes that you have a command line tool installed
|
||||||
// that can handle the iso creation. If you are running Packer from an OSX host,
|
// that can handle the iso creation. Packer will use one of the following
|
||||||
// the required tool is hdiutil which comes preinstalled.
|
// tools:
|
||||||
// On linux hosts, you need to have mkisofs.
|
//
|
||||||
// On Windows, you must have oscdimg.exe. oscdimg.exe is part of the
|
// * xorriso
|
||||||
// Windows ADK tooks, downloadable from
|
// * mkisofs
|
||||||
// https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install#winADK
|
// * hdiutil (normally found in macOS)
|
||||||
|
// * oscdimg (normally found in Windows as part of the Windows ADK)
|
||||||
CDFiles []string `mapstructure:"cd_files"`
|
CDFiles []string `mapstructure:"cd_files"`
|
||||||
CDLabel string `mapstructure:"cd_label"`
|
CDLabel string `mapstructure:"cd_label"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/helper/builder/localexec"
|
"github.com/hashicorp/packer/helper/builder/localexec"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
@ -80,7 +80,12 @@ func (s *StepCreateCD) Run(ctx context.Context, state multistep.StateBag) multis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := retrieveCommandForOS(s.Label, rootFolder, CDPath)
|
cmd, err := retrieveCDISOCreationCommand(s.Label, rootFolder, CDPath)
|
||||||
|
if err != nil {
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
err = localexec.RunAndStream(cmd, ui, []string{})
|
err = localexec.RunAndStream(cmd, ui, []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -107,25 +112,75 @@ func (s *StepCreateCD) Cleanup(multistep.StateBag) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveCommandForOS(label string, source string, dest string) *exec.Cmd {
|
type cdISOCreationCommand struct {
|
||||||
switch runtime.GOOS {
|
Name string
|
||||||
case "windows":
|
Command func(path string, label string, source string, dest string) *exec.Cmd
|
||||||
cmd := exec.Command("oscdimg")
|
}
|
||||||
args := []string{"-j1", "-o", "-m", "-l" + label, source, dest}
|
|
||||||
cmd.Args = append(cmd.Args, args...)
|
var supportedCDISOCreationCommands []cdISOCreationCommand = []cdISOCreationCommand{
|
||||||
return cmd
|
{
|
||||||
case "darwin":
|
"xorriso", func(path string, label string, source string, dest string) *exec.Cmd {
|
||||||
cmd := exec.Command("hdiutil")
|
return exec.Command(
|
||||||
args := []string{"makehybrid", "-o", dest, "-hfs",
|
path,
|
||||||
"-joliet", "-iso", "-default-volume-name", label, source}
|
"-as", "genisoimage",
|
||||||
cmd.Args = append(cmd.Args, args...)
|
"-rock",
|
||||||
return cmd
|
"-joliet",
|
||||||
default:
|
"-volid", label,
|
||||||
cmd := exec.Command("mkisofs")
|
"-output", dest,
|
||||||
args := []string{"-joliet", "-volid", label, "-o", dest, source}
|
source)
|
||||||
cmd.Args = append(cmd.Args, args...)
|
},
|
||||||
return cmd
|
},
|
||||||
|
{
|
||||||
|
"mkisofs", func(path string, label string, source string, dest string) *exec.Cmd {
|
||||||
|
return exec.Command(
|
||||||
|
path,
|
||||||
|
"-joliet",
|
||||||
|
"-volid", label,
|
||||||
|
"-o", dest,
|
||||||
|
source)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hdiutil", func(path string, label string, source string, dest string) *exec.Cmd {
|
||||||
|
return exec.Command(
|
||||||
|
path,
|
||||||
|
"-o", dest,
|
||||||
|
"-hfs",
|
||||||
|
"-joliet",
|
||||||
|
"-iso",
|
||||||
|
"-default-volume-name", label,
|
||||||
|
source)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"oscdimg", func(path string, label string, source string, dest string) *exec.Cmd {
|
||||||
|
return exec.Command(
|
||||||
|
path,
|
||||||
|
"-j1",
|
||||||
|
"-o",
|
||||||
|
"-m",
|
||||||
|
"-l"+label,
|
||||||
|
source,
|
||||||
|
dest)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func retrieveCDISOCreationCommand(label string, source string, dest string) (*exec.Cmd, error) {
|
||||||
|
for _, c := range supportedCDISOCreationCommands {
|
||||||
|
path, err := exec.LookPath(c.Name)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return c.Command(path, label, source, dest), nil
|
||||||
}
|
}
|
||||||
|
var commands = make([]string, 0, len(supportedCDISOCreationCommands))
|
||||||
|
for _, c := range supportedCDISOCreationCommands {
|
||||||
|
commands = append(commands, c.Name)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"could not find a supported CD ISO creation command (the supported commands are: %s)",
|
||||||
|
strings.Join(commands, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepCreateCD) AddFile(dst, src string) error {
|
func (s *StepCreateCD) AddFile(dst, src string) error {
|
||||||
|
|
|
@ -36,11 +36,12 @@
|
||||||
directory itself or its contents will be at the CD root.
|
directory itself or its contents will be at the CD root.
|
||||||
|
|
||||||
Use of this option assumes that you have a command line tool installed
|
Use of this option assumes that you have a command line tool installed
|
||||||
that can handle the iso creation. If you are running Packer from an OSX host,
|
that can handle the iso creation. Packer will use one of the following
|
||||||
the required tool is hdiutil which comes preinstalled.
|
tools:
|
||||||
On linux hosts, you need to have mkisofs.
|
|
||||||
On Windows, you must have oscdimg.exe. oscdimg.exe is part of the
|
* xorriso
|
||||||
Windows ADK tooks, downloadable from
|
* mkisofs
|
||||||
https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install#winADK
|
* hdiutil (normally found in macOS)
|
||||||
|
* oscdimg (normally found in Windows as part of the Windows ADK)
|
||||||
|
|
||||||
- `cd_label` (string) - CD Label
|
- `cd_label` (string) - CD Label
|
||||||
|
|
Loading…
Reference in New Issue