-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlepp.sh
More file actions
147 lines (125 loc) · 3.07 KB
/
Copy pathlepp.sh
File metadata and controls
147 lines (125 loc) · 3.07 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
TEXTDOMAIN=lepp
function install_packages()
{
echo 'Purging apache if installed'
apt --purge remove *apache*
apt-get update && apt-get install -y --allow-unauthenticated ${@}
echo 'Package installation completed'
}
## Usage
function print_help(){
cat <<EOH
Usage: $0 [-h] [-n]
-h | This help menu
-n | install
EOH
exit 1
}
nginx=/var/www/html
### nginx restart command
restartnginx='systemctl reload nginx'
### postgresql restart command
restartpostgres='systemctl start postgresql'
### set default nginx server block
nginxdefault='/etc/nginx/sites-available/default'
###check for root
if [ "$(whoami)" != 'root' ]; then
echo $"You don't have the permission to run $0 as non-root user. Sudo maybe?"
exit 1;
fi
###Install all necessary things!
function postgres(){
apt install nginx nginx-common curl postgresql postgresql-contrib -y
}
function ipaddr(){
###Get IP/domain server
echo -n "Enter your Server IP or domain and press [ENTER]: "
read IP
}
function psqlname(){
echo -n "Enter your username that you want: "
read psqluser
}
function psqlpwd(){
echo -n "Enter your password for user '$psqluser': "
read psqlpass
}
function nmDB(){
echo -n "Enter your DB name that you want: "
read namaDB
}
### edit
function editnginx(){
if ! echo "server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.js index.html index.htm index.nginx-debian.html;
server_name $IP;
location / {
try_files \$uri \$uri/ =404;
}
location ~ \.php\$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}" >| $nginxdefault
then
echo -e $"There is an ERROR create $nginxdefault file"
exit;
else
echo -e $"New $nginxdefault Created."
fi
### make sure nginx can start with new config
nginx -t
### restart nginx
$restartnginx
$restartpostgres
}
function tambahDB(){
#sudo su postgres <<'EOF'
#psql -c "CREATE DATABASE $namaDB;"
#EOF
echo -e "\nCREATE USER $psqluser WITH PASSWORD '$psqlpass';\nCREATE DATABASE $namaDB WITH OWNER $psqluser;\nGRANT ALL PRIVILEGES ON DATABASE $namaDB TO $psqluser;\n"
sudo -u postgres psql -c "CREATE USER $psqluser WITH PASSWORD '$psqlpass';"
sudo -u postgres psql -c "CREATE DATABASE $namaDB WITH OWNER $psqluser;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $namaDB TO $psqluser;"
echo "Finished Database section"
}
function trywrite(){
if ! echo $domain > $nginx/index.html
then
echo $"ERROR: Unable to write in $nginx/. Please check permissions."
exit;
else
echo $"Added index.html into $nginx/"
fi
if ! echo "<?php phpinfo(); ?>" > $nginx/info.php
then
echo $"ERROR: Unable to write in $nginx/. Please check permissions."
exit;
else
echo $"Added info.php into $nginx/"
fi
echo "You can check your webserver here http://$IP/info.php"
}
if [ "$1" = '-h' ]; then
print_help
fi
if [ "$1" = '-n' ]; then
install_packages
ipaddr
postgres
psqlname
psqlpwd
nmDB
editnginx
tambahDB
trywrite
else
print_help
fi