Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. chck_rgx () { # Checks that the given name for a user/group fulfills the regex. The function's parameters are
  2. # * $1: kind of name to check: username, hostname, etc.
  3. # * $2: variable whose value to check if meets the requirements.
  4. local rgx_hostname='^[a-z][a-zA-Z0-9_-]+$' ;
  5. local rgx_inputbox_hostname="The hostname you just submitted isn't a valid name. Try with another name."
  6. local rgx_username='^[a-z][a-z0-9_-]+$' ;
  7. local rgx_inputbox_username="The username you just submitted isn't a valid name. Try with another name." ;
  8. eval rgx_name="$rgx_$1" ;
  9. eval rgx_inputbox="$rgx_inputbox_$1" ;
  10. eval name_ch="$$2" ;
  11. while [[ ! $name_ch =~ $rgx_name ]] ; do
  12. dialog --backtitle "$backtitle_var"
  13. --title "Wrong $1 submitted" --clear
  14. --inputbox "$rgx_inputbox" 0 0 2> name-ch ;
  15. name_ch=$(cat name-ch) ;
  16. rm name-ch ;
  17. done
  18. chckd_var="$name_ch" ;
  19. }
  20.  
  21. dialog --backtitle "$backtitle_var"
  22. --title "Submit the username" --clear
  23. --inputbox "Which username do you want?" 0 0 2> user-name ;
  24. user_name=$(cat user-name) ;
  25. chck_rgx username user_name ;
  26. user_name=$chckd_var ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement