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

Commit 22fb6f7

Browse files
committed
feat: vm option
1 parent add1f3d commit 22fb6f7

24 files changed

Lines changed: 113 additions & 37 deletions

cli/cmd/launch.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"os"
3030
"path/filepath"
3131
"strconv"
32+
"time"
3233

3334
"github.com/charmbracelet/glamour"
3435
"github.com/charmbracelet/log"
@@ -141,8 +142,29 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
141142
launchSettings.InstallMethod = installMethod
142143

143144
}
144-
// choose ssh options
145+
146+
// select install method
145147
form := huh.NewForm(
148+
149+
huh.NewGroup(
150+
huh.NewConfirm().
151+
Title("Launch As VM?").
152+
Value(&launchSettings.VM).
153+
Affirmative("Yes").
154+
Negative("No"),
155+
),
156+
).WithAccessible(accessible)
157+
158+
err = form.Run()
159+
if err != nil {
160+
fmt.Println("form error:", err)
161+
os.Exit(1)
162+
}
163+
launchSettings.Image = "images:" + application.InstallMethods[installMethod].Resources.Image()
164+
launchSettings.InstallMethod = installMethod
165+
166+
// choose ssh options
167+
form = huh.NewForm(
146168
huh.NewGroup(
147169
huh.NewConfirm().
148170
Title("Pass through GPU?").
@@ -354,7 +376,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
354376

355377
createInstance := func() {
356378
// create the instance
357-
err := c.global.client.Launch(launchSettings.Image, launchSettings.Name, launchSettings.Profiles, extraConfigs, false, false)
379+
err := c.global.client.Launch(launchSettings.Image, launchSettings.Name, launchSettings.Profiles, extraConfigs, launchSettings.VM, false)
358380
if err != nil {
359381
fmt.Println("Error creating instance:", err)
360382
os.Exit(1)
@@ -380,6 +402,39 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
380402
fmt.Println("Error starting instance:", err)
381403
os.Exit(1)
382404
}
405+
if launchSettings.VM {
406+
log.Info("VM started, waiting for agent...")
407+
const maxAttempts = 5
408+
const waitTime = 2
409+
getState := func() (bool, error) {
410+
time.Sleep(waitTime * time.Second)
411+
state, err := c.global.client.InstanceState(context.Background(), launchSettings.Name)
412+
if err != nil {
413+
fmt.Println("Error waiting for vm agent:", err)
414+
return false, err
415+
}
416+
if state.State.Processes > 2 {
417+
return true, nil
418+
}
419+
return false, nil
420+
}
421+
attempts := 0
422+
for {
423+
success, err := getState()
424+
if err != nil {
425+
fmt.Println("Error waiting for vm agent:", err)
426+
os.Exit(1)
427+
}
428+
if success {
429+
break
430+
}
431+
attempts++
432+
if attempts >= maxAttempts {
433+
fmt.Println("Error waiting for vm agent: max attempts reached")
434+
os.Exit(1)
435+
}
436+
}
437+
}
383438
}
384439

385440
if doit {

cli/cmd/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type LaunchSettings struct {
7979
Profiles []string `json:"profiles,omitempty"`
8080
CPU int `json:"cpu,omitempty"`
8181
RAM int `json:"ram,omitempty"`
82+
VM bool `json:"vm,omitempty"`
83+
VMRootDiskSize string `json:"vm_root_disk_size,omitempty"`
8284
RootPassword string `json:"root_password,omitempty"`
8385
EnableSSH bool `json:"enable_ssh,omitempty"`
8486
SSHRootPassword bool `json:"ssh_root_password,omitempty"`

cli/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/bketelsen/IncusScripts/cli
33
go 1.23.6
44

55
require (
6-
github.com/bketelsen/inclient v0.0.2
6+
github.com/bketelsen/inclient v0.0.3
77
github.com/charmbracelet/glamour v0.8.0
88
github.com/charmbracelet/huh v0.6.0
99
github.com/charmbracelet/huh/spinner v0.0.0-20250203114958-f07ae1af69ae

cli/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
1414
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
1515
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
1616
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
17-
github.com/bketelsen/inclient v0.0.2 h1:VW7tqG95kEy2A3wln8Hm+IU927dIWrJFvW1mwT/RSG4=
18-
github.com/bketelsen/inclient v0.0.2/go.mod h1:0FTjkxQa3bWiplU90NBTEjGMoKdsfZBWLPtPoE+GaxI=
17+
github.com/bketelsen/inclient v0.0.3 h1:aO0EqEJTvZ1JaF9nXWnuTGMEVZhEdIXbNJTzkEibPfg=
18+
github.com/bketelsen/inclient v0.0.3/go.mod h1:0FTjkxQa3bWiplU90NBTEjGMoKdsfZBWLPtPoE+GaxI=
1919
github.com/bmatcuk/doublestar/v4 v4.8.0 h1:DSXtrypQddoug1459viM9X9D3dp1Z7993fw36I2kNcQ=
2020
github.com/bmatcuk/doublestar/v4 v4.8.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
2121
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=

install/adventurelog-install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,5 @@ msg_info "Cleaning up"
172172
rm -rf /opt/v${RELEASE}.zip
173173
$STD apt-get -y autoremove
174174
$STD apt-get -y autoclean
175-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
175+
msg_ok "Cleaned"
176+
# Modified by surgeon https://github.com/bketelsen/surgeon

install/aria2-install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ msg_info "Cleaning up"
9595
rm AriaNg-*-AllInOne.zip
9696
$STD apt-get -y autoremove
9797
$STD apt-get -y autoclean
98-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
98+
msg_ok "Cleaned"
99+
# Modified by surgeon https://github.com/bketelsen/surgeon

install/bazarr-install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ msg_info "Cleaning up"
6565
rm -rf bazarr.zip
6666
$STD apt-get -y autoremove
6767
$STD apt-get -y autoclean
68-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
68+
msg_ok "Cleaned"
69+
# Modified by surgeon https://github.com/bketelsen/surgeon

install/beszel-install.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ $STD apt-get install -y \
2222
msg_ok "Installed Dependencies"
2323

2424
msg_info "Installing Beszel"
25-
mkdir -p /opt/beszel
26-
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel_$(uname -s)_$(uname -m | sed -e 's/x86_64/amd64/' -e 's/armv6l/arm/' -e 's/armv7l/arm/' -e 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel | tee /opt/beszel/beszel >/dev/null
25+
mkdir -p /opt/beszel
26+
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel_$(uname -s)_$(uname -m | sed -e 's/x86_64/amd64/' -e 's/armv6l/arm/' -e 's/armv7l/arm/' -e 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel | tee /opt/beszel/beszel >/dev/null
2727
chmod +x /opt/beszel/beszel
2828
msg_ok "Installed Beszel"
2929

@@ -51,4 +51,5 @@ customize
5151
msg_info "Cleaning up"
5252
$STD apt-get -y autoremove
5353
$STD apt-get -y autoclean
54-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
54+
msg_ok "Cleaned"
55+
# Modified by surgeon https://github.com/bketelsen/surgeon

install/crafty-controller-install.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $STD apt-get install -y \
2424
apt-transport-https \
2525
coreutils \
2626
software-properties-common \
27-
openjdk-17-jdk
27+
openjdk-17-jdk
2828
wget -q https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
2929
$STD sudo dpkg -i jdk-21_linux-x64_bin.deb
3030
rm -f jdk-21_linux-x64_bin.deb
@@ -94,4 +94,5 @@ msg_info "Cleaning up"
9494
rm -rf /opt/crafty-4-v${RELEASE}.zip
9595
$STD apt-get -y autoremove
9696
$STD apt-get -y autoclean
97-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
97+
msg_ok "Cleaned"
98+
# Modified by surgeon https://github.com/bketelsen/surgeon

install/debian-install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ customize
2525
msg_info "Cleaning up"
2626
$STD apt-get -y autoremove
2727
$STD apt-get -y autoclean
28-
msg_ok "Cleaned"# Modified by surgeon https://github.com/bketelsen/surgeon
28+
msg_ok "Cleaned"
29+
# Modified by surgeon https://github.com/bketelsen/surgeon

0 commit comments

Comments
 (0)