Skip to content

Commit

Permalink
Merge pull request #835 from nanjj/genisoimage
Browse files Browse the repository at this point in the history
Clean up iso mount gen warnings
  • Loading branch information
stgraber authored Apr 9, 2024
2 parents bc48023 + 5851fd9 commit d99ba49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
25 changes: 19 additions & 6 deletions distrobuilder/main_repack-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -181,7 +182,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {

// Mount windows ISO
logger.Infof("Mounting Windows ISO to dir: %q", c.global.sourceDir)
err = shared.RunCommand(c.global.ctx, nil, nil, "mount", "-t", "udf", "-o", "loop", args[0], c.global.sourceDir)
err = shared.RunCommand(c.global.ctx, nil, nil, "mount", "-t", "udf", "-o", "loop,ro", args[0], c.global.sourceDir)
if err != nil {
return fmt.Errorf("Failed to mount %q at %q: %w", args[0], c.global.sourceDir, err)
}
Expand All @@ -204,7 +205,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {

// Mount driver ISO
logger.Infof("Mounting driver ISO to dir %q", driverPath)
err = shared.RunCommand(c.global.ctx, nil, nil, "mount", "-t", "iso9660", "-o", "loop", c.flagDrivers, driverPath)
err = shared.RunCommand(c.global.ctx, nil, nil, "mount", "-t", "iso9660", "-o", "loop,ro", c.flagDrivers, driverPath)
if err != nil {
return fmt.Errorf("Failed to mount %q at %q: %w", c.flagDrivers, driverPath, err)
}
Expand Down Expand Up @@ -361,13 +362,25 @@ func (c *cmdRepackWindows) run(cmd *cobra.Command, args []string, overlayDir str
}

version := strings.Split(stdout.String(), "\n")[0]

genArgs := []string{"--allow-limited-size"}
if strings.HasPrefix(version, "mkisofs") {
err = shared.RunCommand(c.global.ctx, nil, nil, "genisoimage", "-iso-level", "3", "-l", "-no-emul-boot", "-b", "efi/microsoft/boot/efisys.bin", "-o", args[1], overlayDir)
} else {
err = shared.RunCommand(c.global.ctx, nil, nil, "genisoimage", "--allow-limited-size", "-l", "-no-emul-boot", "-b", "efi/microsoft/boot/efisys.bin", "-o", args[1], overlayDir)
genArgs = []string{"-iso-level", "3"}
}

genArgs = append(genArgs, "-input-charset", "utf-8", "-l", "-no-emul-boot",
"-b", "efi/microsoft/boot/efisys.bin", "-o", args[1], overlayDir)
err = shared.RunCommand(context.WithValue(c.global.ctx, shared.ContextKeyStderr,
shared.WriteFunc(func(b []byte) (int, error) {
for i := range b {
if b[i] == '\n' {
b[i] = '\r'
}
}

return os.Stderr.Write(b)
})),
nil, nil, "genisoimage", genArgs...)

if err != nil {
return fmt.Errorf("Failed to generate ISO: %w", err)
}
Expand Down
14 changes: 13 additions & 1 deletion shared/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

const (
ContextKeyEnviron = ContextKey("environ")
ContextKeyStderr = ContextKey("stderr")
EnvRootUUID = "DISTROBUILDER_ROOT_UUID"
)

Expand All @@ -35,6 +36,12 @@ type Environment map[string]EnvVariable
// ContextKey type.
type ContextKey string

type WriteFunc func([]byte) (int, error)

func (w WriteFunc) Write(b []byte) (int, error) {
return w(b)
}

// Copy copies a file.
func Copy(src, dest string) error {
var err error
Expand Down Expand Up @@ -79,7 +86,12 @@ func RunCommand(ctx context.Context, stdin io.Reader, stdout io.Writer, name str
cmd.Stdout = os.Stdout
}

cmd.Stderr = os.Stderr
stderr, ok := ctx.Value(ContextKeyStderr).(io.Writer)
if ok && stderr != nil {
cmd.Stderr = stderr
} else {
cmd.Stderr = os.Stderr
}

return cmd.Run()
}
Expand Down

0 comments on commit d99ba49

Please sign in to comment.