-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-blogfront-create.sh
249 lines (200 loc) · 6.81 KB
/
vue-blogfront-create.sh
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bash
echo -e "\n\nDuring this installation, the following dependencies will be installed if they are not already present:"
echo -e " * Nginx"
echo -e " * Docker"
echo -e " * Docker-Compose"
echo -e " * Certbot\n"
echo -e "\n"
read -p 'Name of the new blog instance: ' Name
read -p 'Display name of the new blog instance: ' Displayname
read -p 'Domain of the new blog instance: ' Domain
read -e -p 'Port to expose (default 4000): ' -i '4000' Port
read -e -p 'Port for MongoDB to expose (default 27017): ' -i '27017' Mongo
echo -e "\n"
read -e -p 'Start Docker? (y/n): ' -i 'y' Docker
read -e -p 'Start Certbot? (y/n): ' -i 'y' Certbot
# Create Domain folder
mkdir /opt/ambrest/blogs/$Domain &>/opt/ambrest/logs/$Domain.log
mkdir /opt/ambrest/blogs/$Domain/config &>/opt/ambrest/logs/$Domain.log
cd /opt/ambrest/blogs/$Domain &>/opt/ambrest/logs/$Domain.log
# Install dependencies
echo -e "\nChecking dependencies...\n"
# Check operating system!
CENTOS="CentOS Linux"
DEBIAN="Debian GNU/Linux"
. /etc/os-release
OS=$NAME
PackageManager=""
# Install on Debian
if [ "$OS" = "$DEBIAN" ]; then
PackageManager="apt"
# Install on CentOS
elif [ "$OS" = "$CENTOS" ]; then
PackageManager="yum"
else
echo -e "\n\n${RED}Your Linux distribution is NOT supported! Do you really think we're dumb enough to let that slide?${NC}"
echo -e "\nPlease visit https://github.com/ambrest/vue-blogfront for manual installation instructions, and next time read the damn instructions."
exit
fi
# EPEL-Release is needed for about everything
if [ "$OS" = "$CENTOS" ]; then
yum install -y epel-release &>/opt/ambrest/logs/$Domain.log
fi
# Nginx
if [[ ! -e /usr/sbin/nginx ]]; then
echo "Installing NGINX..."
$PackageManager install -y nginx &>/opt/ambrest/logs/$Domain.log
systemctl start nginx &>/opt/ambrest/logs/$Domain.log
systemctl enable nginx &>/opt/ambrest/logs/$Domain.log
fi
# Docker
if [[ ! -e /usr/bin/docker ]]; then
echo "Installing Docker..."
(curl -fsSL https://get.docker.com/ | sh) &>/opt/ambrest/logs/$Domain.log
systemctl start docker &>/opt/ambrest/logs/$Domain.log
systemctl enable docker &>/opt/ambrest/logs/$Domain.log
fi
# Docker-Compose
if [[ ! -e /usr/bin/docker-compose ]]; then
echo "Installing Docker-Compose..."
if [[ ! -e /usr/bin/pip ]]; then
$PackageManager install -y python-pip &>/opt/ambrest/logs/$Domain.log
fi
pip install docker-compose &>/opt/ambrest/logs/$Domain.log
fi
# Certbot
if [[ ! -e /usr/bin/certbot ]]; then
echo "Installing Certbot..."
if [ "$OS" = "$CENTOS" ]; then
yum install -y python2-certbot-nginx &>/opt/ambrest/logs/$Domain.log
pip install requests urllib3 pyOpenSSL --force --upgrade &>/opt/ambrest/logs/$Domain.log
pip install requests==2.6.0 &>/opt/ambrest/logs/$Domain.log
easy_install --upgrade pip &>/opt/ambrest/logs/$Domain.log
else
apt install -y python-certbot-nginx
fi
fi
echo -e "\n${GREEN}All dependencies installed!${NC}\n\n"
# Docker-Compose config
echo 'Creating docker configuration...'
cat >./docker-compose.yaml <<EOL
version: '3'
services:
blog:
image: ambrest/vue-blog
container_name: ${Name}_blog
restart: always
volumes:
- ./config:/config
ports:
- "${Port}:4000"
depends_on:
- mongo
mongo:
container_name: ${Name}_mongo
image: mongo
restart: always
volumes:
- ./data:/data/db
ports:
- "${Mongo}:27017"
EOL
# Nginx configuration
echo 'Creating NGINX configuration...'
cat > /etc/nginx/conf.d/$Domain.conf <<EOL
server {
listen 80;
server_name ${Domain};
location ~ (precache-manifest.*|service-worker)\.js {
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;
access_log off;
proxy_pass http://localhost:${Port};
}
location / {
proxy_pass http://localhost:${Port};
}
# Restrict TLS protocols and some ssl improvements
ssl_protocols TLSv1.2;
ssl_ecdh_curve secp521r1:secp384r1;
# Hide upstream proxy headers
proxy_hide_header X-Powered-By;
proxy_hide_header X-AspNetMvc-Version;
proxy_hide_header X-AspNet-Version;
proxy_hide_header X-Drupal-Cache;
# Custom headers
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always;
add_header Referrer-Policy "no-referrer";
add_header Feature-Policy "geolocation none; midi none; notifications none; push none; sync-xhr none; microphone none; camera none; magnetometer none; gyroscope none; speaker none; vibrate none; fullscreen self; payment none; usb none;";
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
# Close slow connections (in case of slow loris attack)
client_body_timeout 10s;
client_header_timeout 10s;
keepalive_timeout 5s 5s;
send_timeout 10s;
}
EOL
# vue-blogfront configuration
echo 'Creating vue-blogfront configuration...'
cat > ./config/blogfront.config.json <<EOL
{
"pageTitle": "${Displayname}",
"themeColor": "#C62642",
"apiEndPoint": "https://${Domain}/api",
"wordsPerMinute": 250,
"postsPreloadAmount": 3,
"meta": {
"description": "Vue blogfront - PWA for blogs. 100% Offline.",
"keywords": "Blog,Blog-engine,Vue-app,Vue,Vue2,PWA,SPA,WebApp",
"author": "Ambrest Designs"
}
}
EOL
# vue-blogfront-api configuration
echo 'Creating vue-blogfront-api configuration...'
cat > ./config/api.config.json <<EOL
{
"info": {
"author": "Ambrest Designs LLC",
"title": "${Displayname}",
"version": 1.0
},
"server": {
"port": 4000,
"startingMessage": "Server started on port 4000...",
"domain": "https://${Domain}",
"api": "https://${Domain}",
"maxClapps": 50,
"emailVerification": false
},
"mail": {
"service": "",
"secure": "",
"port": 0,
"auth": {
"user": "",
"pass": ""
}
},
"auth": {
"apikeyExpiry": 12960000000,
"saltRounds": 10
}
}
EOL
echo -e "\n"
if [ $Docker = 'y' ]; then
echo 'Starting docker...'
docker-compose pull && docker-compose up -d &>/opt/ambrest/logs/$Domain.log
echo -e "${GREEN}Docker started...${NC}\n"
fi
if [ $Certbot = 'y' ]; then
echo 'Starting certbot...'
certbot --nginx
echo -e "${GREEN}Certbot done...${NC}"
fi
systemctl restart nginx &>/opt/ambrest/logs/$Domain.log
echo -e "\n\n${PURPLE}vue-blogfront${NC} ${GREEN}installed successfully!${NC}\n"
echo -e "You can furthur configure your ${PURPLE}vue-blogfront${NC} instance in /opt/ambrest/${Domain}/config, then run ${PURPLE}vue-blogfront update${NC}.\n"