-s option to save user info to file

This commit is contained in:
Matthew Saunders Brown 2021-10-02 14:59:01 -07:00
parent 6a1411bb51
commit 6606865372

View File

@ -17,6 +17,7 @@ help()
echo " -h Print this help." echo " -h Print this help."
echo " -p PASSWORD Password for username. Optional, random password generated if none specified." echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
echo " -u UID Numberic User ID to assign to user. Optional, next available uid set if none specified." echo " -u UID Numberic User ID to assign to user. Optional, next available uid set if none specified."
echo " -s Save user info to /home/username/.passwd. Warning! This inlcudes the unencrypted password."
exit exit
} }
@ -32,7 +33,7 @@ else
exit 1 exit 1
fi fi
while getopts "hp:u:" opt; do while getopts "hp:su:" opt; do
case "${opt}" in case "${opt}" in
h ) h )
help help
@ -40,6 +41,9 @@ while getopts "hp:u:" opt; do
p ) p )
password=${OPTARG} password=${OPTARG}
;; ;;
s )
save=true
;;
u ) u )
uid=${OPTARG} uid=${OPTARG}
;; ;;
@ -101,3 +105,11 @@ if [[ ! -f "/home/$username/.profile" ]]; then
install -o $username -g $username -m 640 /etc/skel/.profile /home/$username install -o $username -g $username -m 640 /etc/skel/.profile /home/$username
fi fi
if [ -n "$save" ]; then
if [[ ! -f "/home/$username/.passwd" ]]; then
touch /home/$username/.passwd
chmod 640 /home/$username/.passwd
chown $username:$username /home/$username/.passwd
echo "$newusers" > /home/$username/.passwd
fi
fi