Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "Account Name:"
- read newUserInput
- if id $newUserInput >/dev/null 2>&1; then
- echo "User with name $newUserInput already exists"
- else
- echo "Adding user $newUserInput"
- useradd $newUserInput
- fi
- echo "Assign a group to the new account:"
- read newUserGroup
- if grep -q $newUserGroup /etc/group
- then
- echo "$newUserGroup group already exists"
- usermod -g $newUserGroup $newUserInput
- else
- groupadd $newUserGroup
- echo "$newUserGroup group created"
- usermod -g $newUserGroup $newUserInput
- fi
- echo "Create a partition for the new user on /dev/sdb (y/n)?"
- read createPartPrompt
- touch /home/unix/usersCreated
- echo $newUserInput >> /home/unix/usersCreated
- count=$(wc -l < /home/unix/usersCreated)
- sda=/dev/sda$count
- if [ "$count" -eq 1 ]; then
- test='p'
- else
- test='l'
- fi
- if [ "$createPartPrompt" = "y" ]; then
- echo 'user said yes'
- (echo n
- echo $test
- echo
- echo
- echo +2G
- echo w
- ) | sudo fdisk /dev/sda
- mkfs -t ext4 $sda
- cd /media
- sudo mkdir $newUserInput
- sudo mount $sda /media/$newUserInput
- if [ ! -d /media/$newUserInput/Personal ]; then
- cd /media/$newUserInput
- sudo mkdir Personal
- sudo chown $newUserInput /media/$newUserInput/Personal
- sudo chmod 760 /media/$newUserInput/Personal
- cd /media/$newUserInput/Personal
- echo $(date) >> Document1
- echo $newUserInput >> Document2
- fi
- else
- echo 'user said no'
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement