Skip to content

Commit 704921e

Browse files
committed
init ver1
1 parent d4876c4 commit 704921e

10 files changed

+429
-0
lines changed

.giignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea/*

README.MD

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## TDC SCRIPT
2+
Script generate website in LEMP STACK - Ubuntu Only
3+
### Install
4+
-Download source and run bash in this folder
5+
6+
```bash
7+
sudo bash install.sh
8+
```
9+
10+
### useage
11+
- For use, you can run command at anywhere in system
12+
```bash
13+
bash tdc
14+
```
15+
16+
### Note
17+
- Script support only in ubuntu server.

action/add_domain

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
3+
4+
printf "=========================================================================\n"
5+
printf " Add New A Domain\n"
6+
printf "=========================================================================\n"
7+
echo -n "Type the user contain list domain or leave null for set /home folder and press [ENTER]: "
8+
read user
9+
echo -n "Type the domain name and press [ENTER]: "
10+
read domain
11+
if [ "$domain" = "" ]; then
12+
echo "Incorrect, please try again"
13+
exit
14+
fi
15+
if [ "$user" = "" ]; then
16+
domain_path="$domain"
17+
else
18+
domain_path="$user/$domain"
19+
fi
20+
21+
if [ -f /etc/nginx/sites-enabled/$domain.conf ]; then
22+
echo "$domain already exist"
23+
echo "Bye...!"
24+
exit
25+
fi
26+
mkdir -p "/home/$domain_path/public_html"
27+
mkdir -p "/home/$domain_path/logs"
28+
29+
cp -p /etc/tdc/action/index.html /home/$domain/public_html/index.html
30+
31+
chown www-data:www-data /home/$domain_path
32+
chown -R www-data:www-data /home/*/public_html
33+
chown -R www-data:www-data /var/lib/php
34+
35+
domain_alias="www.$domain"
36+
if [[ $domain == *www* ]]; then
37+
domain_alias=${domain/www./''}
38+
fi
39+
40+
cat > "/etc/nginx/sites-enabled/$domain.conf" <<END
41+
server {
42+
listen 80;
43+
44+
server_name $domain_alias;
45+
rewrite ^(.*) http://$domain\$1 permanent;
46+
}
47+
48+
server {
49+
listen 80;
50+
51+
# access_log off;
52+
access_log /home/$domain_path/logs/access.log;
53+
# error_log off;
54+
error_log /home/$domain_path/logs/error.log;
55+
56+
root /home/$domain_path/public_html;
57+
index index.php index.html index.htm;
58+
server_name $domain;
59+
60+
location / {
61+
try_files \$uri \$uri/ /index.php?\$args;
62+
}
63+
64+
# Custom configuration
65+
include /home/$domain_path/public_html/*.conf;
66+
67+
location ~ \.php$ {
68+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
69+
include /etc/nginx/fastcgi_params;
70+
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
71+
fastcgi_index index.php;
72+
fastcgi_connect_timeout 300;
73+
fastcgi_send_timeout 300;
74+
fastcgi_read_timeout 300;
75+
fastcgi_buffer_size 32k;
76+
fastcgi_buffers 8 16k;
77+
fastcgi_busy_buffers_size 32k;
78+
fastcgi_temp_file_write_size 32k;
79+
fastcgi_intercept_errors on;
80+
fastcgi_param SCRIPT_FILENAME /home/$domain_path/public_html\$fastcgi_script_name;
81+
}
82+
83+
location ~ /\. {
84+
deny all;
85+
}
86+
87+
location = /favicon.ico {
88+
log_not_found off;
89+
access_log off;
90+
}
91+
92+
location = /robots.txt {
93+
allow all;
94+
log_not_found off;
95+
access_log off;
96+
}
97+
98+
location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
99+
gzip_static off;
100+
add_header Pragma public;
101+
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
102+
access_log off;
103+
expires 30d;
104+
break;
105+
}
106+
107+
location ~* \.(txt|js|css)$ {
108+
add_header Pragma public;
109+
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
110+
access_log off;
111+
expires 30d;
112+
break;
113+
}
114+
}
115+
END
116+
service nginx reload
117+
118+
echo "Created successfully $domain"
119+
echo "Upload code to /home/$domain_path/public_html/"
120+
echo "Log of $domain show in /home/$domain_path/logs"

action/backup_code

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
backupcode()
4+
{
5+
echo "Backup $website, please waiting...."
6+
cd /home/$website/
7+
tar czf $website.tar.gz *
8+
9+
mkdir -p /home/private_html/backup/$website/
10+
mv $website.tar.gz /home/private_html/backup/$website/$website.tar.gz
11+
12+
echo "Backup $website successfully..."
13+
echo "Path of file Backup: /home/private_html/backup/$website/$website.tar.gz"
14+
}
15+
16+
printf "=========================================================================\n"
17+
printf " Backup code\n"
18+
printf "=========================================================================\n"
19+
echo -n "Type the user contain list domain or leave null for set /home folder and press [ENTER]: "
20+
read user
21+
echo -n "Type domain name want to backup and press [ENTER]: "
22+
read website
23+
24+
if [ "$user" = "" ]; then
25+
domain_path="$website"
26+
else
27+
domain_path="$user/$website"
28+
fi
29+
30+
if [ -f /home/$domain_path/public_html/index.php ]; then
31+
echo "Found $domain_path"
32+
if [ -f /home/private_html/backup/$website/$website.tar.gz ]; then
33+
read -r -p "Old file Found , you are sure want to delete old file and create a new file ? [y/N] " response
34+
case $response in
35+
[yY][eE][sS]|[yY])
36+
rm -rf /home/private_html/backup/$website/
37+
38+
backupcode
39+
;;
40+
*)
41+
echo "Bye....!"
42+
;;
43+
esac
44+
else
45+
backupcode
46+
fi
47+
else
48+
echo "Sorry, we did not found $website"
49+
echo "Or $website is empty"
50+
echo "Bye...!"
51+
exit
52+
fi

action/backup_database

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
backupdata ()
4+
{
5+
echo "Is backing up $dataname..."
6+
mkdir -p /home/private_html/backup/$dataname
7+
cd /home/private_html/backup/$dataname
8+
mysqldump -u $user -p$pass $dataname | gzip -9 > $dataname.sql.gz
9+
10+
echo "Backup successfully!"
11+
echo "Path of file backup: /home/private_html/backup/$dataname/$dataname.sql.gz"
12+
}
13+
14+
printf "=========================================================================\n"
15+
printf " Backup Data\n"
16+
printf "=========================================================================\n"
17+
echo -n "Type the user of database [ENTER]: "
18+
read user
19+
echo -n "Type the password of database [ENTER]: "
20+
read pass
21+
echo -n "Type database name you want backup and press [ENTER]: "
22+
read dataname
23+
24+
if [ "$user" = "" ]; then
25+
domain_path="$dataname"
26+
else
27+
domain_path="$user/$dataname"
28+
fi
29+
30+
if [ -f /var/lib/mysql/$dataname/db.opt ]; then
31+
echo "Found $dataname"
32+
if [ -f /home/private_html/backup/$dataname/$dataname.sql.gz ]; then
33+
read -r -p "Old fileFound , you are sure want to delete old file and create a new file ? [y/N] " response
34+
case $response in
35+
[yY][eE][sS]|[yY])
36+
rm -rf /home/private_html/backup/$dataname
37+
38+
backupdata
39+
;;
40+
*)
41+
echo "Bye....!"
42+
;;
43+
esac
44+
else
45+
backupdata
46+
fi
47+
48+
else
49+
echo "Not Found $dataname, please try again"
50+
echo "Bye...!"
51+
exit
52+
fi

action/create_database

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
if [ -f /var/lib/mysql/mysql/db.opt ]; then
4+
printf "=========================================================================\n"
5+
printf " Create Database\n"
6+
printf "=========================================================================\n"
7+
echo -n "Type a database name yout want to create and press [ENTER]: "
8+
read dataname
9+
if [ "$dataname" = "" ]; then
10+
echo "Database name is required"
11+
exit
12+
fi
13+
14+
if [ -f /var/lib/mysql/$dataname/db.opt ]; then
15+
echo "Data $dataname already exist"
16+
echo "Bye....!"
17+
exit
18+
fi
19+
20+
echo -n "Type username of database you want to create and press enter [ENTER]: "
21+
read username
22+
if [ "$username" = "" ]; then
23+
username="$dataname"
24+
echo "Database username is empty, We set default database username is $dataname"
25+
fi
26+
27+
echo -n "Type password of $username [ENTER]: "
28+
read password
29+
if [ "$password" = "" ]; then
30+
password="$dataname"
31+
echo "Password is empty, We set defaut password is $dataname"
32+
fi
33+
34+
#root user and pasword
35+
echo -n "Type root database username [ENTER]: "
36+
read rootuser
37+
if [ "$rootuser" = "" ]; then
38+
$rootuser = "root"
39+
echo "Set default is root"
40+
fi
41+
echo -n "Type root database password [ENTER]: "
42+
read rootpass
43+
if [ "$rootpass" = "" ]; then
44+
$rootpass =""
45+
echo "Set default is NULL"
46+
fi
47+
48+
49+
cat > "/tmp/config.temp" <<END
50+
CREATE DATABASE $dataname COLLATE utf8_general_ci;
51+
CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';
52+
GRANT ALL PRIVILEGES ON $dataname . * TO '$username'@'localhost';
53+
FLUSH PRIVILEGES;
54+
END
55+
56+
mysql -u $rootuser -p$rootpass < /tmp/config.temp
57+
rm -f /tmp/config.temp
58+
59+
echo "Created database $dataname successfully !"
60+
echo "==================="
61+
echo "Database detail:"
62+
printf "database name: $dataname\nUser name: $username\nPassword: $password\n\n"
63+
64+
echo "Bye....!"
65+
66+
else
67+
echo "Mysql was not running or user and password invaild!!!"
68+
echo "please check again!!!"
69+
exit
70+
fi

action/delete_domain

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
printf "=========================================================================\n"
4+
printf " Delete Domain\n"
5+
printf "=========================================================================\n"
6+
printf "Sure to delete it\n"
7+
8+
echo -n "Type the user contain list domain or leave null for set /home folder and press [ENTER]: "
9+
read user
10+
11+
echo -n "Type the domain name and press [ENTER]: "
12+
read domain
13+
14+
if [ "$user" = "" ]; then
15+
domain_path="$domain"
16+
else
17+
domain_path="$user/$domain"
18+
fi
19+
20+
if [ -f /etc/nginx/sites-enabled/$domain.conf ]; then
21+
read -r -p "Found $domain, You are sure to delete ? [y/N] " response
22+
case $response in
23+
[yY][eE][sS]|[yY])
24+
rm -rf /home/$domain_path
25+
rm -f /etc/nginx/sites-enabled/$domain.conf
26+
service nginx reload
27+
28+
echo "Delete successfully...!"
29+
;;
30+
*)
31+
echo "Bye....!"
32+
;;
33+
esac
34+
elif [ -f /etc/nginx/sites-available/$domain.conf ]; then
35+
read -r -p "Found $domain, You are sure to delete ? [y/N] " response
36+
case $response in
37+
[yY][eE][sS]|[yY])
38+
rm -rf /home/$domain_path
39+
rm -f /etc/nginx/sites-available/$domain.conf
40+
service nginx reload
41+
42+
echo "Delete successfully...!"
43+
;;
44+
*)
45+
echo "Bye....!"
46+
;;
47+
esac
48+
else
49+
echo "Not Found $domain, please check again!"
50+
echo "Bye....!"
51+
exit
52+
fi

action/domain_list

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
printf "=========================================================================\n"
4+
printf " List Domain\n"
5+
printf "=========================================================================\n"
6+
echo "=========== enabled folder: ================"
7+
ls -1 /etc/nginx/sites-enabled/
8+
echo "=========== available Folder ==============="
9+
ls -1 /etc/nginx/sites-available/

0 commit comments

Comments
 (0)