switch to sh and use chpasswd to set password

This commit is contained in:
Ben Harris 2020-06-18 13:52:05 -04:00
parent d7ce3e544e
commit 7bbf6b6759
1 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# ---------------------------------------------------------------------------
# makeuser - tilde.team new user creation
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
@ -29,7 +29,9 @@ case $1 in
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
[[ $# -ne 3 ]] && error_exit "not enough args"
if [ $# -ne 3 ]; then
error_exit "not enough args"
fi
if id "$1" > /dev/null 2>&1; then
exit 0
@ -37,9 +39,9 @@ case $1 in
printf "adding new user %s\n" "$1"
newpw=$(pwgen -1B 10)
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
sudo useradd -m -g 100 -p "$pwcrypt" -s /bin/bash "$1" \
sudo useradd -m -g 100 -s /bin/bash "$1" \
|| error_exit "couldn't add user"
printf "%s:%s\n" "$1" "$newpw" | sudo chpasswd
printf "sending welcome mail\n"
sed -e "s/newusername/$1/g" \