Skip to content

Instantly share code, notes, and snippets.

@ahelal
Last active December 12, 2016 21:27
Show Gist options
  • Save ahelal/68a8defc2766e50e8be770aa68c90bd8 to your computer and use it in GitHub Desktop.
Save ahelal/68a8defc2766e50e8be770aa68c90bd8 to your computer and use it in GitHub Desktop.
simulate useradd for alpine
#!/bin/sh
set -e
while test $# -gt 0
do
case "$1" in
-m)
# create homedir
shift 1 ;;
-d)
_home="$2"
shift 2 ;;
-s)
_shell="$2"
shift 2 ;;
-p)
_password="$2"
shift 2 ;;
*)
_username="$1"
break ;;
esac
done
[[ -z "${_home}" ]] && echo "Missing home" && exit 1
[[ -z "${_shell}" ]] && echo "Missing shell" && exit 1
[[ -z "${_password}" ]] && echo "Missing password" && exit 1
[[ -z "${_username}" ]] && echo "Missing username" && exit 1
adduser -h ${_home} -s ${_shell} -D ${_username}
# change password
password=$(echo "${_password}" | mkpasswd) && echo "kitchen:${password}" | chpasswd
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment