Advertisement
azverin

bash: AddSite

Mar 27th, 2012
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.94 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "Enter Domain without www., http:// etc.:"
  4. read DOMAIN
  5.  
  6. # ROOT pass to MySQL:
  7. SQLROOTPASS="mysql_root_passwd"
  8.  
  9. # FTP:
  10. USERNAME=${DOMAIN//\./_}
  11. USERPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
  12. IP=`wget -qO - http://cfaj.freeshell.org/ipaddr.cgi`
  13.  
  14. # MySQL:
  15. MYSQLDB="${USERNAME}_db"
  16. MYSQLUSER=$USERNAME
  17. MYSQLPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
  18.  
  19. # DIRs:
  20. VHOSTS=/etc/httpd/vhosts
  21. SAMPLE=/root/vhosts.sample
  22. BASE="/home/$USERNAME"
  23.  
  24. # Check dir not exists
  25. if [ -d "$BASE/$DOMAIN" ]; then
  26.     echo "$DOMAIN exists!"
  27.     exit 1
  28. fi
  29.    
  30. # Check conf not exists
  31. if [ -f "$VHOSTS/$DOMAIN.conf" ]; then
  32.     echo "$DOMAIN exists in apache!"
  33.     exit 1
  34. fi
  35.  
  36. # Check user don`t exists
  37. passwd $USERNAME > /dev/null 2>&1
  38. if [ $? -eq 0 ]; then
  39. # if [ -n $TMP ]; then
  40.     echo "$USERNAME found!"
  41.     exit 1
  42. fi
  43.  
  44. echo "Creating User: $USERNAME."
  45. adduser -g www -s /sbin/nologin $USERNAME
  46. echo "$USERNAME:$USERPASS" |chpasswd
  47.  
  48. echo "Creating Dirs: web, log, tmp."
  49. mkdir -p "$BASE/$DOMAIN"
  50. mkdir "$BASE/$DOMAIN/web"
  51. mkdir "$BASE/$DOMAIN/log"
  52. mkdir "$BASE/$DOMAIN/tmp"
  53. chmod -R 770 "$BASE"
  54. echo "<?php phpinfo();" >> "$BASE/$DOMAIN/web/index.php"
  55. chmod 640 "$BASE/$DOMAIN/web/index.php"
  56. chown -R $USERNAME:www "$BASE"
  57.  
  58. echo "Creating VirtualHost."
  59. sed -e "s/domain.com/$DOMAIN/g" "$SAMPLE" > "$VHOSTS/$DOMAIN.conf"
  60. sed -i -e "s/username/$USERNAME/g" "$VHOSTS/$DOMAIN.conf"
  61.  
  62. echo "Restart apache."
  63. /etc/init.d/httpd graceful
  64.  
  65. echo "Create MySQL user & DB."
  66. echo "create database $MYSQLDB;" | mysql --password=$SQLROOTPASS
  67. echo "GRANT ALL PRIVILEGES ON $MYSQLDB.* TO $MYSQLUSER@'localhost' IDENTIFIED BY '$MYSQLPASS';" | mysql --password=$SQLROOTPASS
  68. echo "flush privileges;" | mysql --password=$SQLROOTPASS
  69.  
  70. echo "FTP:"
  71. echo "Host: $IP"
  72. echo "User: $USERNAME"
  73. echo "Pass: $USERPASS"
  74.  
  75. echo "MySQL:"
  76. echo "DB:   $MYSQLDB"
  77. echo "User: $MYSQLUSER"
  78. echo "Pass: $MYSQLPASS"
  79.  
  80. echo "Enter to exit."
  81. read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement