Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "Account Name:"
  4. read newUserInput
  5.  
  6. if id $newUserInput >/dev/null 2>&1; then
  7. echo "User with name $newUserInput already exists"
  8. else
  9. echo "Adding user $newUserInput"
  10. useradd $newUserInput
  11. fi
  12.  
  13. echo "Assign a group to the new account:"
  14. read newUserGroup
  15.  
  16. if grep -q $newUserGroup /etc/group
  17. then
  18. echo "$newUserGroup group already exists"
  19. usermod -g $newUserGroup $newUserInput
  20. else
  21. groupadd $newUserGroup
  22. echo "$newUserGroup group created"
  23. usermod -g $newUserGroup $newUserInput
  24. fi
  25.  
  26.  
  27. echo "Create a partition for the new user on /dev/sdb (y/n)?"
  28. read createPartPrompt
  29.  
  30. touch /home/unix/usersCreated
  31. echo $newUserInput >> /home/unix/usersCreated
  32. count=$(wc -l < /home/unix/usersCreated)
  33. sda=/dev/sda$count
  34.  
  35. if [ "$count" -eq 1 ]; then
  36. test='p'
  37. else
  38. test='l'
  39. fi
  40.  
  41. if [ "$createPartPrompt" = "y" ]; then
  42. echo 'user said yes'
  43. (echo n
  44. echo $test
  45. echo
  46. echo
  47. echo +2G
  48. echo w
  49. ) | sudo fdisk /dev/sda
  50. mkfs -t ext4 $sda
  51. cd /media
  52. sudo mkdir $newUserInput
  53. sudo mount $sda /media/$newUserInput
  54.  
  55. if [ ! -d /media/$newUserInput/Personal ]; then
  56. cd /media/$newUserInput
  57. sudo mkdir Personal
  58. sudo chown $newUserInput /media/$newUserInput/Personal
  59. sudo chmod 760 /media/$newUserInput/Personal
  60. cd /media/$newUserInput/Personal
  61. echo $(date) >> Document1
  62. echo $newUserInput >> Document2
  63. fi
  64. else
  65. echo 'user said no'
  66. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement