Skip to content

Commit c8732dd

Browse files
committed
fix install script
1 parent f097acb commit c8732dd

File tree

5 files changed

+85
-65
lines changed

5 files changed

+85
-65
lines changed

Dockerfile

-3
This file was deleted.

install.sh

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Data Path
4-
# DataPath=/usr/local/etc/nginx-ui
4+
DataPath=/usr/local/etc/nginx-ui
55
# Bin Path
66
# BinPath=/usr/local/bin/nginx-ui
77
# Service Path
@@ -37,13 +37,13 @@ identify_the_operating_system_and_architecture() {
3737
if [[ "$(uname)" == 'Linux' ]]; then
3838
case "$(uname -m)" in
3939
'i386' | 'i686')
40-
MACHINE='32'
40+
MACHINE='386'
4141
;;
4242
'amd64' | 'x86_64')
43-
MACHINE='64'
43+
MACHINE='amd64'
4444
;;
4545
'armv8' | 'aarch64')
46-
MACHINE='arm64-v8a'
46+
MACHINE='arm64'
4747
;;
4848
*)
4949
echo "error: The architecture is not supported."
@@ -102,21 +102,22 @@ install_software() {
102102
}
103103

104104
download() {
105-
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' "$PROXY"https://github.com/0xJacky/nginx-ui/releases/latest)
105+
LATEST_RELEASE=$(curl -L -s --insecure -H 'Accept: application/json' "$PROXY"https://api.github.com/repos/0xJacky/nginx-ui/releases/latest)
106106
# shellcheck disable=SC2001
107-
LATEST_VERSION=$(echo "$LATEST_RELEASE" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
107+
LATEST_VERSION=$(echo "$LATEST_RELEASE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
108108
DOWNLOAD_LINK=$PROXY"https://github.com/0xJacky/nginx-ui/releases/download/$LATEST_VERSION/nginx-ui-linux-$MACHINE.tar.gz"
109109

110110
echo "Downloading NginxUI archive: $DOWNLOAD_LINK"
111-
if ! curl -x "${PROXY}" -R -H 'Cache-Control: no-cache' -o "$TAR_FILE" "$DOWNLOAD_LINK"; then
111+
if ! curl --insecure -R -H 'Cache-Control: no-cache' -L "$DOWNLOAD_LINK" > "$TAR_FILE"; then
112112
echo 'error: Download failed! Please check your network or try again.'
113113
return 1
114114
fi
115115
return 0
116116
}
117117

118118
decompression() {
119-
if ! unzip -q "$1" -d "$TMP_DIRECTORY"; then
119+
echo "$1"
120+
if ! tar -zxvf "$1" -C "$TMP_DIRECTORY"; then
120121
echo 'error: Nginx UI decompression failed.'
121122
"rm" -r "$TMP_DIRECTORY"
122123
echo "removed: $TMP_DIRECTORY"
@@ -131,7 +132,21 @@ install_bin() {
131132
}
132133

133134
install_service() {
134-
install -m 644 "${TMP_DIRECTORY}/nginx-ui.service" "$ServicePath"
135+
cat > "$ServicePath" << EOF
136+
[Unit]
137+
Description=Yet another WebUI for Nginx
138+
Documentation=https://github.com/0xJacky/nginx-ui
139+
After=network.target
140+
[Service]
141+
Type=simple
142+
ExecStart=/usr/local/bin/nginx-ui --config /usr/local/etc/nginx-ui/app.ini
143+
Restart=on-failure
144+
TimeoutStopSec=5
145+
KillMode=mixed
146+
[Install]
147+
WantedBy=multi-user.target
148+
EOF
149+
chmod 644 ServicePath
135150
}
136151

137152
start_nginx_ui() {
@@ -163,7 +178,9 @@ main() {
163178
# TMP
164179
TMP_DIRECTORY="$(mktemp -d)"
165180
# Tar
166-
TAR_FILE="${TMP_DIRECTORY}/nginx-ui-linux-$ARCH.tar.gz"
181+
TAR_FILE="${TMP_DIRECTORY}/nginx-ui-linux-$MACHINE.tar.gz"
182+
183+
identify_the_operating_system_and_architecture
167184

168185
install_software 'curl' 'curl'
169186

@@ -173,6 +190,8 @@ main() {
173190
install_bin
174191
install_service
175192

193+
mkdir DataPath
194+
176195
start_nginx_ui
177196
stop_nginx_ui
178197

main.go

+54-51
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,71 @@
11
package main
22

33
import (
4-
"context"
5-
"flag"
6-
"github.com/0xJacky/Nginx-UI/server/model"
7-
"github.com/0xJacky/Nginx-UI/server/router"
8-
"github.com/0xJacky/Nginx-UI/server/settings"
9-
tool2 "github.com/0xJacky/Nginx-UI/server/tool"
10-
"log"
11-
"mime"
12-
"net/http"
13-
"os/signal"
14-
"syscall"
15-
"time"
4+
"context"
5+
"flag"
6+
"github.com/0xJacky/Nginx-UI/server/model"
7+
"github.com/0xJacky/Nginx-UI/server/router"
8+
"github.com/0xJacky/Nginx-UI/server/settings"
9+
tool2 "github.com/0xJacky/Nginx-UI/server/tool"
10+
"github.com/gin-gonic/gin"
11+
"log"
12+
"mime"
13+
"net/http"
14+
"os/signal"
15+
"syscall"
16+
"time"
1617
)
1718

1819
func main() {
19-
// Create context that listens for the interrupt signal from the OS.
20-
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
21-
defer stop()
20+
// Create context that listens for the interrupt signal from the OS.
21+
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
22+
defer stop()
2223

23-
// Hack: fix wrong Content Type of .js file on some OS platforms
24-
// See https://github.com/golang/go/issues/32350
25-
_ = mime.AddExtensionType(".js", "text/javascript; charset=utf-8")
24+
// Hack: fix wrong Content Type of .js file on some OS platforms
25+
// See https://github.com/golang/go/issues/32350
26+
_ = mime.AddExtensionType(".js", "text/javascript; charset=utf-8")
2627

27-
var confPath string
28-
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
29-
flag.Parse()
28+
var confPath string
29+
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
30+
flag.Parse()
3031

31-
settings.Init(confPath)
32-
log.Printf("nginx config dir path: %s", tool2.GetNginxConfPath(""))
33-
if "" != settings.ServerSettings.JwtSecret {
34-
model.Init()
35-
go tool2.AutoCert()
36-
}
32+
gin.SetMode(settings.ServerSettings.RunMode)
33+
34+
settings.Init(confPath)
35+
log.Printf("nginx config dir path: %s", tool2.GetNginxConfPath(""))
36+
if "" != settings.ServerSettings.JwtSecret {
37+
model.Init()
38+
go tool2.AutoCert()
39+
}
3740

38-
srv := &http.Server{
39-
Addr: ":" + settings.ServerSettings.HttpPort,
40-
Handler: router.InitRouter(),
41-
}
41+
srv := &http.Server{
42+
Addr: ":" + settings.ServerSettings.HttpPort,
43+
Handler: router.InitRouter(),
44+
}
4245

43-
// Initializing the server in a goroutine so that
44-
// it won't block the graceful shutdown handling below
45-
go func() {
46-
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
47-
log.Fatalf("listen: %s\n", err)
48-
}
49-
}()
46+
// Initializing the server in a goroutine so that
47+
// it won't block the graceful shutdown handling below
48+
go func() {
49+
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
50+
log.Fatalf("listen: %s\n", err)
51+
}
52+
}()
5053

51-
// Listen for the interrupt signal.
52-
<-ctx.Done()
54+
// Listen for the interrupt signal.
55+
<-ctx.Done()
5356

54-
// Restore default behavior on the interrupt signal and notify user of shutdown.
55-
stop()
56-
log.Println("shutting down gracefully, press Ctrl+C again to force")
57+
// Restore default behavior on the interrupt signal and notify user of shutdown.
58+
stop()
59+
log.Println("shutting down gracefully, press Ctrl+C again to force")
5760

58-
// The context is used to inform the server it has 5 seconds to finish
59-
// the request it is currently handling
60-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
61-
defer cancel()
62-
if err := srv.Shutdown(ctx); err != nil {
63-
log.Fatal("Server forced to shutdown: ", err)
64-
}
61+
// The context is used to inform the server it has 5 seconds to finish
62+
// the request it is currently handling
63+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
64+
defer cancel()
65+
if err := srv.Shutdown(ctx); err != nil {
66+
log.Fatal("Server forced to shutdown: ", err)
67+
}
6568

66-
log.Println("Server exiting")
69+
log.Println("Server exiting")
6770

6871
}

nginx-ui

-25.6 MB
Binary file not shown.

nginx-ui.service

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
Description=Yet another WebUI for Nginx
33
Documentation=https://github.com/0xJacky/nginx-ui
44
After=network.target
5-
65
[Service]
76
Type=simple
87
ExecStart=/usr/local/bin/nginx-ui --config /usr/local/etc/nginx-ui/app.ini
98
Restart=on-failure
109
TimeoutStopSec=5
1110
KillMode=mixed
11+
[Install]
12+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)