-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
302 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/gek64/gek/gApp" | ||
"runtime" | ||
"embed" | ||
"errors" | ||
"net/url" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
type CC struct { | ||
Toolbox []string `json:"toolbox"` | ||
Application Application `json:"application"` | ||
Config Config `json:"config"` | ||
Service Service `json:"service"` | ||
} | ||
|
||
type Application struct { | ||
Repo string `json:"repo"` | ||
RepoList map[string]string `json:"repoList"` | ||
File []string `json:"file"` | ||
Location string `json:"location"` | ||
UninstallDeleteLocation bool `json:"uninstallDeleteLocation"` | ||
} | ||
type Config struct { | ||
Location string `json:"location"` | ||
UninstallDeleteLocation bool `json:"uninstallDeleteLocation"` | ||
} | ||
type Service struct { | ||
Name string `json:"name"` | ||
Content string `json:"content"` | ||
} | ||
|
||
// 存储配置文件及服务文件 | ||
// | ||
//go:embed configs/* | ||
//go:embed service/* | ||
var container embed.FS | ||
|
||
func initConf() (err error) { | ||
var configBytes []byte | ||
var configPath string | ||
|
||
// 检查系统中的init system | ||
_, initSystemBin := gApp.CheckInitSystem() | ||
|
||
switch runtime.GOOS { | ||
case gApp.SupportedOS[0]: | ||
switch initSystemBin { | ||
case gApp.InitSystem["systemd"]: | ||
configPath = "configs/linux_systemd.json" | ||
case gApp.InitSystem["openrc"]: | ||
configPath = "configs/linux_openrc.json" | ||
default: | ||
var supportInitSystemListString string | ||
for key := range gApp.InitSystem { | ||
supportInitSystemListString = supportInitSystemListString + ", " + key | ||
} | ||
return fmt.Errorf("no supported init system found, currently only %s are supported", supportInitSystemListString) | ||
} | ||
case gApp.SupportedOS[1]: | ||
switch initSystemBin { | ||
case gApp.InitSystem["rc.d"]: | ||
configPath = "configs/freebsd_rcd.json" | ||
return fmt.Errorf("freebsd does not yet support") | ||
default: | ||
var supportInitSystemListString string | ||
for key := range gApp.InitSystem { | ||
supportInitSystemListString = supportInitSystemListString + ", " + key | ||
} | ||
return fmt.Errorf("no supported init system found, currently only %s are supported", supportInitSystemListString) | ||
} | ||
} | ||
|
||
configBytes, err = container.ReadFile(configPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = json.Unmarshal(configBytes, &cc) | ||
if err != nil { | ||
return err | ||
} | ||
func GetDownloadURL() (downloadURL string, err error) { | ||
baseURL := "https://github.com/userdocs/qbittorrent-nox-static/releases/latest/download/" | ||
assetName := "" | ||
switch runtime.GOARCH { | ||
case "amd64": | ||
assetName = "x86_64-qbittorrent-nox" | ||
case "386": | ||
assetName = "x86-qbittorrent-nox" | ||
case "arm": | ||
assetName = "armv7-qbittorrent-nox" | ||
case "arm64": | ||
assetName = "aarch64-qbittorrent-nox" | ||
} | ||
return url.JoinPath(baseURL, assetName) | ||
} | ||
|
||
return nil | ||
func GetService() (initSystem string, serviceContent []byte, err error) { | ||
serviceFile := "" | ||
// systemd | ||
_, err = exec.LookPath("systemctl") | ||
if err == nil { | ||
serviceFile = "service/qbittorrent.service" | ||
initSystem = "systemd" | ||
} | ||
// alpine openrc | ||
_, err = exec.LookPath("openrc") | ||
if err == nil { | ||
serviceFile = "service/qbittorrent.openrc" | ||
initSystem = "openrc" | ||
} | ||
// freebsd rc.d | ||
_, err = exec.LookPath("rcorder") | ||
if err == nil { | ||
serviceFile = "service/qbittorrent.rcd" | ||
initSystem = "rc.d" | ||
} | ||
|
||
// 找不到初始化系统返回错误 | ||
if initSystem == "" { | ||
return "", nil, errors.New("init system not found") | ||
} | ||
|
||
// 读取文件并返回文件内容 | ||
bytes, err := container.ReadFile(serviceFile) | ||
if err != nil { | ||
return initSystem, nil, err | ||
} | ||
return initSystem, bytes, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.