Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swctl: post install steps for docker #150

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cmd/swctl/app/cmd_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ func InstallDocker(cli Cli, dockerVersion string) error {
color.Fprintln(cli.Out(), out)

}
errorGroup := postInstall(cli)
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
if len(errorGroup) != 0 {
for _, err := range errorGroup {
color.Fprintln(cli.Out(), err)
}
} else {
color.Fprintln(cli.Out(), "Please log out and then log back in for the group membership changes to take effect or enter command \"newgrp docker\"")
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}
Expand Down Expand Up @@ -747,3 +755,42 @@ func isUserRoot() (bool, error) {
return true, nil

}
func postInstall(cli Cli) []error {
var errorGroup []error
sudoName, err := logname(cli)
fmt.Fprintln(cli.Out(), sudoName)
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
// handling case when linux has no login name (e.g. container)
if err == nil {
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
commands := []string{
"usermod -aG docker " + sudoName, // add user do docker group
}

for _, command := range commands {

out, stderr, err := cli.Exec(GetSudoPrefix(cli)+"bash -c", []string{command}, false)

if stderr != "" {
errorGroup = append(errorGroup, errors.New(command+": "+stderr))
}
if err != nil {
errorGroup = append(errorGroup, errors.New(err.Error()+"("+command+")"))
}
color.Fprintln(cli.Out(), out)
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
color.Fprintln(cli.Out(), err)
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
}

return errorGroup
}

func logname(cli Cli) (string, error) {
stdout, stderr, err := cli.Exec("logname", nil, false)
Giluerre marked this conversation as resolved.
Show resolved Hide resolved
if stderr != "" {
return "", errors.New(stderr)
}
if err != nil {
return "", err
}
return stdout, err
}