/contrib/dialog/samples/inputmenu3

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 106 lines · 97 code · 5 blank · 4 comment · 6 complexity · b19f92b821c14f36956ca084778f21ae MD5 · raw file

  1. #! /bin/sh
  2. # $Id: inputmenu3,v 1.10 2010/01/13 10:32:51 tom Exp $
  3. #
  4. # "inputmenu1" with defaultitem, help-button and item-help.
  5. . ./setup-vars
  6. backtitle="An Example for the use of --inputmenu:"
  7. ids=`id|sed -e 's/([^)]*)//g'`
  8. uid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
  9. gid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`
  10. user="$USER"
  11. home="$HOME"
  12. returncode=0
  13. defaultitem="Username:"
  14. while test $returncode != 1 && test $returncode != 250
  15. do
  16. exec 3>&1
  17. value=`$DIALOG --clear --ok-label "Create" \
  18. --backtitle "$backtitle" \
  19. --help-button \
  20. --help-label "Script" \
  21. --default-item "$defaultitem" \
  22. --item-help "$@" \
  23. --inputmenu "Originally I designed --inputmenu for a \
  24. configuration purpose. Here is a possible piece of a configuration program." \
  25. 20 60 10 \
  26. "Username:" "$user" "User login-name" \
  27. "UID:" "$uid" "User-ID (number)" \
  28. "GID:" "$gid" "Group-ID (number)" \
  29. "HOME:" "$home" "User's home-directory" \
  30. 2>&1 1>&3`
  31. returncode=$?
  32. exec 3>&-
  33. case $returncode in
  34. $DIALOG_CANCEL)
  35. "$DIALOG" \
  36. --clear \
  37. --backtitle "$backtitle" \
  38. --yesno "Really quit?" 10 30
  39. case $? in
  40. $DIALOG_OK)
  41. break
  42. ;;
  43. $DIALOG_CANCEL)
  44. returncode=99
  45. ;;
  46. esac
  47. ;;
  48. $DIALOG_OK)
  49. case $value in
  50. HELP*)
  51. "$DIALOG" \
  52. --textbox "$0" 0 0
  53. ;;
  54. *)
  55. "$DIALOG" \
  56. --clear \
  57. --backtitle "$backtitle" \
  58. --msgbox "useradd \n\
  59. -d $home \n\
  60. -u $uid \n\
  61. -g $gid \n\
  62. $user" 10 40
  63. ;;
  64. esac
  65. ;;
  66. $DIALOG_HELP)
  67. "$DIALOG" \
  68. --textbox "$0" 0 0
  69. ;;
  70. $DIALOG_EXTRA)
  71. tag=`echo "$value" |sed -e 's/^RENAMED //' -e 's/:.*/:/'`
  72. item=`echo "$value" |sed -e 's/^.*:[ ]*//' -e 's/[ ]*$//'`
  73. case "$tag" in
  74. Username:)
  75. user="$item"
  76. ;;
  77. UID:)
  78. uid="$item"
  79. ;;
  80. GID:)
  81. gid="$item"
  82. ;;
  83. HOME:)
  84. home="$item"
  85. ;;
  86. *)
  87. tag=
  88. ;;
  89. esac
  90. test -n "$tag" && defaultitem="$tag"
  91. ;;
  92. $DIALOG_ESC)
  93. echo "ESC pressed."
  94. break
  95. ;;
  96. esac
  97. done