From 41a5ddd15079bf0f75100335bb163ba629b70eae Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 19 May 2022 19:11:29 +0000 Subject: setup-user: suggest a username use first char in first name and all last name, in lower case as suggested user name. --- setup-user.in | 3 ++- tests/setup_user_test | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/setup-user.in b/setup-user.in index 789ff84..4c900a9 100644 --- a/setup-user.in +++ b/setup-user.in @@ -52,7 +52,8 @@ fi if [ -n "$interactive" ] && [ -z "$username" ]; then while true; do - ask "Enter username for $fullname:" + ask "Enter username for $fullname" \ + $(echo "$fullname" | sed -E 's/^(.).*\s+(.*)/\1\2/' | tr '[:upper:]' '[:lower:]') username="$resp" if [ -n "$fullname" ]; then $MOCK adduser -g "$fullname" $nopassword "$username" && break diff --git a/tests/setup_user_test b/tests/setup_user_test index d8e6d77..03660b9 100755 --- a/tests/setup_user_test +++ b/tests/setup_user_test @@ -48,12 +48,12 @@ setup_user_interactive_body() { setup_user_interactive_fullname_body() { init_env ( - echo "testuser" + echo "" ) | atf_check -s exit:0 \ -o not-match:"Enter full name" \ - -o match:"Enter username" \ - -o not-match:"adduser.* -D .*testuser" \ - -o match:"adduser.* -g Joe User .*testuser" \ + -o match:"Enter username.*[juser]" \ + -o not-match:"adduser.* -D .*" \ + -o match:"adduser.* -g Joe User .*juser" \ -e empty \ setup-user -f "Joe User" -k none } -- cgit v1.2.3