Selaa lähdekoodia

add install.sh

0xJacky 3 vuotta sitten
vanhempi
commit
2b3db0387d
9 muutettua tiedostoa jossa 205 lisäystä ja 11 poistoa
  1. 1 0
      .gitignore
  2. 3 0
      Dockerfile
  3. 4 4
      frontend/src/views/dashboard/DashBoard.vue
  4. 1 5
      frontend/version.json
  5. 1 1
      go.mod
  6. 4 0
      go.sum
  7. 190 0
      install.sh
  8. BIN
      nginx-ui
  9. 1 1
      nginx-ui.service

+ 1 - 0
.gitignore

@@ -5,3 +5,4 @@ tmp
 node_modules
 app.ini
 dist
+*.exe

+ 3 - 0
Dockerfile

@@ -0,0 +1,3 @@
+FROM ubuntu
+WORKDIR /app
+EXPOSE 9000

+ 4 - 4
frontend/src/views/dashboard/DashBoard.vue

@@ -121,9 +121,9 @@ export default {
         this.websocket.onmessage = this.wsOnMessage
         this.websocket.onopen = this.wsOpen
         const time = new Date()
-        for (let i = 0; i < 120; i++) {
-            this.cpu_analytic.datasets[0].data.push({x: time, y: 0})
-            this.cpu_analytic.datasets[1].data.push({x: time, y: 0})
+        for (let i = 200; i > 0; i--) {
+            this.cpu_analytic.datasets[0].data.push({x: time-i*1000, y: 0})
+            this.cpu_analytic.datasets[1].data.push({x: time-i*1000, y: 0})
         }
     },
     destroyed() {
@@ -142,7 +142,7 @@ export default {
                 .push({x: time, y: r.cpu_user})
             this.cpu_analytic.datasets[1].data
                 .push({x: time, y: this.cpu})
-            if (this.cpu_analytic.datasets[0].data.length > 120) {
+            if (this.cpu_analytic.datasets[0].data.length > 200) {
                 this.cpu_analytic.datasets[0].data.shift()
                 this.cpu_analytic.datasets[1].data.shift()
             }

+ 1 - 5
frontend/version.json

@@ -1,5 +1 @@
-{
-    "version": "1.1.0",
-    "build_id": 8,
-    "total_build": 25
-}
+{"version":"1.1.0","build_id":9,"total_build":26}

+ 1 - 1
go.mod

@@ -23,7 +23,7 @@ require (
 )
 
 require (
-	github.com/0xJacky/pofile v0.0.0-20220219022008-df96416310e5 // indirect
+	github.com/0xJacky/pofile v0.0.1 // indirect
 	github.com/StackExchange/wmi v1.2.1 // indirect
 	github.com/cenkalti/backoff/v4 v4.1.0 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect

+ 4 - 0
go.sum

@@ -27,6 +27,10 @@ github.com/0xJacky/pofile v0.0.0-20220216140954-bc565a3feb80 h1:qKPxkbGoP/vVxN1V
 github.com/0xJacky/pofile v0.0.0-20220216140954-bc565a3feb80/go.mod h1:gSDWobvodMtvwh7FE/F999AQoCwBoXgzyGffYFX9nKA=
 github.com/0xJacky/pofile v0.0.0-20220219022008-df96416310e5 h1:NEsbh2Wez8+0Y72hbVQPPhyIkmc1RAgWOWbcISRUxEs=
 github.com/0xJacky/pofile v0.0.0-20220219022008-df96416310e5/go.mod h1:gSDWobvodMtvwh7FE/F999AQoCwBoXgzyGffYFX9nKA=
+github.com/0xJacky/pofile v0.0.0-20220219101524-60ce48e4de23 h1:nqaxj4ZYzLZzhFQeX1ZrXEBz0haUu7PypGFhQbQfDX0=
+github.com/0xJacky/pofile v0.0.0-20220219101524-60ce48e4de23/go.mod h1:gSDWobvodMtvwh7FE/F999AQoCwBoXgzyGffYFX9nKA=
+github.com/0xJacky/pofile v0.0.1 h1:hVRaw6ZHkajSMAuP58WMDTvGF8+OF297jpAchFK/4rQ=
+github.com/0xJacky/pofile v0.0.1/go.mod h1:gSDWobvodMtvwh7FE/F999AQoCwBoXgzyGffYFX9nKA=
 github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
 github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg=
 github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=

+ 190 - 0
install.sh

@@ -0,0 +1,190 @@
+#!/usr/bin/env bash
+
+# Data Path
+# DataPath=/usr/local/etc/nginx-ui
+# Bin Path
+# BinPath=/usr/local/bin/nginx-ui
+# Service Path
+ServicePath=/usr/lib/systemd/system/nginx-ui.service
+PROXY=""
+
+## Demo function for processing parameters
+judgment_parameters() {
+    while [[ "$#" -gt '0' ]]; do
+        case "$1" in
+        '-p' | '--proxy')
+            if [[ -z "$2" ]]; then
+                echo "error: Please specify the proxy server address."
+                exit 1
+            fi
+            PROXY="$2"
+            shift
+            ;;
+        esac
+        shift
+    done
+}
+
+check_if_running_as_root() {
+    # If you want to run as another user, please modify $EUID to be owned by this user
+    if [[ "$EUID" -ne '0' ]]; then
+        echo "error: You must run this script as root!"
+        exit 1
+    fi
+}
+
+identify_the_operating_system_and_architecture() {
+    if [[ "$(uname)" == 'Linux' ]]; then
+        case "$(uname -m)" in
+        'i386' | 'i686')
+            MACHINE='32'
+            ;;
+        'amd64' | 'x86_64')
+            MACHINE='64'
+            ;;
+        'armv8' | 'aarch64')
+            MACHINE='arm64-v8a'
+            ;;
+        *)
+            echo "error: The architecture is not supported."
+            exit 1
+            ;;
+        esac
+        if [[ ! -f '/etc/os-release' ]]; then
+            echo "error: Don't use outdated Linux distributions."
+            exit 1
+        fi
+        # Do not combine this judgment condition with the following judgment condition.
+        ## Be aware of Linux distribution like Gentoo, which kernel supports switch between Systemd and OpenRC.
+        if [[ -f /.dockerenv ]] || grep -q 'docker\|lxc' /proc/1/cgroup && [[ "$(type -P systemctl)" ]]; then
+            true
+        elif [[ -d /run/systemd/system ]] || grep -q systemd <(ls -l /sbin/init); then
+            true
+        else
+            echo "error: Only Linux distributions using systemd are supported."
+            exit 1
+        fi
+        if [[ "$(type -P apt)" ]]; then
+            PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install'
+            # PACKAGE_MANAGEMENT_REMOVE='apt purge'
+        elif [[ "$(type -P dnf)" ]]; then
+            PACKAGE_MANAGEMENT_INSTALL='dnf -y install'
+            # PACKAGE_MANAGEMENT_REMOVE='dnf remove'
+        elif [[ "$(type -P yum)" ]]; then
+            PACKAGE_MANAGEMENT_INSTALL='yum -y install'
+            # PACKAGE_MANAGEMENT_REMOVE='yum remove'
+        elif [[ "$(type -P zypper)" ]]; then
+            PACKAGE_MANAGEMENT_INSTALL='zypper install -y --no-recommends'
+            # PACKAGE_MANAGEMENT_REMOVE='zypper remove'
+        elif [[ "$(type -P pacman)" ]]; then
+            PACKAGE_MANAGEMENT_INSTALL='pacman -Syu --noconfirm'
+            # PACKAGE_MANAGEMENT_REMOVE='pacman -Rsn'
+        else
+            echo "error: The script does not support the package manager in this operating system."
+            exit 1
+        fi
+    else
+        echo "error: This operating system is not supported."
+        exit 1
+    fi
+}
+
+install_software() {
+    package_name="$1"
+    file_to_detect="$2"
+    type -P "$file_to_detect" >/dev/null 2>&1 && return
+    if ${PACKAGE_MANAGEMENT_INSTALL} "$package_name"; then
+        echo "info: $package_name is installed."
+    else
+        echo "error: Installation of $package_name failed, please check your network."
+        exit 1
+    fi
+}
+
+download() {
+    LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' "$PROXY"https://github.com/0xJacky/nginx-ui/releases/latest)
+    # shellcheck disable=SC2001
+    LATEST_VERSION=$(echo "$LATEST_RELEASE" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
+    DOWNLOAD_LINK=$PROXY"https://github.com/0xJacky/nginx-ui/releases/download/$LATEST_VERSION/nginx-ui-linux-$MACHINE.tar.gz"
+
+    echo "Downloading NginxUI archive: $DOWNLOAD_LINK"
+    if ! curl -x "${PROXY}" -R -H 'Cache-Control: no-cache' -o "$TAR_FILE" "$DOWNLOAD_LINK"; then
+        echo 'error: Download failed! Please check your network or try again.'
+        return 1
+    fi
+    return 0
+}
+
+decompression() {
+    if ! unzip -q "$1" -d "$TMP_DIRECTORY"; then
+        echo 'error: Nginx UI decompression failed.'
+        "rm" -r "$TMP_DIRECTORY"
+        echo "removed: $TMP_DIRECTORY"
+        exit 1
+    fi
+    echo "info: Extract the Nginx UI package to $TMP_DIRECTORY and prepare it for installation."
+}
+
+install_bin() {
+    NAME="nginx-ui"
+    install -m 755 "${TMP_DIRECTORY}/$NAME" "/usr/local/bin/$NAME"
+}
+
+install_service() {
+    install -m 644 "${TMP_DIRECTORY}/nginx-ui.service" "$ServicePath"
+}
+
+start_nginx_ui() {
+    if [[ -f ServicePath ]]; then
+        systemctl start nginx-ui
+        sleep 1s
+        if systemctl -q is-active nginx-ui; then
+            echo 'info: Start the Nginx UI service.'
+        else
+            echo 'error: Failed to start the Nginx UI service.'
+            exit 1
+        fi
+    fi
+}
+
+stop_nginx_ui() {
+    if ! systemctl stop nginx-ui; then
+        echo 'error: Failed to stop the Nginx UI service.'
+        exit 1
+    fi
+    echo 'info: Nginx UI service Stopped.'
+}
+
+main() {
+    check_if_running_as_root
+
+    judgment_parameters "$@"
+
+    # TMP
+    TMP_DIRECTORY="$(mktemp -d)"
+    # Tar
+    TAR_FILE="${TMP_DIRECTORY}/nginx-ui-linux-$ARCH.tar.gz"
+
+    install_software 'curl' 'curl'
+
+    download
+    decompression "$TAR_FILE"
+
+    install_bin
+    install_service
+
+    start_nginx_ui
+    stop_nginx_ui
+
+    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
+        echo "warning: Failed to enable and start the Nginx UI service."
+    fi
+}
+
+main "$@"

BIN
nginx-ui


+ 1 - 1
nginx-ui.service

@@ -5,7 +5,7 @@ After=network.target
 
 [Service]
 Type=simple
-ExecStart=/usr/local/bin/nginx-ui -d /usr/local/etc/nginx-ui/app.ini
+ExecStart=/usr/local/bin/nginx-ui --config /usr/local/etc/nginx-ui/app.ini
 Restart=on-failure
 TimeoutStopSec=5
 KillMode=mixed