This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e3ce03  docs: update apisix install dependencies guide (#5209)
9e3ce03 is described below

commit 9e3ce038651a4fb6bac53822a380afb33517c7e8
Author: Yu.Bozhong <[email protected]>
AuthorDate: Wed Oct 13 18:20:01 2021 +0800

    docs: update apisix install dependencies guide (#5209)
---
 docs/en/latest/install-dependencies.md | 115 ++-------------------------------
 docs/zh/latest/install-dependencies.md | 115 ++-------------------------------
 utils/install-dependencies.sh          | 103 +++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 216 deletions(-)

diff --git a/docs/en/latest/install-dependencies.md 
b/docs/en/latest/install-dependencies.md
index 46353f0..eb80687 100644
--- a/docs/en/latest/install-dependencies.md
+++ b/docs/en/latest/install-dependencies.md
@@ -22,11 +22,7 @@ title: Install Dependencies
 -->
 
 - [Note](#note)
-- [CentOS 7](#centos-7)
-- [Fedora 31 & 32](#fedora-31--32)
-- [Ubuntu 16.04 & 18.04](#ubuntu-1604--1804)
-- [Debian 9 & 10](#debian-9--10)
-- [Mac OSX](#mac-osx)
+- [Install](#install)
 
 ## Note
 
@@ -44,115 +40,18 @@ title: Install Dependencies
 
 - OpenResty is a dependency of APISIX. If it is your first time to deploy 
APISIX and you don't need to use OpenResty to deploy other services, you can 
stop and disable OpenResty after installation since it will not affect the 
normal work of APISIX. Please operate carefully according to your service. For 
example in Ubuntu: `systemctl stop openresty && systemctl disable openresty`.
 
-## CentOS 7
+## Install
 
-```shell
-# install etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
+Run the following command to install Apache APISIX's dependencies on a 
supported operating system.
 
-# add OpenResty source
-sudo yum install yum-utils
-sudo yum-config-manager --add-repo 
https://openresty.org/package/centos/openresty.repo
+Supported OS versions: CentOS7, Fedora31 & 32, Ubuntu 16.04 & 18.04, Debian 9 
& 10, Mac OSX
 
-# install OpenResty and some compilation tools
-sudo yum install -y openresty curl git gcc openresty-openssl111-devel unzip 
pcre pcre-devel libldap2-dev
-
-# install LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# start etcd server
-nohup etcd &
 ```
-
-## Fedora 31 & 32
-
-```shell
-# add OpenResty source
-sudo yum install yum-utils
-sudo yum-config-manager --add-repo 
https://openresty.org/package/fedora/openresty.repo
-
-# install etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# install OpenResty and some compilation tools
-sudo yum install -y openresty curl git gcc openresty-openssl111-devel pcre 
pcre-devel libldap2-dev
-
-# install LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# start etcd server
-nohup etcd &
+curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh
 -sL | bash -
 ```
 
-## Ubuntu 16.04 & 18.04
-
-```shell
-# add OpenResty source
-wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
-sudo apt-get update
-sudo apt-get -y install software-properties-common
-sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu 
$(lsb_release -sc) main"
-sudo apt-get update
-
-# install etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# install OpenResty and some compilation tools
-sudo apt-get install -y git openresty curl openresty-openssl111-dev make gcc 
libpcre3 libpcre3-dev libldap2-dev
-
-# install LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
+If you have cloned the Apache APISIX project, execute in the Apache APISIX 
root directory:
 
-# start etcd server
-nohup etcd &
 ```
-
-## Debian 9 & 10
-
-```shell
-# optional
-sed -i 's|^deb http://deb.debian.org/debian|deb 
http://mirrors.huaweicloud.com/debian|g' /etc/apt/sources.list
-sed -i 's|^deb http://security.debian.org/debian-security|deb 
http://mirrors.huaweicloud.com/debian-security|g' /etc/apt/sources.list
-apt update
-apt install wget gnupg -y
-
-# add OpenResty source
-wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
-sudo apt-get -y install software-properties-common
-sudo add-apt-repository -y "deb http://openresty.org/package/debian 
$(lsb_release -sc) openresty"
-sudo apt-get update
-
-# install etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# install OpenResty and some compilation tools
-sudo apt-get install -y git openresty curl make openresty-openssl111-dev 
libpcre3 libpcre3-dev libldap2-dev
-
-# install LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# start etcd server
-nohup etcd &
-```
-
-## Mac OSX
-
-```shell
-# install OpenResty, etcd and some compilation tools
-brew install openresty/brew/openresty luarocks [email protected] etcd curl git pcre 
openldap
-
-# start etcd server
-brew services start etcd
+bash utils/install-dependencies.sh
 ```
diff --git a/docs/zh/latest/install-dependencies.md 
b/docs/zh/latest/install-dependencies.md
index 070b33e..07d27ce 100644
--- a/docs/zh/latest/install-dependencies.md
+++ b/docs/zh/latest/install-dependencies.md
@@ -22,11 +22,7 @@ title: 安装依赖
 -->
 
 - [注意](#注意)
-- [CentOS 7](#centos-7)
-- [Fedora 31 & 32](#fedora-31--32)
-- [Ubuntu 16.04 & 18.04](#ubuntu-1604--1804)
-- [Debian 9 & 10](#debian-9--10)
-- [Mac OSX](#mac-osx)
+- [安装](#安装)
 
 ## 注意
 
@@ -44,115 +40,18 @@ title: 安装依赖
 
 - OpenResty 是 APISIX 的一个依赖项,如果是第一次部署 APISIX 并且不需要使用 OpenResty 部署其他服务,可以在 
OpenResty 安装完成后停止并禁用 OpenResty,这不会影响 APISIX 的正常工作,请根据自己的业务谨慎操作。例如 
Ubuntu:`systemctl stop openresty && systemctl disable openresty`。
 
-## CentOS 7
+## 安装
 
-```shell
-# 安装 etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
+在支持的操作系统上运行以下指令即可安装 Apache APISIX dependencies。
 
-# 添加 OpenResty 源
-sudo yum install yum-utils
-sudo yum-config-manager --add-repo 
https://openresty.org/package/centos/openresty.repo
+支持的操作系统版本: CentOS 7, Fedora 31 & 32, Ubuntu 16.04 & 18.04, Debian 9 & 10, Mac 
OSX。
 
-# 安装 OpenResty 和 编译工具
-sudo yum install -y openresty curl git gcc openresty-openssl111-devel unzip 
pcre pcre-devel
-
-# 安装 LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# 开启 etcd server
-nohup etcd &
 ```
-
-## Fedora 31 & 32
-
-```shell
-# 添加 OpenResty 源
-sudo yum install yum-utils
-sudo yum-config-manager --add-repo 
https://openresty.org/package/fedora/openresty.repo
-
-# 安装 etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# 安装 OpenResty 和 编译工具
-sudo yum install -y openresty curl git gcc openresty-openssl111-devel pcre 
pcre-devel
-
-# 安装 LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# 开启 etcd server
-nohup etcd &
+curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh
 -sL | bash -
 ```
 
-## Ubuntu 16.04 & 18.04
-
-```shell
-# 添加 OpenResty 源
-wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
-sudo apt-get update
-sudo apt-get -y install software-properties-common
-sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu 
$(lsb_release -sc) main"
-sudo apt-get update
-
-# 安装 etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# 安装 OpenResty 和 编译工具
-sudo apt-get install -y git openresty curl openresty-openssl111-dev make gcc 
libpcre3 libpcre3-dev
-
-# 安装 LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
+如果你已经克隆了 Apache APISIX 仓库,在根目录运行以下指令安装 Apache APISIX dependencies。
 
-# 开启 etcd server
-nohup etcd &
 ```
-
-## Debian 9 & 10
-
-```shell
-# 可选
-sed -i 's|^deb http://deb.debian.org/debian|deb 
http://mirrors.huaweicloud.com/debian|g' /etc/apt/sources.list
-sed -i 's|^deb http://security.debian.org/debian-security|deb 
http://mirrors.huaweicloud.com/debian-security|g' /etc/apt/sources.list
-apt update
-apt install wget gnupg -y
-
-# 添加 OpenResty 源
-wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
-sudo apt-get -y install software-properties-common
-sudo add-apt-repository -y "deb http://openresty.org/package/debian 
$(lsb_release -sc) openresty"
-sudo apt-get update
-
-# 安装 etcd
-wget 
https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
-tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \
-    cd etcd-v3.4.13-linux-amd64 && \
-    sudo cp -a etcd etcdctl /usr/bin/
-
-# 安装 OpenResty 和 编译工具
-sudo apt-get install -y git openresty curl make openresty-openssl111-dev 
libpcre3 libpcre3-dev
-
-# 安装 LuaRocks
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
-
-# 开启 etcd server
-nohup etcd &
-```
-
-## Mac OSX
-
-```shell
-# 安装 OpenResty, etcd 和 编译工具
-brew install openresty/brew/openresty luarocks [email protected] etcd curl git pcre
-
-# 开启 etcd server
-brew services start etcd
+bash utils/install-dependencies.sh
 ```
diff --git a/utils/install-dependencies.sh b/utils/install-dependencies.sh
new file mode 100755
index 0000000..19a7e33
--- /dev/null
+++ b/utils/install-dependencies.sh
@@ -0,0 +1,103 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -ex
+
+# Install dependencies on centos and fedora
+function install_dependencies_with_yum() {
+    # add OpenResty source
+    sudo yum install yum-utils
+    sudo yum-config-manager --add-repo 
"https://openresty.org/package/${1}/openresty.repo";
+    sudo yum check-update
+
+    # install OpenResty and some compilation tools
+    sudo yum install -y openresty curl git gcc openresty-openssl111-devel 
unzip pcre pcre-devel libldap2-dev
+}
+
+# Install dependencies on ubuntu and debian
+function install_dependencies_with_apt() {
+    # add OpenResty source
+    sudo apt-get update
+    sudo apt-get -y install software-properties-common wget lsb-release
+    wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
+    if [[ "${1}" == "ubuntu" ]]; then
+        sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu 
$(lsb_release -sc) main"
+    elif [[ "${1}" == "debian" ]]; then
+        sudo add-apt-repository -y "deb http://openresty.org/package/debian 
$(lsb_release -sc) openresty"
+    fi
+    sudo apt-get update
+
+    # install OpenResty and some compilation tools
+    sudo apt-get install -y git openresty curl openresty-openssl111-dev make 
gcc libpcre3 libpcre3-dev libldap2-dev
+}
+
+# Install dependencies on mac osx
+function install_dependencies_on_mac_osx() {
+    # install OpenResty, etcd and some compilation tools
+    brew install openresty/brew/openresty luarocks [email protected] etcd curl git pcre 
openldap
+
+    # start etcd server
+    brew services start etcd
+}
+
+# Identify the different distributions and call the corresponding function
+function multi_distro_installation() {
+    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
+        install_dependencies_with_yum "centos"
+    elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; 
then
+        install_dependencies_with_yum "fedora"
+    elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; 
then
+        install_dependencies_with_apt "debian"
+    elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; 
then
+        install_dependencies_with_apt "ubuntu"
+    else
+        echo "Non-supported operating system version"
+    fi
+}
+
+# Install etcd
+function install_etcd() {
+    ETCD_VERSION='3.4.13'
+    wget 
https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz
+    tar -xvf etcd-v${ETCD_VERSION}-linux-amd64.tar.gz && \
+        cd etcd-v${ETCD_VERSION}-linux-amd64 && \
+        sudo cp -a etcd etcdctl /usr/bin/
+    nohup etcd &
+}
+
+# Install LuaRocks
+function install_luarocks() {
+    curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
+}
+
+# Entry
+function main() {
+    OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
+    if [[ "${OS_NAME}" == "linux" ]]; then
+        multi_distro_installation
+        install_luarocks
+        install_etcd
+    elif [[ "${OS_NAME}" == "darwin" ]]; then
+        install_dependencies_on_mac_osx
+    else
+        echo "Non-surported distribution"
+    fi
+}
+
+main

Reply via email to