Skip to content

Commit 95d97bf

Browse files
authored
feat: support TrueNAS Fangtooth (#56)
1 parent 39ccacb commit 95d97bf

File tree

3 files changed

+165
-92
lines changed

3 files changed

+165
-92
lines changed

cli/cmd/launch.go

+59
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import (
2727
"errors"
2828
"fmt"
2929
"os"
30+
"os/exec"
3031
"path/filepath"
3132
"strconv"
3233
"strings"
3334
"time"
3435

3536
"github.com/charmbracelet/glamour"
3637
"github.com/charmbracelet/log"
38+
"github.com/lxc/incus/v6/shared/api"
3739
"github.com/spf13/cobra"
3840

3941
"github.com/charmbracelet/huh"
@@ -94,11 +96,58 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
9496

9597
}
9698

99+
var isTrueNAS bool
100+
97101
var enableSSH bool
98102
var addGPU bool
99103
var profiles []string
100104
var validBridges []string
101105

106+
isTrueNAS, err = c.global.client.IsTrueNAS(c.Command().Context())
107+
if err != nil {
108+
log.Error("Error checking if TrueNAS:", "error", err)
109+
return err
110+
}
111+
if isTrueNAS {
112+
profiles, err := c.global.client.ProfileNames(c.Command().Context())
113+
if err != nil {
114+
log.Error("Error getting profiles:", "error", err)
115+
return err
116+
}
117+
found := false
118+
for _, p := range profiles {
119+
if p == "scriptcli-storage" {
120+
found = true
121+
log.Debug("Found TrueNAS profile", "profile", p)
122+
launchSettings.Profiles = append(launchSettings.Profiles, p)
123+
}
124+
}
125+
if !found {
126+
log.Info("No TrueNAS profiles found")
127+
p := api.ProfilesPost{
128+
Name: "scriptcli-storage",
129+
ProfilePut: api.ProfilePut{
130+
Config: map[string]string{},
131+
Description: "TrueNAS storage profile for script-cli",
132+
Devices: map[string]map[string]string{
133+
"root": {
134+
"path": "/",
135+
"pool": "default",
136+
"type": "disk",
137+
},
138+
},
139+
},
140+
}
141+
err := c.global.client.ProfileCreate(c.Command().Context(), p)
142+
if err != nil {
143+
log.Error("Error getting profiles:", "error", err)
144+
return err
145+
}
146+
launchSettings.Profiles = append(launchSettings.Profiles, "scriptcli-storage")
147+
148+
}
149+
}
150+
102151
proceed, err := launchForm(app, application.Description, accessible)
103152
if err != nil {
104153
return err
@@ -453,8 +502,10 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
453502
if disableSecureBoot(application.InstallMethods[launchSettings.InstallMethod].Resources.OS) {
454503
launchSettings.VMSecureBoot = false
455504
}
505+
456506
if launchSettings.VM {
457507
deviceOverrides["root"] = map[string]string{"size": launchSettings.VMRootDiskSize}
508+
458509
extraConfigs["limits.cpu"] = strconv.Itoa(launchSettings.CPU)
459510
extraConfigs["limits.memory"] = launchSettings.RAM
460511
if !launchSettings.VMSecureBoot {
@@ -560,6 +611,14 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
560611
out, _ := WelcomeMessage(*application, launchSettings)
561612
output, _ := glamour.Render(out, "dark")
562613
fmt.Print(output)
614+
if isTrueNAS {
615+
log.Info("Removing setup script from instance...")
616+
err = exec.Command("incus", "config", "set", launchSettings.Name, "environment.FUNCTIONS_FILE_PATH", "").Run()
617+
if err != nil {
618+
fmt.Println("Error removing functions file path:", err)
619+
return err
620+
}
621+
}
563622
} else {
564623
log.Error("Instance creation cancelled")
565624
}

cli/go.mod

+26-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
module github.com/bketelsen/IncusScripts/cli
22

3-
go 1.23.6
3+
go 1.23.7
4+
5+
toolchain go1.24.0
46

57
require (
6-
github.com/bketelsen/inclient v0.0.5
8+
github.com/bketelsen/inclient v0.2.0
79
github.com/charmbracelet/glamour v0.8.0
810
github.com/charmbracelet/huh v0.6.0
911
github.com/charmbracelet/huh/spinner v0.0.0-20250207133237-2eba4f31bf81
1012
github.com/charmbracelet/log v0.4.0
11-
github.com/lxc/incus/v6 v6.9.0
12-
github.com/spf13/cobra v1.8.1
13-
github.com/spf13/viper v1.19.0
13+
github.com/lxc/incus/v6 v6.11.0
14+
github.com/spf13/cobra v1.9.1
15+
github.com/spf13/viper v1.20.1
1416
)
1517

1618
require (
@@ -30,61 +32,57 @@ require (
3032
github.com/dustin/go-humanize v1.0.1 // indirect
3133
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
3234
github.com/fsnotify/fsnotify v1.8.0 // indirect
33-
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
35+
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
3436
github.com/go-logfmt/logfmt v0.6.0 // indirect
3537
github.com/go-logr/logr v1.4.2 // indirect
3638
github.com/go-logr/stdr v1.2.2 // indirect
39+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
3740
github.com/google/uuid v1.6.0 // indirect
3841
github.com/gorilla/css v1.0.1 // indirect
3942
github.com/gorilla/securecookie v1.1.2 // indirect
4043
github.com/gorilla/websocket v1.5.3 // indirect
41-
github.com/hashicorp/hcl v1.0.0 // indirect
4244
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4345
github.com/kr/fs v0.1.0 // indirect
4446
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
45-
github.com/magiconair/properties v1.8.9 // indirect
4647
github.com/mattn/go-isatty v0.0.20 // indirect
4748
github.com/mattn/go-localereader v0.0.1 // indirect
4849
github.com/mattn/go-runewidth v0.0.16 // indirect
4950
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
5051
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
51-
github.com/mitchellh/mapstructure v1.5.0 // indirect
5252
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
5353
github.com/muesli/cancelreader v0.2.2 // indirect
5454
github.com/muesli/reflow v0.3.0 // indirect
5555
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
5656
github.com/muhlemmer/gu v0.3.1 // indirect
5757
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
58-
github.com/pkg/sftp v1.13.7 // indirect
58+
github.com/pkg/sftp v1.13.9 // indirect
5959
github.com/rivo/uniseg v0.4.7 // indirect
6060
github.com/russross/blackfriday/v2 v2.1.0 // indirect
61-
github.com/sagikazarmark/locafero v0.7.0 // indirect
62-
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
61+
github.com/sagikazarmark/locafero v0.9.0 // indirect
6362
github.com/sirupsen/logrus v1.9.3 // indirect
6463
github.com/sourcegraph/conc v0.3.0 // indirect
65-
github.com/spf13/afero v1.12.0 // indirect
64+
github.com/spf13/afero v1.14.0 // indirect
6665
github.com/spf13/cast v1.7.1 // indirect
6766
github.com/spf13/pflag v1.0.6 // indirect
6867
github.com/subosito/gotenv v1.6.0 // indirect
6968
github.com/yuin/goldmark v1.7.8 // indirect
7069
github.com/yuin/goldmark-emoji v1.0.4 // indirect
71-
github.com/zitadel/logging v0.6.1 // indirect
72-
github.com/zitadel/oidc/v3 v3.34.1 // indirect
73-
github.com/zitadel/schema v1.3.0 // indirect
70+
github.com/zitadel/logging v0.6.2 // indirect
71+
github.com/zitadel/oidc/v3 v3.37.0 // indirect
72+
github.com/zitadel/schema v1.3.1 // indirect
7473
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
75-
go.opentelemetry.io/otel v1.34.0 // indirect
76-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
77-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
74+
go.opentelemetry.io/otel v1.35.0 // indirect
75+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
76+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
7877
go.uber.org/multierr v1.11.0 // indirect
79-
golang.org/x/crypto v0.33.0 // indirect
80-
golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect
81-
golang.org/x/net v0.34.0 // indirect
82-
golang.org/x/oauth2 v0.26.0 // indirect
83-
golang.org/x/sync v0.11.0 // indirect
84-
golang.org/x/sys v0.30.0 // indirect
85-
golang.org/x/term v0.29.0 // indirect
86-
golang.org/x/text v0.22.0 // indirect
87-
gopkg.in/ini.v1 v1.67.0 // indirect
78+
golang.org/x/crypto v0.36.0 // indirect
79+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
80+
golang.org/x/net v0.37.0 // indirect
81+
golang.org/x/oauth2 v0.28.0 // indirect
82+
golang.org/x/sync v0.12.0 // indirect
83+
golang.org/x/sys v0.32.0 // indirect
84+
golang.org/x/term v0.30.0 // indirect
85+
golang.org/x/text v0.23.0 // indirect
8886
gopkg.in/yaml.v2 v2.4.0 // indirect
8987
gopkg.in/yaml.v3 v3.0.1 // indirect
9088
)

0 commit comments

Comments
 (0)