Auto-install qemu-guest-agent package during image customization
This commit is contained in:
25
customize.go
25
customize.go
@@ -28,6 +28,12 @@ func customizeImage(config *Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
if config.GuestAgent {
|
||||
if err := installGuestAgent(imagePath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Verifying customized image...")
|
||||
if err := verifyImage(imagePath); err != nil {
|
||||
return fmt.Errorf("customized image verification failed: %w", err)
|
||||
@@ -93,3 +99,22 @@ func injectSSHKey(imagePath, sshKeyPath string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func installGuestAgent(imagePath string) error {
|
||||
fmt.Println("Installing QEMU Guest Agent...")
|
||||
|
||||
cmd := exec.Command("virt-customize",
|
||||
"-a", imagePath,
|
||||
"--install", "qemu-guest-agent",
|
||||
"--run-command", "systemctl enable qemu-guest-agent",
|
||||
)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to install qemu-guest-agent: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("QEMU Guest Agent installed and enabled!")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user