Skip to content

Commit

Permalink
Run the user in initramfs if we dont need network (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka authored May 26, 2023
1 parent 3c484d9 commit 8e456ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions internal/agent/interactive_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ func InteractiveInstall(debug, spawnShell bool) error {
if err != nil {
return err
}


// Cleanup the users if we selected the default values as they are not valid users
if users == "github:someuser,github:someuser2" {
users = ""
}
sshUsers := strings.Split(users, ",")

// Prompt the user by prompts defined by the provider
Expand Down Expand Up @@ -231,6 +235,8 @@ func InteractiveInstall(debug, spawnShell bool) error {

usersToSet := map[string]schema.User{}

stage := config.NetworkStage.String()

if userName != "" {
user := schema.User{
Name: userName,
Expand All @@ -239,13 +245,18 @@ func InteractiveInstall(debug, spawnShell bool) error {
SSHAuthorizedKeys: sshUsers,
}

// If we got no ssh keys, we don't need network, do the user as soon as possible
if len(user.SSHAuthorizedKeys) == 0 {
stage = config.InitramfsStage.String()
}

usersToSet = map[string]schema.User{
userName: user,
}
}

cloudConfig := schema.YipConfig{Name: "Config generated by the installer",
Stages: map[string][]schema.Stage{config.NetworkStage.String(): {
Stages: map[string][]schema.Stage{stage: {
{
Users: usersToSet,
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ func Scan(opts ...collector.Option) (c *Config, err error) {
type Stage string

const (
NetworkStage Stage = "network"
NetworkStage Stage = "network"
InitramfsStage Stage = "initramfs"
)

func (n Stage) String() string {
Expand Down

0 comments on commit 8e456ec

Please sign in to comment.