Skip to content

Commit 2e123b6

Browse files
authored
feat(install): add one click install script for Ubuntu18.04
<en> add one click install script for Ubuntu18.04 <zh> 添加 Ubuntu 18.04 一键安装脚本,方便用户在本地快速进行 dev 开发 docker pull ubuntu docker run -it -p 1234:80 -p 1235:1337 -v `pwd`:/app ubuntu wget -qO- https://raw.githubusercontent.com/ly525/luban-h5/dev/deploy/ubuntu-install.sh | bash
1 parent b140e67 commit 2e123b6

File tree

1 file changed

+357
-0
lines changed

1 file changed

+357
-0
lines changed

deploy/ubuntu-install.sh

+357
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
#/usr/bin/env
2+
3+
######################################################
4+
# [鲁班H5] Ubuntu18.04 一键安装脚本
5+
######################################################
6+
7+
8+
######################################################
9+
# [本地一键安装步骤]
10+
# docker pull ubuntu
11+
# docker run -it -p 1234:80 -p 1235:1337 -v `pwd`:/app ubuntu
12+
# wget -qO- https://raw.githubusercontent.com/ly525/luban-h5/dev/deploy/ubuntu-install.sh | bash
13+
######################################################
14+
15+
######################################################
16+
# [安装完成之后]
17+
# 1. 鲁班后台
18+
# 1.1 宿主机访问 [鲁班后台]:localhost:1234/admin,自定义配置账号密码,登录即可
19+
# 1.2 配置相关权限,文档参见:https://ly525.github.io/luban-h5/zh/getting-started/quick-start.html#%E5%90%8E%E7%AB%AF%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA
20+
21+
# 2. 鲁班前端
22+
# 2.1 宿主机访问 「鲁班前端」:localhost:1234/main, 即可看到鲁班的前端了
23+
######################################################
24+
25+
######################################################
26+
# [问题反馈]
27+
28+
# GitHub:https://github.com/ly525/luban-h5
29+
######################################################
30+
31+
32+
#
33+
#
34+
35+
## Variables
36+
#
37+
38+
GREEN="\033[0;32m"
39+
YELLOW="\033[0;33m"
40+
RED="\033[0;31m"
41+
NEUTRAL="\033[0m"
42+
NGINX_CONFIG_DIR='/etc/nginx/'
43+
44+
45+
#
46+
## Displaying functions
47+
#
48+
49+
function already {
50+
echo -e "${YELLOW}[-]$1 is already installed${NEUTRAL}"
51+
}
52+
53+
function installing {
54+
echo -e "${GREEN}[~]Installing $1...${NEUTRAL}"
55+
}
56+
57+
function success {
58+
echo -e "${GREEN}[+]$1 successfully installed${NEUTRAL}"
59+
}
60+
61+
function exitBanner {
62+
echo "#"
63+
echo "# Node.js, Strapi, PM2, MongoDB and nginx are now installed"
64+
echo "#"
65+
}
66+
67+
function base_install {
68+
RUN $1 &>/dev/null
69+
if [ $? == "1" ]; then
70+
already wget
71+
else
72+
installing $1
73+
apt-get install -y $1
74+
success $1
75+
fi
76+
}
77+
78+
function set_apt_mirror {
79+
# 准备工作:
80+
# 1. 更换 ubuntu 镜像
81+
#
82+
# 查看 ubuntu 版本: cat /etc/issue
83+
# 替换为清华大学镜像:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
84+
# 或替换为中科大镜像:https://lug.ustc.edu.cn/wiki/mirrors/help/ubuntu
85+
# sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
86+
# sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
87+
#
88+
sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
89+
apt update
90+
91+
}
92+
93+
#
94+
## Logic
95+
#
96+
97+
# function install_wget {
98+
# wget &>/dev/null
99+
# if [ $? == "1" ]; then
100+
# already wget
101+
# else
102+
# installing wget
103+
# apt-get update
104+
# apt-get install -y wget
105+
# success wget
106+
# fi
107+
# }
108+
109+
function install_nvm {
110+
if [ -a $HOME/.nvm ]; then
111+
already nvm
112+
else
113+
installing nvm
114+
# -q, --quiet 安静模式(无信息输出)
115+
# -O, --output-document=FILE 将文档写入 FILE
116+
wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
117+
export NVM_DIR=$HOME/.nvm;
118+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
119+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
120+
# source $HOME/.nvm/nvm.sh;
121+
# . ~/.nvm/nvm.sh;
122+
# source ~/.bashrc
123+
nvm --version
124+
success nvm
125+
fi
126+
}
127+
128+
function install_node {
129+
node -v &>/dev/null
130+
if [ $? == "0" ]; then
131+
already node
132+
else
133+
installing node
134+
# source $HOME/.nvm/nvm.sh;
135+
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/;
136+
# gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
137+
export NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/;
138+
nvm install stable
139+
nvm use stable
140+
nvm alias default stable
141+
success node
142+
fi
143+
}
144+
145+
function install_yarn {
146+
yarn -v &>/dev/null
147+
if [ $? == "0" ]; then
148+
already yarn
149+
else
150+
installing yarn
151+
apt install gnupg -y
152+
apt install gnupg1 -y
153+
apt install gnupg2 -y
154+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
155+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
156+
# https://yarnpkg.com/en/docs/install#debian-stable
157+
apt-get remove -y cmdtest
158+
apt-get update
159+
apt-get install -y yarn
160+
success yarn
161+
fi
162+
}
163+
164+
function set_npm_mirror {
165+
if [ -a $HOME/.npmrc ]; then
166+
already set_npm_mirror
167+
else
168+
installing set_npm_mirror
169+
wget -qO- https://raw.githubusercontent.com/ly525/luban-h5/dev/deploy/mirror.sh | bash
170+
success set_npm_mirror
171+
fi
172+
}
173+
174+
175+
176+
function install_strapi {
177+
strapi &>/dev/null
178+
if [ $? == "0" ]; then
179+
already Strapi
180+
else
181+
installing Strapi
182+
# 这里将mac怀疑安全性的包采取信任
183+
# https://github.com/strapi/strapi/issues/2787
184+
npm install --unsafe-perm=true --allow-root -g strapi@alpha
185+
# . ~/.nvm/nvm.sh
186+
# source $HOME/.nvm/nvm.sh;
187+
strapi -v
188+
success Strapi
189+
fi
190+
}
191+
192+
function install_pm2 {
193+
pm2 &>/dev/null
194+
if [ $? == "1" ]; then
195+
already PM2
196+
else
197+
installing PM2
198+
npm install -g pm2@latest
199+
. ~/.nvm/nvm.sh
200+
pm2 update
201+
success PM2
202+
fi
203+
}
204+
205+
function install_nginx {
206+
nginx &>/dev/null
207+
if [ $? == "1" ]; then
208+
already nginx
209+
else
210+
installing nginx
211+
apt-get update
212+
apt-get install -y nginx
213+
214+
# Relpace nginx config file
215+
sed -i 's/www-data/root/g' /etc/nginx/nginx.conf
216+
cat > /etc/nginx/sites-available/default <<EOF
217+
##
218+
# You should look at the following URL's in order to grasp a solid understanding
219+
# of Nginx configuration files in order to fully unleash the power of Nginx.
220+
# http://wiki.nginx.org/Pitfalls
221+
# http://wiki.nginx.org/QuickStart
222+
# http://wiki.nginx.org/Configuration
223+
#
224+
# Generally, you will want to move this file somewhere, and start with a clean
225+
# file but keep this around for reference. Or just disable in sites-enabled.
226+
#
227+
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
228+
##
229+
230+
231+
# ----- luban nginx config start
232+
server {
233+
234+
listen 80 default_server;
235+
listen [::]:80 default_server;
236+
server_name _;
237+
238+
client_body_buffer_size 4096M;
239+
client_max_body_size 4096M;
240+
proxy_buffer_size 128M;
241+
proxy_buffers 32 128M;
242+
proxy_busy_buffers_size 128M;
243+
244+
gzip on;
245+
gzip_min_length 1k;
246+
gzip_buffers 4 16k;
247+
gzip_disable "MSIE [1-6]\.";
248+
gzip_comp_level 3;
249+
gzip_types image/png application/json text/plain application/x-javascript text/css application/xml text/javascript application/javascript;
250+
251+
location ~ ^/(upload|content-manager|users-permissions|works|admin|psd-files|workforms|third-libs|engine-assets) {
252+
253+
proxy_set_header Host \$host;
254+
proxy_set_header X-Real-IP \$remote_addr;
255+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
256+
proxy_pass http://localhost:1337;
257+
}
258+
259+
# location /index {
260+
# root /home/centos/codebase/luban/luban-h5-dist/front-end/;
261+
# #try_files \$uri \$uri/ /index.html;
262+
# }
263+
# location / {
264+
265+
# root /home/centos/codebase/luban/luban-h5-dist/landing-page/;
266+
# #try_files \$uri \$uri/ /index.html;
267+
# }
268+
269+
270+
location ^~ /main {
271+
alias /root/luban-h5/front-end/h5/dist/;
272+
# index index.html;
273+
#try_files \$uri \$uri/ /index.html;
274+
}
275+
276+
}
277+
278+
# ----- luban nginx config end
279+
EOF
280+
service nginx restart
281+
success nginx
282+
fi
283+
}
284+
285+
function install_mongodb {
286+
mongo &>/dev/null
287+
if [ $? == "1" ]; then
288+
already MongoDB
289+
else
290+
installing MongoDB
291+
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
292+
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list
293+
apt-get update
294+
apt-get install -y mongodb-org
295+
service mongod start
296+
success MongoDB
297+
fi
298+
}
299+
300+
301+
function install_luban-h5 {
302+
if [ -a $HOME/luban-h5 ]; then
303+
already luban-h5
304+
else
305+
installing luban-h5
306+
cd ~/
307+
git clone https://github.com/ly525/luban-h5
308+
309+
# 鲁班前端
310+
cd luban-h5/front-end/h5 && yarn && yarn build && yarn engine:build
311+
312+
cd -
313+
314+
# 鲁班后端
315+
cd luban-h5/back-end/h5-api/
316+
yarn
317+
yarn build # build strapi admin
318+
pm2 start server.js
319+
pwd
320+
success luban-h5
321+
fi
322+
}
323+
324+
#
325+
## Main
326+
#
327+
328+
set_apt_mirror
329+
330+
331+
base_install vim
332+
base_install wget
333+
base_install curl
334+
base_install git
335+
base_install make
336+
base_install gcc
337+
base_install python
338+
## for `yarn add sqlite3`
339+
## https://packages.ubuntu.com/xenial/build-essential
340+
## https://linuxconfig.org/how-to-install-g-the-c-compiler-on-ubuntu-18-04-bionic-beaver-linux
341+
base_install build-essential
342+
343+
344+
install_nvm
345+
install_node
346+
install_yarn
347+
set_npm_mirror
348+
install_strapi
349+
install_pm2
350+
install_nginx
351+
install_luban-h5
352+
exitBanner
353+
354+
echo
355+
echo -e "${GREEN}[+]Done.${NEUTRAL}"
356+
357+
exec $SHELL -l

0 commit comments

Comments
 (0)