Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.37 KB | None | 0 0
  1. #!/bin/bash
  2. # Adding a new user to the Cyanix system.
  3. # newuser is a script based on useradd.
  4. # We use this primarily rather than the script adduser.
  5. # This script makes a random password and then uses perl crypt
  6. # to secure the password.
  7.  
  8.  
  9. clear
  10. echo "Cyanix newuser v1.0"
  11. read  -r  -p  "Enter a username: " username;
  12. echo "Using username: $username "
  13. password=$(makepasswd)
  14. echo "Using password: $password "
  15. echo "Username: $username Password: $password "
  16.  
  17. read  -r -s -n1 -p "Are these settings correct? " answer;
  18.     if [[ $answer = [yY] ]]; then
  19.     clear
  20.     echo "Please write down the password and username."
  21.     echo "Creating username: $username with password $password"
  22.  
  23.         if [ $(id -u) -eq 0 ]; then
  24.                 egrep "^$username" /etc/passwd >/dev/null
  25.                     if [ $? -eq 0 ]; then
  26.                     echo "$username already exists!"
  27.                         exit 1
  28.                     else
  29.                     pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  30.                             useradd -m -p $pass $username
  31.                             [ $? -eq 0 ] && echo "$username has been added to the system!" || echo "Failed to add $username"
  32.                     mkdir /home/$username/www
  33.                     echo "<html><head><title> $username has not created their website. </title> </head><body> $username has not created their website yet. </body></html> " >> /home/$username/www/index.html  
  34.                     echo "$username             IN  CNAME   cyanix.org. " >> /etc/bind/cyanix.org.db                   
  35.                     echo "Created sub domain $username.cyanix.org"
  36.                     echo "# $username.Cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
  37.                     echo "<VirtualHost *>" >> /etc/apache2/sites-available/$username.cyanix.org
  38.                                         echo "      ServerAdmin admin@cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
  39.                                         echo "      ServerName  $username.cyanix.org"  >> /etc/apache2/sites-available/$username.cyanix.org
  40.                     echo "      ServerAlias cyanix.org"  >> /etc/apache2/sites-available/$username.cyanix.org
  41.                     echo " "  >> /etc/apache2/sites-available/$username.cyanix.org
  42.                             echo "# Indexes + Directory Root."  >> /etc/apache2/sites-available/$username.cyanix.org
  43.                     echo "      DirectoryIndex index.html" >> /etc/apache2/sites-available/$username.cyanix.org
  44.                         echo "      DocumentRoot /home/$username/www/" >> /etc/apache2/sites-available/$username.cyanix.org
  45.                                         echo "</VirtualHost>"  >> /etc/apache2/sites-available/$username.cyanix.org
  46.  
  47.                                         echo "Created apache site enabled."
  48.  
  49.                                         echo " whoami created user $username on $(date +%Y/%/m%d) " >> /var/log/$username.newuser;
  50.                         read  -r -s -n1 -p "Refresh Apache and Bind now? " restartab;
  51.                         if [[ $restartab = [yY] ]]; then
  52.                             echo "Refreshing Apache and Bind now"
  53.                             a2ensite $username.cyanix.org
  54.                             /etc/init.d/bind9 restart
  55.                             /etc/init.d/apache2 reload
  56.                             clear
  57.                                                     echo "Apache and Bind have been refreshed."
  58.                             echo "$username.cyanix.org is now active."
  59.                             echo "Have a great day."
  60.                         else   
  61.                             clear
  62.                             echo "You must manually restart Bind9 and Apache2 for the subdomain to activate."
  63.                             echo "Have a great day"
  64.                         fi
  65.                 fi
  66.             else
  67.                 echo "You must SUDO to use this script!"
  68.                 exit 2
  69.             fi
  70.     else
  71.         clear
  72.         ./newuser
  73.   fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement