Browse Source

feat(install.sh): add version channel option

Jacky 1 month ago
parent
commit
e5d1cbac84

+ 24 - 1
docs/guide/install-script-linux.md

@@ -22,14 +22,37 @@ install.sh install [OPTIONS]
 | `-l, --local <file>`  | Install Nginx UI from a local file (`string`)                                                                   |
 | `-p, --proxy <url>`   | Download through a proxy server (`string`)<br/>e.g., `-p http://127.0.0.1:8118` or `-p socks5://127.0.0.1:1080` |
 | `-r, --reverse-proxy` | Download through a reverse proxy server (`string`)<br/>e.g., `-r https://cloud.nginxui.com/`                          |
+| `-c, --channel <channel>` | Specify the version channel (`string`)<br/>Available channels: `stable` (default), `prerelease`, `dev`
 
+#### Version Channels
+
+| Channel      | Description                                                                                          |
+|--------------|------------------------------------------------------------------------------------------------------|
+| `stable`     | Latest stable release (default) - Recommended for production use                                     |
+| `prerelease` | Latest prerelease version - Contains new features that are being tested before stable release       |
+| `dev`        | Latest development build from dev branch - Contains the newest features but may be unstable         |
 
 ### Quick Usage
 
-```shell
+::: code-group
+
+```shell [Stable (Default)]
+# Install the latest stable version
 bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install
 ```
 
+```shell [Prerelease]
+# Install the latest prerelease version
+bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel prerelease
+```
+
+```shell [Development]
+# Install the latest development build
+bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel dev
+```
+
+:::
+
 The default listening port is `9000`, and the default HTTP Challenge port is `9180`.
 If there is a port conflict, please modify `/usr/local/etc/nginx-ui/app.ini` manually,
 then use `systemctl restart nginx-ui` to restart the Nginx UI service.

+ 25 - 1
docs/zh_CN/guide/install-script-linux.md

@@ -21,13 +21,37 @@ install.sh install [OPTIONS]
 | `-l, --local <file>`  | 从本地文件安装 Nginx UI (`string`)                                                           |
 | `-p, --proxy <url>`   | 通过代理服务器下载 (`string`)<br/>例如:`-p http://127.0.0.1:8118` 或 `-p socks5://127.0.0.1:1080` |
 | `-r, --reverse-proxy` | 通过反向代理服务器下载 (`string`)<br/>例如:`-r https://cloud.nginxui.com/`                               |
+| `-c, --channel <channel>` | 指定版本通道 (`string`)<br/>可用通道:`stable`(默认)、`prerelease`、`dev`
+
+#### 版本通道
+
+| 通道         | 描述                                                      |
+|------------|-----------------------------------------------------------|
+| `stable`   | 最新稳定版本(默认) - 推荐用于生产环境                                |
+| `prerelease` | 最新预发布版本 - 包含正在测试的新功能,将在稳定版本发布前进行验证                |
+| `dev`      | 来自 dev 分支的最新开发构建 - 包含最新功能但可能不稳定                   |
 
 ### 快速使用
 
-```shell
+::: code-group
+
+```shell [稳定版(默认)]
+# 安装最新稳定版本
 bash -c "$(curl -L https://cloud.nginxui.com/https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install -r https://cloud.nginxui.com/
 ```
 
+```shell [预发布版]
+# 安装最新预发布版本
+bash -c "$(curl -L https://cloud.nginxui.com/https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel prerelease -r https://cloud.nginxui.com/
+```
+
+```shell [开发版]
+# 安装最新开发构建
+bash -c "$(curl -L https://cloud.nginxui.com/https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel dev -r https://cloud.nginxui.com/
+```
+
+:::
+
 一键安装脚本默认设置的监听端口为 `9000`,HTTP Challenge 端口默认为 `9180`。如果有端口冲突,请手动修改 `/usr/local/etc/nginx-ui/app.ini`,
 并使用 `systemctl restart nginx-ui` 重启 Nginx UI 服务。更多有关信息,请查看 [配置参考](./config-server)。
 

+ 25 - 2
docs/zh_TW/guide/install-script-linux.md

@@ -21,14 +21,37 @@ install.sh install [OPTIONS]
 | `-l, --local <file>`  | 從本機檔案安裝 Nginx UI (`string`)                                                           |
 | `-p, --proxy <url>`   | 透過代理伺服器下載 (`string`)<br/>例如:`-p http://127.0.0.1:8118` 或 `-p socks5://127.0.0.1:1080` |
 | `-r, --reverse-proxy` | 透過反向代理伺服器下載 (`string`)<br/>例如:`-r https://cloud.nginxui.com/`                               |
