V2bX/cmd/install_linux.go

60 lines
1.4 KiB
Go
Raw Normal View History

2023-05-23 22:26:14 -04:00
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) {
2023-05-23 22:37:52 -04:00
execCommandStd("bash",
2023-05-23 22:26:14 -04:00
"<(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("卸载成功"))
}