Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 22e0c22

Browse files
authored
fix(launch): fixes launch problems on TrueNAS (#65)
changes script execution on TrueNAS hosts
1 parent 670ea70 commit 22e0c22

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

cli/cmd/launch.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
143143
log.Error("Error getting profiles:", "error", err)
144144
return err
145145
}
146+
log.Info("Created Incus profile", "profile", p.Name)
146147
launchSettings.Profiles = append(launchSettings.Profiles, "scriptcli-storage")
147148

148149
}
@@ -495,6 +496,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
495496

496497
// Cacher
497498
extraConfigs["environment.CACHER"] = "no"
499+
extraConfigs["environment.DEBIAN_FRONTEND"] = "noninteractive"
498500

499501
// Disable ipv6
500502
extraConfigs["environment.DISABLEIPV6"] = "yes" // todo: make this a form option
@@ -528,8 +530,9 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
528530
}
529531
}
530532
// Function script
531-
extraConfigs["environment.FUNCTIONS_FILE_PATH"] = string(funcScript)
533+
//extraConfigs["environment.FUNCTIONS_FILE_PATH"] = string(funcScript)
532534

535+
extraConfigs["environment.FUNCTIONS_FILE_PATH"] = "/install.func"
533536
createInstance := func() {
534537
// create the instance
535538
err := c.global.client.Launch(launchSettings.Image, launchSettings.Name, launchSettings.Profiles, extraConfigs, deviceOverrides, launchSettings.Network, launchSettings.VM, false)
@@ -600,8 +603,48 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
600603
fmt.Println("Error downloading install script:", err)
601604
os.Exit(1)
602605
}
606+
607+
dir, err := os.MkdirTemp("", "scriptcli-installfunc")
608+
if err != nil {
609+
fmt.Println("Error creating temp dir:", err)
610+
os.Exit(1)
611+
}
612+
defer os.RemoveAll(dir)
613+
// write the install script to a file
614+
modifiedScript := []byte("#!/bin/env bash\n")
615+
modifiedScript = append(modifiedScript, funcScript...)
616+
modifiedScript = append(modifiedScript, []byte("\n")...)
617+
err = os.WriteFile(filepath.Join(dir, "install.func"), modifiedScript, 0644)
618+
if err != nil {
619+
fmt.Println("Error writing install script:", err)
620+
os.Exit(1)
621+
}
622+
// push the install script to the instance
623+
log.Info("Adding installation functions to instance...")
624+
err = exec.Command("incus", "file", "push", filepath.Join(dir, "install.func"), launchSettings.Name+"/install.func").Run()
625+
if err != nil {
626+
fmt.Println("Error pushing functions file:", err)
627+
return err
628+
}
629+
// push the install script to the instance
630+
log.Info("Making installation functions executable...")
631+
err = exec.Command("incus", "exec", launchSettings.Name, "--", "chmod", "+x", "/install.func").Run()
632+
if err != nil {
633+
fmt.Println("Error making functions file executable:", err)
634+
os.Exit(0)
635+
}
636+
log.Info("Running installer...")
637+
638+
insFunc := string(installFunc)
639+
insFunc = strings.ReplaceAll(insFunc, "/dev/stdin <<<", "")
603640
// run installer
604-
err = c.global.client.ExecInteractive([]string{launchSettings.Name, "bash", "-c", string(installFunc)}, []string{}, 0, 0, "", os.Stdin, os.Stdout, os.Stderr)
641+
command := exec.Command("incus", "exec", launchSettings.Name, "--", "bash", "-c", string(insFunc))
642+
command.Stdin = os.Stdin
643+
command.Stdout = os.Stdout
644+
command.Stderr = os.Stderr
645+
command.Run()
646+
647+
// err = c.global.client.ExecInteractive([]string{launchSettings.Name, "bash", "-c", string(insFunc)}, []string{}, 0, 0, "", os.Stdin, os.Stdout, os.Stderr)
605648
if err != nil {
606649
fmt.Println("Error executing installer:", err)
607650
os.Exit(1)
@@ -619,6 +662,12 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
619662
return err
620663
}
621664
}
665+
log.Info("Removing setup script from instance...")
666+
err = exec.Command("incus", "config", "set", launchSettings.Name, "environment.DEBIAN_FRONTEND", "").Run()
667+
if err != nil {
668+
fmt.Println("Error removing functions file path:", err)
669+
return err
670+
}
622671
} else {
623672
log.Error("Instance creation cancelled")
624673
}

0 commit comments

Comments
 (0)