Here's my script. Wanted to make it good. Got some great practice with various loops and functions as well as putting in failsafes and making it a bit interactive
#variables to be used...
newuser= #variable used to create a new user
currentuser=$HOME #current user variable, reads $HOME variable
yesno= #variable for yes/no answers
rootid=0 #vairable to determine root status
newexist= #used to determine if we are using a new or existing user
echo "what would you like the new user's name to be"
echo "the new user will be $newuser"
echo "creating new user..."
#function to ask if the user is new or old
echo "Are you creating a new user or moving files to an existing account"
if [ "$newexist" = "new" ]; then
echo "what is the name of the account you wish to move files to"
#this function copies all the user's files over
echo "the current user is $currentuser"
echo "do you wish to move this user to /home/$newuser ?"
read yesno #asks for user input
if [ "$yesno" = "n" ] || [ "$yesno" != "y" ] #if the answer is n or not y then ask for new user name
echo "enter the username of the account to be moved"
read currentuser #gets user input and puts into currentuser variable
currentuser=/home/$currentuser #if $currentuser is left as just an inputed name "user" then it will try to use user instead of /home/user so set variable to use /home/$currentuser
echo "this is the right user?"
if [ "$yesno" != "y" ]; then #this if statement is needed to prevent wrong inputs, eg no instead of n
echo "you have not entered a valid answer"
echo "exiting status 1"
#when the user is set right it now moves all the files over to the new user
mv "-f" $currentuser/* /home/$newuser #moves files recursively and forcefully, probably need if we use the adduser method
echo "files have been moved from $currentuser to $newuser"
echo "removing old files"
rm -Rf $currentuser/*
cd $currentuser #moves to the old user's folder
echo "making new directories"
mkdir Desktop Documents Downloads Music Pictures Videos #makes all the default user directories for ubuntu
echo "changing user permissions"
chown $newuser /home/$newuser/* #changes file ownership, otherwise everything is owned by root
chmod 755 /home/$newuser/* #changes file permissions, rwx,r-x,r-x, read,write, execute for user and read execute for else
#start off testing for root, because this cannot be done without it and should exit if you are not root
if [ "$UID" -eq "$rootid" ] #checks for root
newold #calls newuser function
moveuser #calls move user function
else #If you are not root then it exits
echo "You are not root. Run the script again with sudo"
echo "exiting now"