+| `-c, --channel <channel>` | 指定版本通道 (`string`)<br/>可用通道:`stable`(預設)、`prerelease`、`dev`
 
+#### 版本通道
+
+| 通道         | 說明                                                      |
+|------------|-----------------------------------------------------------|
+| `stable`   | 最新穩定版本(預設) - 建議用於正式環境                                |
+| `prerelease` | 最新預發布版本 - 包含正在測試的新功能,將在穩定版本發布前進行驗證                |
+| `dev`      | 來自 dev 分支的最新開發構建 - 包含最新功能但可能不穩定                   |
 
 ### 快速使用
 
-```shell
+::: code-group
+
+```shell [穩定版(預設)]
+# 安裝最新穩定版本
 bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install
 ```
 
+```shell [預發布版]
+# 安裝最新預發布版本
+bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel prerelease
+```
+
+```shell [開發版]
+# 安裝最新開發構建
+bash -c "$(curl -L https://raw.githubusercontent.com/0xJacky/nginx-ui/main/install.sh)" @ install --channel dev
+```
+
+:::
+
 安裝指令碼預設的監聽連接埠為 `9000`,HTTP Challenge 連接埠預設為 `9180`。如果出現連接埠衝突請修改 `/usr/local/etc/nginx-ui/app.ini`,
 並使用 `systemctl restart nginx-ui` 重啟 Nginx UI 守護行程。更多有關資訊,請檢視 [設定參考](./config-server)。
 
@@ -166,4 +189,4 @@ rc-update add nginx-ui default
 /etc/init.d/nginx-ui status
 ```
 
-:::
+:::

+ 149 - 30
install.sh

@@ -17,6 +17,9 @@ SERVICE_TYPE=''
 # Latest release version
 RELEASE_LATEST=''
 
+# Version channel (stable, prerelease, dev)
+VERSION_CHANNEL='stable'
+
 # install
 INSTALL='0'
 
@@ -92,6 +95,18 @@ judgment_parameters() {
             PROXY="$2"
             shift
             ;;
+        '-c' | '--channel')
+            if [[ -z "$2" ]]; then
+                echo -e "${FontRed}error: Please specify the version channel (stable, prerelease, dev).${FontSuffix}"
+                exit 1
+            fi
+            if [[ "$2" != "stable" && "$2" != "prerelease" && "$2" != "dev" ]]; then
+                echo -e "${FontRed}error: Invalid channel. Must be one of: stable, prerelease, dev.${FontSuffix}"
+                exit 1
+            fi
+            VERSION_CHANNEL="$2"
+            shift
+            ;;
         '--purge')
             PURGE='1'
             ;;
