Skip to content

Commit

Permalink
cherry-pick of #70: fix: install sudo if it's missing (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkeven authored Dec 13, 2024
1 parent af56b95 commit 3d96fb0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/common/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package common

import (
"bufio"
"bytetrade.io/web3os/installer/pkg/core/util"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -198,6 +199,12 @@ func (d *DefaultLoader) Load() (*kubekeyapiv1alpha2.Cluster, error) {

allInOne := &kubekeyapiv1alpha2.Cluster{}

if osType != Darwin && osType != Windows {
if err := installSUDOIfMissing(); err != nil {
return nil, err
}
}

if err := localSSH(osType); err != nil {
return nil, err
}
Expand Down Expand Up @@ -468,6 +475,18 @@ func currentUser(osType string) (*user.User, error) {
return u, nil
}

func installSUDOIfMissing() error {
p, _ := util.GetCommand("sudo")
if p != "" {
return nil
}
output, err := exec.Command("/bin/sh", "-c", "apt install -y sudo").CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to install the sudo command that's missing: %s", string(output))
}
return nil
}

func localSSH(osType string) error {
switch osType {
case Windows:
Expand Down

0 comments on commit 3d96fb0

Please sign in to comment.