mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
add manage command
This commit is contained in:
59
cmd/install_linux.go
Normal file
59
cmd/install_linux.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var targetVersion string
|
||||
|
||||
var (
|
||||
updateCommand = cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update V2bX version",
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
c := execCommandStd("bash",
|
||||
"<(curl -Ls https://raw.githubusercontents.com/Yuzuki616/V2bX-script/master/install.sh)",
|
||||
targetVersion)
|
||||
},
|
||||
Args: cobra.NoArgs,
|
||||
}
|
||||
uninstallCommand = cobra.Command{
|
||||
Use: "uninstall",
|
||||
Short: "Uninstall V2bX",
|
||||
Run: uninstallHandle,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
updateCommand.PersistentFlags().StringVar(&targetVersion, "version", "", "update target version")
|
||||
command.AddCommand(&updateCommand)
|
||||
command.AddCommand(&uninstallCommand)
|
||||
}
|
||||
|
||||
func uninstallHandle(_ *cobra.Command, _ []string) {
|
||||
var yes string
|
||||
fmt.Println(Warn("确定要卸载 V2bX 吗?(Y/n)"))
|
||||
fmt.Scan(&yes)
|
||||
if strings.ToLower(yes) != "y" {
|
||||
fmt.Println("已取消卸载")
|
||||
}
|
||||
_, err := execCommand("systemctl stop V2bX&&systemctl disable V2bX")
|
||||
if err != nil {
|
||||
fmt.Println(Err("exec cmd error: ", err))
|
||||
fmt.Println(Err("卸载失败"))
|
||||
return
|
||||
}
|
||||
_ = os.RemoveAll("/etc/systemd/system/V2bX.service")
|
||||
_ = os.RemoveAll("/etc/V2bX/")
|
||||
_ = os.RemoveAll("/usr/local/V2bX/")
|
||||
_, err = execCommand("systemctl daemon-reload&&systemctl reset-failed")
|
||||
if err != nil {
|
||||
fmt.Println(Err("exec cmd error: ", err))
|
||||
fmt.Println(Err("卸载失败"))
|
||||
return
|
||||
}
|
||||
fmt.Println(Ok("卸载成功"))
|
||||
}
|
||||
Reference in New Issue
Block a user