SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. alias useradd=adduser
  4.  
  5. args=
  6. user=
  7. usergroup=true
  8. groups=
  9. password=
  10. home=
  11. shell=
  12.  
  13. TEMP=$(getopt \
  14.         -o b:c:d:De:f:g:G:hk:K:lmMNop:rs:u:UZ: \
  15.         -l base-dir:,comment:,home:,defaults,expiredate:,inactive:,gid:,groups:,help,skel:,key:,no-log-init,create-home,no-user-group,non-unique,password:,system,shell:,uid:,user-group,selinux-user \
  16.         -- "$@"
  17.         )
  18. eval set -- "$TEMP"
  19. while true ; do
  20.   case "$1" in
  21.     -b|--base-dir) shift ;;
  22.     -c|--comment) args="$args -g '$2'" ; shift ;;
  23.     -d|--home) args="$args -h '$2'" ; shift ;;
  24.     -D|--defaults) ;;
  25.     -e|--expiredate) shift ;;
  26.     -f|--inactive) shift ;;
  27.     -g|--gid|-G|--groups)
  28.       if [ "" = "$groups" ] ; then
  29.         groups="$2"
  30.       else
  31.         groups="$groups,$2"
  32.       fi
  33.       shift
  34.       ;;
  35.     -h|--help) ;;
  36.     -k|--skel) args="$args -k '$2'" ; shift ;;
  37.     -K|--key) shift ;;
  38.     -l|--no-log-init) ;;
  39.     -m|--create-home) ;;
  40.     -M) args="$args -H" ;;
  41.     -N|--no-user-group) usergroup= ;;
  42.     -o|--non-unique) ;;
  43.     -p|--password) password="$2" ; shift ;;
  44.     -r|--system) args="$args -S" ;;
  45.     -s|--shell) args="$args -s '$2'" ; shift  ;;
  46.     -u|--uid) args="$args -u $2" ; shift ;;
  47.     -U|--user-group) usergroup=true ;;
  48.     -Z|--selinux-user) ;;
  49.     --) ;;
  50.     *) user="$1" ; shift ; break ;;
  51.   esac
  52.   shift
  53. done
  54.  
  55. adduser -D $args $user
  56.  
  57. exit 0
  58. # something in the following causes provisioning to hang (fail)
  59.  
  60. eval set -- "${groups//,/ }"
  61. while [ "" != "$1" ] ; do
  62.   adduser $user $1 ; shift
  63. done
  64.  
  65. if [ "" != "$password" ] ; then
  66.   # passwd $user <<END # cannot read from stdin?
  67.   su $user -c chpasswd <<END
  68. $password
  69. $password
  70.  
  71. END
  72. fi
  73.  
  74. # unlock user
  75. passwd -u $user
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top