@@ -231,12 +246,43 @@ install_software() {
 get_latest_version() {
     # Get latest release version number
     local latest_release
-    if ! latest_release=$(curl_with_retry -sS -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"); then
-        echo -e "${FontRed}error: Failed to get release list, please check your network.${FontSuffix}"
-        exit 1
+    if [[ "$VERSION_CHANNEL" == "stable" ]]; then
+        if ! latest_release=$(curl_with_retry -sS -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"); then
+            echo -e "${FontRed}error: Failed to get release list, please check your network.${FontSuffix}"
+            exit 1
+        fi
+        RELEASE_LATEST="$(echo "$latest_release" | sed 'y/,/\n/' | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
+    elif [[ "$VERSION_CHANNEL" == "prerelease" ]]; then
+        if ! latest_release=$(curl_with_retry -sS -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/0xJacky/nginx-ui/releases"); then
+            echo -e "${FontRed}error: Failed to get release list, please check your network.${FontSuffix}"
+            exit 1
+        fi
+        # Find the latest prerelease version
+        RELEASE_LATEST="$(echo "$latest_release" | sed 'y/,/\n/' | grep -B5 -A5 '"prerelease": true' | grep '"tag_name":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')"
+        if [[ -z "$RELEASE_LATEST" ]]; then
+            echo -e "${FontYellow}warning: No prerelease version found, falling back to stable version.${FontSuffix}"
+            # Fallback to stable release
+            if ! latest_release=$(curl_with_retry -sS -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"); then
+                echo -e "${FontRed}error: Failed to get release list, please check your network.${FontSuffix}"
+                exit 1
+            fi
+            RELEASE_LATEST="$(echo "$latest_release" | sed 'y/,/\n/' | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
+        fi
+    elif [[ "$VERSION_CHANNEL" == "dev" ]]; then
+        # Get latest dev commit info
+        local dev_commit
+        if ! dev_commit=$(curl_with_retry -sS -H "Accept: application/vnd.github.v3+json" "${RPROXY}https://api.github.com/repos/0xJacky/nginx-ui/commits/dev?per_page=1"); then
+            echo -e "${FontRed}error: Failed to get dev commit info, please check your network.${FontSuffix}"
+            exit 1
+        fi
+        local commit_sha="$(echo "$dev_commit" | sed 'y/,/\n/' | grep '"sha":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')"
+        if [[ -z "$commit_sha" ]]; then
+            echo -e "${FontRed}error: Failed to get dev commit SHA.${FontSuffix}"
+            exit 1
+        fi
+        RELEASE_LATEST="sha-${commit_sha:0:7}"
     fi
 
-    RELEASE_LATEST="$(echo "$latest_release" | sed 'y/,/\n/' | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
     if [[ -z "$RELEASE_LATEST" ]]; then
         if echo "$latest_release" | grep -q "API rate limit exceeded"; then
             echo -e "${FontRed}error: github API rate limit exceeded${FontSuffix}"
@@ -251,7 +297,13 @@ get_latest_version() {
 
 download_nginx_ui() {
     local download_link
-    download_link="${RPROXY}https://github.com/0xJacky/nginx-ui/releases/download/$RELEASE_LATEST/nginx-ui-linux-$MACHINE.tar.gz"
+    if [[ "$VERSION_CHANNEL" == "dev" ]]; then
+        # For dev builds, use the CloudflareWorkerAPI dev-builds endpoint
+        download_link="${RPROXY}https://cloud.nginxui.com/dev-builds/nginx-ui-linux-$MACHINE.tar.gz"
+    else
+        # For stable and prerelease versions
+        download_link="${RPROXY}https://github.com/0xJacky/nginx-ui/releases/download/$RELEASE_LATEST/nginx-ui-linux-$MACHINE.tar.gz"
+    fi
 
     echo "Downloading Nginx UI archive: $download_link"
     if ! curl_with_retry -R -H 'Cache-Control: no-cache' -L -o "$TAR_FILE" "$download_link"; then
@@ -415,6 +467,73 @@ start_nginx_ui() {
     fi
 }
 
+check_nginx_ui_status() {
+    if [[ "$SERVICE_TYPE" == "systemd" ]]; then
+        if systemctl list-unit-files | grep -qw 'nginx-ui'; then
+            if systemctl -q is-active nginx-ui; then
+                return 0  # running
+            else
+                return 1  # not running
+            fi
+        else
+            return 2  # not installed
+        fi
+    elif [[ "$SERVICE_TYPE" == "openrc" ]]; then
+        if [[ -f "$OpenRCPath" ]]; then
+            if rc-service nginx-ui status | grep -q "started"; then
+                return 0  # running
+            else
+                return 1  # not running
+            fi
+        else
+            return 2  # not installed
+        fi
+    else
+        # init.d
+        if [[ -f "$InitPath" ]]; then
+            if $InitPath status >/dev/null 2>&1; then
+                return 0  # running
+            else
+                return 1  # not running
+            fi
+        else
+            return 2  # not installed
+        fi
+    fi
+}
+
+restart_nginx_ui() {
+    if [[ "$SERVICE_TYPE" == "systemd" ]]; then
+        systemctl restart nginx-ui
+        sleep 1s
+        if systemctl -q is-active nginx-ui; then
+            echo 'info: Restart the Nginx UI service.'
+        else
+            echo -e "${FontRed}error: Failed to restart the Nginx UI service.${FontSuffix}"
+            exit 1
+        fi
+    elif [[ "$SERVICE_TYPE" == "openrc" ]]; then
+        rc-service nginx-ui restart
+        sleep 1s
+        if rc-service nginx-ui status | grep -q "started"; then
+            echo 'info: Restart the Nginx UI service.'
+        else
+            echo -e "${FontRed}error: Failed to restart the Nginx UI service.${FontSuffix}"
+            exit 1
+        fi
+    else
+        # init.d
+        $InitPath restart
+        sleep 1s
+        if $InitPath status >/dev/null 2>&1; then
+            echo 'info: Restart the Nginx UI service.'
+        else
+            echo -e "${FontRed}error: Failed to restart the Nginx UI service.${FontSuffix}"
+            exit 1
+        fi
+    fi
+}
+
 stop_nginx_ui() {
     if [[ "$SERVICE_TYPE" == "systemd" ]]; then
         if ! systemctl stop nginx-ui; then
@@ -544,6 +663,10 @@ show_help() {
     echo '    -l, --local               Install Nginx UI from a local file'
     echo '    -p, --proxy               Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
     echo '    -r, --reverse-proxy       Download through a reverse proxy server, e.g., -r https://cloud.nginxui.com/'
+    echo '    -c, --channel             Specify the version channel (stable, prerelease, dev)'
+    echo '                              stable: Latest stable release (default)'
+    echo '                              prerelease: Latest prerelease version'
+    echo '                              dev: Latest development build from dev branch'
     echo '  remove:'
     echo '    --purge                   Remove all the Nginx UI files, include logs, configs, etc'
     exit 0
@@ -574,7 +697,7 @@ main() {
         decompression "$LOCAL_FILE"
     else
         get_latest_version
-        echo "info: Installing Nginx UI $RELEASE_LATEST for $(uname -m)"
+        echo "info: Installing Nginx UI $RELEASE_LATEST ($VERSION_CHANNEL channel) for $(uname -m)"
         if ! download_nginx_ui; then
             "rm" -r "$TMP_DIRECTORY"
             echo "removed: $TMP_DIRECTORY"
@@ -583,25 +706,6 @@ main() {
         decompression "$TAR_FILE"
     fi
 
-    # Determine if nginx-ui is running
-    NGINX_UI_RUNNING='0'
-    if [[ "$SERVICE_TYPE" == "systemd" && $(systemctl list-unit-files | grep -qw 'nginx-ui') ]]; then
-        if [[ -n "$(pidof nginx-ui)" ]]; then
-            stop_nginx_ui
-            NGINX_UI_RUNNING='1'
-        fi
-    elif [[ "$SERVICE_TYPE" == "openrc" && -f "$OpenRCPath" ]]; then
-        if rc-service nginx-ui status | grep -q "started"; then
-            stop_nginx_ui
-            NGINX_UI_RUNNING='1'
-        fi
-    elif [[ "$SERVICE_TYPE" == "initd" && -f "$InitPath" ]]; then
-        if [[ -n "$(pidof nginx-ui)" ]]; then
-            stop_nginx_ui
-            NGINX_UI_RUNNING='1'
-        fi
-    fi
-
     install_bin
     echo 'installed: /usr/local/bin/nginx-ui'
 
@@ -620,14 +724,31 @@ main() {
 
     install_config
 
-    if [[ "$NGINX_UI_RUNNING" -eq '1' ]]; then
+    # Check nginx-ui service status and decide whether to start or restart
+    check_nginx_ui_status
+    service_status=$?
+    
+    if [[ $service_status -eq 0 ]]; then
+        # Service is running, restart it
+        echo "info: Nginx UI service is running, restarting..."
+        restart_nginx_ui
+    elif [[ $service_status -eq 1 ]]; then
+        # Service is installed but not running, start it
+        echo "info: Nginx UI service is not running, starting..."
         start_nginx_ui
+        # Enable service for auto-start
+        if [[ "$SERVICE_TYPE" == "systemd" ]]; then
+            systemctl enable nginx-ui
+        elif [[ "$SERVICE_TYPE" == "openrc" ]]; then
+            rc-update add nginx-ui default
+        fi
     else
+        # Service is not installed, start it and enable
+        echo "info: Installing and starting Nginx UI service..."
         if [[ "$SERVICE_TYPE" == "systemd" ]]; then
             systemctl start nginx-ui
             systemctl enable nginx-ui
             sleep 1s
-
             if systemctl -q is-active nginx-ui; then
                 echo "info: Start and enable the Nginx UI service."
             else
@@ -637,8 +758,7 @@ main() {
             rc-service nginx-ui start
             rc-update add nginx-ui default
             sleep 1s
-
-            if rc-service nginx-ui status | grep -q "running"; then
+            if rc-service nginx-ui status | grep -q "started"; then
                 echo "info: Started and added the Nginx UI service to default runlevel."
             else
                 echo -e "${FontYellow}warning: Failed to start the Nginx UI service.${FontSuffix}"
@@ -646,7 +766,6 @@ main() {
         elif [[ "$SERVICE_TYPE" == "initd" ]]; then
             $InitPath start
             sleep 1s
-
             if $InitPath status >/dev/null 2>&1; then
                 echo "info: Started the Nginx UI service."
             else