From 3b6f93afdf79368de81181aafc75a960613ed21a Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Tue, 28 Mar 2023 16:51:23 +0800 Subject: [PATCH] feat: add one-key setup script --- README.md | 12 ++------- scripts/setup.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 scripts/setup.sh diff --git a/README.md b/README.md index a48afd7c..56949ce4 100644 --- a/README.md +++ b/README.md @@ -116,18 +116,10 @@ OPENAI_API_KEY= 2. 执行 `yarn install && yarn dev` 即可。 ### 本地部署 Local Deployment - -请直接询问 ChatGPT,使用下列 Prompt: - -``` -如何使用 pm2 和 yarn 部署 nextjs 项目到 ubuntu 服务器上,项目编译命令为 yarn build,启动命令为 yarn start,启动时需要设置环境变量为 OPENAI_API_KEY,端口为 3000,使用 ngnix 做反向代理 +```shell +bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) ``` -Please ask ChatGPT with prompt: - -``` -how to deploy nextjs project with pm2 and yarn on my ubuntu server, the build command is `yarn build`, the start command is `yarn start`, the project must start with env var named `OPENAI_API_KEY`, the port is 3000, use ngnix -``` ### 容器部署 Docker Deployment diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 00000000..63a28bf0 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Check if running on a supported system +case "$(uname -s)" in + Linux) + if [[ -f "/etc/lsb-release" ]]; then + . /etc/lsb-release + if [[ "$DISTRIB_ID" != "Ubuntu" ]]; then + echo "This script only works on Ubuntu, not $DISTRIB_ID." + exit 1 + fi + else + if [[ ! "$(cat /etc/*-release | grep '^ID=')" =~ ^(ID=\"ubuntu\")|(ID=\"centos\")|(ID=\"arch\")$ ]]; then + echo "Unsupported Linux distribution." + exit 1 + fi + fi + ;; + Darwin) + echo "Running on MacOS." + ;; + *) + echo "Unsupported operating system." + exit 1 + ;; +esac + +# Check if needed dependencies are installed and install if necessary +if ! command -v node >/dev/null || ! command -v git >/dev/null || ! command -v yarn >/dev/null; then + case "$(uname -s)" in + Linux) + if [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"ubuntu\"" ]]; then + sudo apt-get update + sudo apt-get -y install nodejs git yarn + elif [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"centos\"" ]]; then + sudo yum -y install epel-release + sudo yum -y install nodejs git yarn + elif [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"arch\"" ]]; then + sudo pacman -Syu -y + sudo pacman -S -y nodejs git yarn + else + echo "Unsupported Linux distribution" + exit 1 + fi + ;; + Darwin) + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew install node git yarn + ;; + esac +fi + +# Clone the repository and install dependencies +git clone https://github.com/Yidadaa/ChatGPT-Next-Web +cd ChatGPT-Next-Web +yarn install + +# Prompt user for environment variables +read -p "Enter OPENAI_API_KEY: " OPENAI_API_KEY +read -p "Enter CODE: " CODE +read -p "Enter PORT: " PORT + +# Build and run the project using the environment variables +OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn build && OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn start