Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gek64 committed May 29, 2024
1 parent 8abe3b4 commit 6e6ebe0
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 428 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@
## Usage

```
Usage:
qbtsh [Commands]
Command:
-install : Install
-uninstall : Uninstall
-update : Update
-reload : Reload
-h : Show help
-v : Show version
Example:
1) qbtsh -install : Install qBittorrent-nox
3) qbtsh -update : Update qBittorrent-nox
5) qbtsh -uninstall : Remove config,cache and uninstall qBittorrent-nox
6) qbtsh -reload : Reload service
NAME:
qbtsh.exe - qBittorrent-nox quick install tool
USAGE:
qbtsh.exe [global options] command
VERSION:
v2.00
COMMANDS:
install, i Install qBittorrent-nox
uninstall, u Remove config,cache and uninstall qBittorrent-nox
update, up Update qBittorrent-nox
reload, r Reload service
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

## Install
Expand All @@ -59,6 +64,7 @@ chmod +x /usr/local/bin/qbtsh
git clone https://github.com/gek64/qbtsh.git
# Compile the source code
cd qbtsh
export CGO_ENABLED=0
go build -v -trimpath -ldflags "-s -w"
```

Expand Down
34 changes: 20 additions & 14 deletions README_chs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@
## 使用说明

```
使用说明:
qbtsh [指令]
指令:
-install : 安装
-uninstall : 卸载
-update : 升级
-reload : 重载
-h : 显示帮助
-v : 显示版本
实例:
1) qbtsh -install : 安装 qBittorrent-nox
3) qbtsh -update : 升级 qBittorrent-nox
5) qbtsh -uninstall : 卸载 qBittorrent-nox,并移除应用配置文件及应用缓存
6) qbtsh -reload : 重载服务
NAME:
qbtsh.exe - qBittorrent-nox quick install tool
USAGE:
qbtsh.exe [global options] command
VERSION:
v2.00
COMMANDS:
install, i Install qBittorrent-nox
uninstall, u Remove config,cache and uninstall qBittorrent-nox
update, up Update qBittorrent-nox
reload, r Reload service
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

## 安装说明
Expand All @@ -56,6 +61,7 @@ chmod +x /usr/local/bin/qbtsh
git clone https://github.com/gek64/qbtsh.git
# 编译源代码
cd qbtsh
export CGO_ENABLED=0
go build -v -trimpath -ldflags "-s -w"
```

Expand Down
129 changes: 53 additions & 76 deletions config.go
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
}
26 changes: 0 additions & 26 deletions configs/linux_openrc.json

This file was deleted.

26 changes: 0 additions & 26 deletions configs/linux_systemd.json

This file was deleted.

Loading

0 comments on commit 6e6ebe0

Please sign in to comment.