Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- alias useradd=adduser
- args=
- user=
- usergroup=true
- groups=
- password=
- home=
- shell=
- TEMP=$(getopt \
- -o b:c:d:De:f:g:G:hk:K:lmMNop:rs:u:UZ: \
- -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 \
- -- "$@"
- )
- eval set -- "$TEMP"
- while true ; do
- case "$1" in
- -b|--base-dir) shift ;;
- -c|--comment) args="$args -g '$2'" ; shift ;;
- -d|--home) args="$args -h '$2'" ; shift ;;
- -D|--defaults) ;;
- -e|--expiredate) shift ;;
- -f|--inactive) shift ;;
- -g|--gid|-G|--groups)
- if [ "" = "$groups" ] ; then
- groups="$2"
- else
- groups="$groups,$2"
- fi
- shift
- ;;
- -h|--help) ;;
- -k|--skel) args="$args -k '$2'" ; shift ;;
- -K|--key) shift ;;
- -l|--no-log-init) ;;
- -m|--create-home) ;;
- -M) args="$args -H" ;;
- -N|--no-user-group) usergroup= ;;
- -o|--non-unique) ;;
- -p|--password) password="$2" ; shift ;;
- -r|--system) args="$args -S" ;;
- -s|--shell) args="$args -s '$2'" ; shift ;;
- -u|--uid) args="$args -u $2" ; shift ;;
- -U|--user-group) usergroup=true ;;
- -Z|--selinux-user) ;;
- --) ;;
- *) user="$1" ; shift ; break ;;
- esac
- shift
- done
- adduser -D $args $user
- exit 0
- # something in the following causes provisioning to hang (fail)
- eval set -- "${groups//,/ }"
- while [ "" != "$1" ] ; do
- adduser $user $1 ; shift
- done
- if [ "" != "$password" ] ; then
- # passwd $user <<END # cannot read from stdin?
- su $user -c chpasswd <<END
- $password
- $password
- END
- fi
- # unlock user
- passwd -u $user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement