|
|
|
|
@ -22,19 +22,20 @@ type StepCreateFloppy struct {
|
|
|
|
|
floppyPath string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
|
func (s *StepCreateFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
if len(s.Files) == 0 {
|
|
|
|
|
log.Println("No floppy files specified. Floppy disk will not be made.")
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui := state["ui"].(packer.Ui)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
ui.Say("Creating floppy disk...")
|
|
|
|
|
|
|
|
|
|
// Create a temporary file to be our floppy drive
|
|
|
|
|
floppyF, err := ioutil.TempFile("", "packer")
|
|
|
|
|
if err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating temporary file for floppy: %s", err)
|
|
|
|
|
state.Put("error",
|
|
|
|
|
fmt.Errorf("Error creating temporary file for floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
defer floppyF.Close()
|
|
|
|
|
@ -46,7 +47,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
|
|
|
|
|
// Set the size of the file to be a floppy sized
|
|
|
|
|
if err := floppyF.Truncate(1440 * 1024); err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -54,7 +55,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
log.Println("Initializing block device backed by temporary file")
|
|
|
|
|
device, err := fs.NewFileDisk(floppyF)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -66,7 +67,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
OEMName: "packer",
|
|
|
|
|
}
|
|
|
|
|
if fat.FormatSuperFloppy(device, formatConfig); err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -74,7 +75,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
log.Println("Initializing FAT filesystem on block device")
|
|
|
|
|
fatFs, err := fat.New(device)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -82,7 +83,7 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
log.Println("Reading the root directory from the filesystem")
|
|
|
|
|
rootDir, err := fatFs.RootDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error creating floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -90,18 +91,18 @@ func (s *StepCreateFloppy) Run(state map[string]interface{}) multistep.StepActio
|
|
|
|
|
for _, filename := range s.Files {
|
|
|
|
|
ui.Message(fmt.Sprintf("Copying: %s", filepath.Base(filename)))
|
|
|
|
|
if s.addSingleFile(rootDir, filename); err != nil {
|
|
|
|
|
state["error"] = fmt.Errorf("Error adding file to floppy: %s", err)
|
|
|
|
|
state.Put("error", fmt.Errorf("Error adding file to floppy: %s", err))
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the path to the floppy so it can be used later
|
|
|
|
|
state["floppy_path"] = s.floppyPath
|
|
|
|
|
state.Put("floppy_path", s.floppyPath)
|
|
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StepCreateFloppy) Cleanup(map[string]interface{}) {
|
|
|
|
|
func (s *StepCreateFloppy) Cleanup(multistep.StateBag) {
|
|
|
|
|
if s.floppyPath != "" {
|
|
|
|
|
log.Printf("Deleting floppy disk: %s", s.floppyPath)
|
|
|
|
|
os.Remove(s.floppyPath)
|
|
|
|
|
|