forked from denisoid/simple-administration-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddsite.sh
More file actions
executable file
·53 lines (33 loc) · 1.13 KB
/
addsite.sh
File metadata and controls
executable file
·53 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
SITE=$1
#directories for virtual hosts
APACHE_VHOST_DIR=/etc/apache2/sites-enabled/
NGINX_VHOST_DIR=/etc/nginx/sites-enabled/
#path to virtual host templates
APACHE_VHOST=skel/apache2
NGINX_VHOST=skel/nginx
#copying and insert host name
cp $APACHE_VHOST $APACHE_VHOST_DIR$SITE;
sed -i 's/__host__/'$SITE'/g' $APACHE_VHOST_DIR$SITE
cp $NGINX_VHOST $NGINX_VHOST_DIR$SITE;
sed -i 's/__host__/'$SITE'/g' $NGINX_VHOST_DIR$SITE
#creating mysql username and password
MYSQLU=`echo $SITE | tr \.- __`
MYSQLU=${MYSQLU:0:16}
MYSQLP=`./gen_pass.sh`
#sql queries for creating database and grant access
MYSQL_QUERIES="CREATE DATABASE $MYSQLU; GRANT ALL PRIVILEGES ON $MYSQLU.* TO $MYSQLU@localhost IDENTIFIED BY '$MYSQLP';"
echo "Enter password for mysql";
echo $MYSQL_QUERIES | mysql -p ;
#creating user
adduser $SITE --disabled-password --quiet --force-badname
mkdir /home/$SITE/public_html/
chown $SITE:$SITE /home/$SITE/public_html/
echo "User created!"
echo "Username: " $SITE
echo "MYSQL user: " $MYSQLU
echo "MYSQL database: "$MYSQLU
echo "MYSQL password: " $MYSQLP
#restart webserver
service apache2 graceful
service nginx reload