Add and use a helper to run subprocess
In most cases e.g. we do want to show stdout/stderr, and it's handy to have a debug log when we're running a subprocess. While we're here, switch to just forking `cp` in the setup code. Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
parent
214fcda30e
commit
3c717fde11
1 changed files with 6 additions and 23 deletions
|
|
@ -2,9 +2,7 @@ package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/osbuild/bootc-image-builder/bib/internal/podmanutil"
|
"github.com/osbuild/bootc-image-builder/bib/internal/podmanutil"
|
||||||
|
|
@ -39,36 +37,21 @@ func EnsureEnvironment() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !utils.IsMountpoint(runTmp) {
|
if !utils.IsMountpoint(runTmp) {
|
||||||
if err := exec.Command("mount", "-t", "tmpfs", "tmpfs", runTmp).Run(); err != nil {
|
if err := utils.RunCmdSync("mount", "-t", "tmpfs", "tmpfs", runTmp); err != nil {
|
||||||
return fmt.Errorf("failed to mount tmpfs to %s: %w", runTmp, err)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
src, err := os.Open("/usr/bin/osbuild")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer src.Close()
|
|
||||||
destPath := filepath.Join(runTmp, "osbuild")
|
destPath := filepath.Join(runTmp, "osbuild")
|
||||||
dst, err := os.Create(destPath)
|
if err := utils.RunCmdSync("cp", "-p", "/usr/bin/osbuild", destPath); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer dst.Close()
|
if err := utils.RunCmdSync("chcon", installType, destPath); err != nil {
|
||||||
if _, err := io.Copy(dst, src); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := dst.Chmod(0o755); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dst.Close()
|
|
||||||
if err := exec.Command("chcon", installType, destPath).Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to chcon: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a bind mount into our target location; we can't copy it because
|
// Create a bind mount into our target location; we can't copy it because
|
||||||
// again we have to perserve the SELinux label.
|
// again we have to perserve the SELinux label.
|
||||||
if err := exec.Command("mount", "--bind", destPath, osbuildPath).Run(); err != nil {
|
if err := utils.RunCmdSync("mount", "--bind", destPath, osbuildPath); err != nil {
|
||||||
return fmt.Errorf("failed to bind mount to %s: %w", osbuildPath, err)
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue