-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from sol-eng/add-user-check-and-verify
Add user step to setup and add prompt user with lookup and validation
- Loading branch information
Showing
5 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package operatingsystem | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/sol-eng/wbi/internal/system" | ||
) | ||
|
||
func PromptAndVerifyUser() (string, bool, error) { | ||
var overallSkip bool | ||
var userAccount string | ||
for { | ||
username, err := PromptUserAccount() | ||
userAccount = username | ||
if err != nil { | ||
return "", false, err | ||
} | ||
if strings.Contains(userAccount, "skip") { | ||
overallSkip = true | ||
break | ||
} | ||
// lookup user account details | ||
user, err := UserLookup(userAccount) | ||
if err != nil { | ||
system.PrintAndLogInfo(fmt.Sprintf(`The user account "%s" you entered cannot be found. Please try again. To skip this section type "skip".`, userAccount)) | ||
} else if user.Uid == "0" { | ||
system.PrintAndLogInfo(fmt.Sprintf(`The user account "%s" is root. A non-root user is required. Please try again. To skip this section type "skip".`, userAccount)) | ||
} else if user.HomeDir == "" { | ||
system.PrintAndLogInfo(fmt.Sprintf(`The user account "%s" does not have a home directory. A home directory is required. Please try again. To skip this section type "skip".`, userAccount)) | ||
} else { | ||
system.PrintAndLogInfo(fmt.Sprintf("user %s account found and validated", userAccount)) | ||
break | ||
} | ||
} | ||
|
||
return userAccount, overallSkip, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters