From 2e123b647d4c86c6d5f0c996da6f40ded4832067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=8F=E9=B2=81=E7=8F=AD?= Date: Sat, 30 Nov 2019 13:16:56 +0800 Subject: [PATCH] feat(install): add one click install script for Ubuntu18.04 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add one click install script for Ubuntu18.04 添加 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 --- deploy/ubuntu-install.sh | 357 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 357 insertions(+) create mode 100644 deploy/ubuntu-install.sh diff --git a/deploy/ubuntu-install.sh b/deploy/ubuntu-install.sh new file mode 100644 index 00000000..1e299f58 --- /dev/null +++ b/deploy/ubuntu-install.sh @@ -0,0 +1,357 @@ +#/usr/bin/env + +###################################################### +# [鲁班H5] Ubuntu18.04 一键安装脚本 +###################################################### + + +###################################################### +# [本地一键安装步骤] +# 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. 鲁班后台 +# 1.1 宿主机访问 [鲁班后台]:localhost:1234/admin,自定义配置账号密码,登录即可 +# 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 + +# 2. 鲁班前端 +# 2.1 宿主机访问 「鲁班前端」:localhost:1234/main, 即可看到鲁班的前端了 +###################################################### + +###################################################### +# [问题反馈] + +# GitHub:https://github.com/ly525/luban-h5 +###################################################### + + +# +# + +## Variables +# + +GREEN="\033[0;32m" +YELLOW="\033[0;33m" +RED="\033[0;31m" +NEUTRAL="\033[0m" +NGINX_CONFIG_DIR='/etc/nginx/' + + +# +## Displaying functions +# + +function already { + echo -e "${YELLOW}[-]$1 is already installed${NEUTRAL}" +} + +function installing { + echo -e "${GREEN}[~]Installing $1...${NEUTRAL}" +} + +function success { + echo -e "${GREEN}[+]$1 successfully installed${NEUTRAL}" +} + +function exitBanner { + echo "#" + echo "# Node.js, Strapi, PM2, MongoDB and nginx are now installed" + echo "#" +} + +function base_install { + RUN $1 &>/dev/null + if [ $? == "1" ]; then + already wget + else + installing $1 + apt-get install -y $1 + success $1 + fi +} + +function set_apt_mirror { + # 准备工作: + # 1. 更换 ubuntu 镜像 + # + # 查看 ubuntu 版本: cat /etc/issue + # 替换为清华大学镜像:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ + # 或替换为中科大镜像:https://lug.ustc.edu.cn/wiki/mirrors/help/ubuntu + # sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list + # sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list + # + sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list + apt update + +} + +# +## Logic +# + +# function install_wget { +# wget &>/dev/null +# if [ $? == "1" ]; then +# already wget +# else +# installing wget +# apt-get update +# apt-get install -y wget +# success wget +# fi +# } + +function install_nvm { + if [ -a $HOME/.nvm ]; then + already nvm + else + installing nvm + # -q, --quiet 安静模式(无信息输出) + # -O, --output-document=FILE 将文档写入 FILE + wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash + export NVM_DIR=$HOME/.nvm; + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + # source $HOME/.nvm/nvm.sh; + # . ~/.nvm/nvm.sh; + # source ~/.bashrc + nvm --version + success nvm + fi +} + +function install_node { + node -v &>/dev/null + if [ $? == "0" ]; then + already node + else + installing node + # source $HOME/.nvm/nvm.sh; + export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/; + # gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR + export NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/; + nvm install stable + nvm use stable + nvm alias default stable + success node + fi +} + +function install_yarn { + yarn -v &>/dev/null + if [ $? == "0" ]; then + already yarn + else + installing yarn + apt install gnupg -y + apt install gnupg1 -y + apt install gnupg2 -y + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + # https://yarnpkg.com/en/docs/install#debian-stable + apt-get remove -y cmdtest + apt-get update + apt-get install -y yarn + success yarn + fi +} + +function set_npm_mirror { + if [ -a $HOME/.npmrc ]; then + already set_npm_mirror + else + installing set_npm_mirror + wget -qO- https://raw.githubusercontent.com/ly525/luban-h5/dev/deploy/mirror.sh | bash + success set_npm_mirror + fi +} + + + +function install_strapi { + strapi &>/dev/null + if [ $? == "0" ]; then + already Strapi + else + installing Strapi + # 这里将mac怀疑安全性的包采取信任 + # https://github.com/strapi/strapi/issues/2787 + npm install --unsafe-perm=true --allow-root -g strapi@alpha + # . ~/.nvm/nvm.sh + # source $HOME/.nvm/nvm.sh; + strapi -v + success Strapi + fi +} + +function install_pm2 { + pm2 &>/dev/null + if [ $? == "1" ]; then + already PM2 + else + installing PM2 + npm install -g pm2@latest + . ~/.nvm/nvm.sh + pm2 update + success PM2 + fi +} + +function install_nginx { + nginx &>/dev/null + if [ $? == "1" ]; then + already nginx + else + installing nginx + apt-get update + apt-get install -y nginx + + # Relpace nginx config file + sed -i 's/www-data/root/g' /etc/nginx/nginx.conf + cat > /etc/nginx/sites-available/default </dev/null + if [ $? == "1" ]; then + already MongoDB + else + installing MongoDB + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 + 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 + apt-get update + apt-get install -y mongodb-org + service mongod start + success MongoDB + fi +} + + +function install_luban-h5 { + if [ -a $HOME/luban-h5 ]; then + already luban-h5 + else + installing luban-h5 + cd ~/ + git clone https://github.com/ly525/luban-h5 + + # 鲁班前端 + cd luban-h5/front-end/h5 && yarn && yarn build && yarn engine:build + + cd - + + # 鲁班后端 + cd luban-h5/back-end/h5-api/ + yarn + yarn build # build strapi admin + pm2 start server.js + pwd + success luban-h5 + fi +} + +# +## Main +# + +set_apt_mirror + + +base_install vim +base_install wget +base_install curl +base_install git +base_install make +base_install gcc +base_install python +## for `yarn add sqlite3` +## https://packages.ubuntu.com/xenial/build-essential +## https://linuxconfig.org/how-to-install-g-the-c-compiler-on-ubuntu-18-04-bionic-beaver-linux +base_install build-essential + + +install_nvm +install_node +install_yarn +set_npm_mirror +install_strapi +install_pm2 +install_nginx +install_luban-h5 +exitBanner + +echo +echo -e "${GREEN}[+]Done.${NEUTRAL}" + +exec $SHELL -l