added installer shell script and additional steps
This commit is contained in:
132
tui/steps/encryption.go
Normal file
132
tui/steps/encryption.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package steps
|
||||
|
||||
import (
|
||||
"miasma-installer/tui/styles"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type EncryptionModel struct {
|
||||
EnableEncryption bool
|
||||
Password string
|
||||
ConfirmPassword string
|
||||
passwordInput textinput.Model
|
||||
confirmInput textinput.Model
|
||||
focusIndex int
|
||||
Finished bool
|
||||
showInputs bool
|
||||
}
|
||||
|
||||
func NewEncryptionModel() EncryptionModel {
|
||||
pi := textinput.New()
|
||||
pi.Placeholder = "Enter encryption password"
|
||||
pi.EchoMode = textinput.EchoPassword
|
||||
pi.Focus()
|
||||
|
||||
ci := textinput.New()
|
||||
ci.Placeholder = "Confirm password"
|
||||
ci.EchoMode = textinput.EchoPassword
|
||||
|
||||
return EncryptionModel{
|
||||
EnableEncryption: true,
|
||||
passwordInput: pi,
|
||||
confirmInput: ci,
|
||||
showInputs: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (m EncryptionModel) Init() tea.Cmd {
|
||||
return textinput.Blink
|
||||
}
|
||||
|
||||
func (m EncryptionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if m.Finished {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "enter":
|
||||
if !m.showInputs {
|
||||
m.Finished = true
|
||||
return m, nil
|
||||
}
|
||||
|
||||
if m.focusIndex == 0 {
|
||||
m.focusIndex = 1
|
||||
m.passwordInput.Blur()
|
||||
return m, m.confirmInput.Focus()
|
||||
} else if m.focusIndex == 1 {
|
||||
if m.passwordInput.Value() == m.confirmInput.Value() && m.passwordInput.Value() != "" {
|
||||
m.Password = m.passwordInput.Value()
|
||||
m.Finished = true
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
case "y":
|
||||
if !m.showInputs {
|
||||
m.EnableEncryption = true
|
||||
m.showInputs = true
|
||||
return m, m.passwordInput.Focus()
|
||||
}
|
||||
|
||||
case "n":
|
||||
if !m.showInputs {
|
||||
m.EnableEncryption = false
|
||||
m.Finished = true
|
||||
return m, nil
|
||||
}
|
||||
|
||||
case "tab", "shift+tab":
|
||||
if m.showInputs {
|
||||
if m.focusIndex == 0 {
|
||||
m.focusIndex = 1
|
||||
m.passwordInput.Blur()
|
||||
return m, m.confirmInput.Focus()
|
||||
} else {
|
||||
m.focusIndex = 0
|
||||
m.confirmInput.Blur()
|
||||
return m, m.passwordInput.Focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
if m.showInputs {
|
||||
if m.focusIndex == 0 {
|
||||
m.passwordInput, cmd = m.passwordInput.Update(msg)
|
||||
} else {
|
||||
m.confirmInput, cmd = m.confirmInput.Update(msg)
|
||||
}
|
||||
}
|
||||
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m EncryptionModel) View() string {
|
||||
s := styles.TitleStyle.Render("Disk Encryption")
|
||||
s += "\n\n"
|
||||
|
||||
if !m.showInputs {
|
||||
s += "Enable LUKS2 disk encryption? (recommended)\n\n"
|
||||
s += styles.HelpStyle.Render("[y] Yes [n] No")
|
||||
} else {
|
||||
s += "Enter encryption password:\n\n"
|
||||
s += m.passwordInput.View() + "\n\n"
|
||||
s += m.confirmInput.View() + "\n\n"
|
||||
|
||||
if m.passwordInput.Value() != "" && m.confirmInput.Value() != "" {
|
||||
if m.passwordInput.Value() != m.confirmInput.Value() {
|
||||
s += styles.HelpStyle.Render("Passwords do not match\n")
|
||||
}
|
||||
}
|
||||
|
||||
s += styles.HelpStyle.Render("[Tab] Switch fields [Enter] Continue")
|
||||
}
|
||||
|
||||
return styles.MainStyle.Render(s)
|
||||
}
|
||||
Reference in New Issue
Block a user