Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Adding a new user to the Cyanix system.
- # newuser is a script based on useradd.
- # We use this primarily rather than the script adduser.
- # This script makes a random password and then uses perl crypt
- # to secure the password.
- clear
- echo "Cyanix newuser v1.0"
- read -r -p "Enter a username: " username;
- echo "Using username: $username "
- password=$(makepasswd)
- echo "Using password: $password "
- echo "Username: $username Password: $password "
- read -r -s -n1 -p "Are these settings correct? " answer;
- if [[ $answer = [yY] ]]; then
- clear
- echo "Please write down the password and username."
- echo "Creating username: $username with password $password"
- if [ $(id -u) -eq 0 ]; then
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- echo "$username already exists!"
- exit 1
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m -p $pass $username
- [ $? -eq 0 ] && echo "$username has been added to the system!" || echo "Failed to add $username"
- mkdir /home/$username/www
- 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
- echo "$username IN CNAME cyanix.org. " >> /etc/bind/cyanix.org.db
- echo "Created sub domain $username.cyanix.org"
- echo "# $username.Cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
- echo "<VirtualHost *>" >> /etc/apache2/sites-available/$username.cyanix.org
- echo " ServerAdmin admin@cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
- echo " ServerName $username.cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
- echo " ServerAlias cyanix.org" >> /etc/apache2/sites-available/$username.cyanix.org
- echo " " >> /etc/apache2/sites-available/$username.cyanix.org
- echo "# Indexes + Directory Root." >> /etc/apache2/sites-available/$username.cyanix.org
- echo " DirectoryIndex index.html" >> /etc/apache2/sites-available/$username.cyanix.org
- echo " DocumentRoot /home/$username/www/" >> /etc/apache2/sites-available/$username.cyanix.org
- echo "</VirtualHost>" >> /etc/apache2/sites-available/$username.cyanix.org
- echo "Created apache site enabled."
- echo " whoami created user $username on $(date +%Y/%/m%d) " >> /var/log/$username.newuser;
- read -r -s -n1 -p "Refresh Apache and Bind now? " restartab;
- if [[ $restartab = [yY] ]]; then
- echo "Refreshing Apache and Bind now"
- a2ensite $username.cyanix.org
- /etc/init.d/bind9 restart
- /etc/init.d/apache2 reload
- clear
- echo "Apache and Bind have been refreshed."
- echo "$username.cyanix.org is now active."
- echo "Have a great day."
- else
- clear
- echo "You must manually restart Bind9 and Apache2 for the subdomain to activate."
- echo "Have a great day"
- fi
- fi
- else
- echo "You must SUDO to use this script!"
- exit 2
- fi
- else
- clear
- ./newuser
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement