Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "Enter Domain without www., http:// etc.:"
- read DOMAIN
- # ROOT pass to MySQL:
- SQLROOTPASS="mysql_root_passwd"
- # FTP:
- USERNAME=${DOMAIN//\./_}
- USERPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
- IP=`wget -qO - http://cfaj.freeshell.org/ipaddr.cgi`
- # MySQL:
- MYSQLDB="${USERNAME}_db"
- MYSQLUSER=$USERNAME
- MYSQLPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
- # DIRs:
- VHOSTS=/etc/httpd/vhosts
- SAMPLE=/root/vhosts.sample
- BASE="/home/$USERNAME"
- # Check dir not exists
- if [ -d "$BASE/$DOMAIN" ]; then
- echo "$DOMAIN exists!"
- exit 1
- fi
- # Check conf not exists
- if [ -f "$VHOSTS/$DOMAIN.conf" ]; then
- echo "$DOMAIN exists in apache!"
- exit 1
- fi
- # Check user don`t exists
- passwd $USERNAME > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- # if [ -n $TMP ]; then
- echo "$USERNAME found!"
- exit 1
- fi
- echo "Creating User: $USERNAME."
- adduser -g www -s /sbin/nologin $USERNAME
- echo "$USERNAME:$USERPASS" |chpasswd
- echo "Creating Dirs: web, log, tmp."
- mkdir -p "$BASE/$DOMAIN"
- mkdir "$BASE/$DOMAIN/web"
- mkdir "$BASE/$DOMAIN/log"
- mkdir "$BASE/$DOMAIN/tmp"
- chmod -R 770 "$BASE"
- echo "<?php phpinfo();" >> "$BASE/$DOMAIN/web/index.php"
- chmod 640 "$BASE/$DOMAIN/web/index.php"
- chown -R $USERNAME:www "$BASE"
- echo "Creating VirtualHost."
- sed -e "s/domain.com/$DOMAIN/g" "$SAMPLE" > "$VHOSTS/$DOMAIN.conf"
- sed -i -e "s/username/$USERNAME/g" "$VHOSTS/$DOMAIN.conf"
- echo "Restart apache."
- /etc/init.d/httpd graceful
- echo "Create MySQL user & DB."
- echo "create database $MYSQLDB;" | mysql --password=$SQLROOTPASS
- echo "GRANT ALL PRIVILEGES ON $MYSQLDB.* TO $MYSQLUSER@'localhost' IDENTIFIED BY '$MYSQLPASS';" | mysql --password=$SQLROOTPASS
- echo "flush privileges;" | mysql --password=$SQLROOTPASS
- echo "FTP:"
- echo "Host: $IP"
- echo "User: $USERNAME"
- echo "Pass: $USERPASS"
- echo "MySQL:"
- echo "DB: $MYSQLDB"
- echo "User: $MYSQLUSER"
- echo "Pass: $MYSQLPASS"
- echo "Enter to exit."
- read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement