2023-05-23 22:26:14 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2023-07-29 07:27:15 -04:00
|
|
|
|
|
|
|
"github.com/InazumaV/V2bX/common/exec"
|
|
|
|
"github.com/spf13/cobra"
|
2023-05-23 22:26:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var targetVersion string
|
|
|
|
|
|
|
|
var (
|
|
|
|
updateCommand = cobra.Command{
|
|
|
|
Use: "update",
|
|
|
|
Short: "Update V2bX version",
|
|
|
|
Run: func(_ *cobra.Command, _ []string) {
|
2023-06-01 20:45:22 -04:00
|
|
|
exec.RunCommandStd("bash",
|
2023-07-29 07:27:15 -04:00
|
|
|
"<(curl -Ls https://raw.githubusercontents.com/InazumaV/V2bX-script/master/install.sh)",
|
2023-05-23 22:26:14 -04:00
|
|
|
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("已取消卸载")
|
|
|
|
}
|
2023-06-01 20:45:22 -04:00
|
|
|
_, err := exec.RunCommandByShell("systemctl stop V2bX&&systemctl disable V2bX")
|
2023-05-23 22:26:14 -04:00
|
|
|
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/")
|
2023-05-29 16:04:05 -04:00
|
|
|
_ = os.RemoveAll("/bin/V2bX")
|
2023-06-01 20:45:22 -04:00
|
|
|
_, err = exec.RunCommandByShell("systemctl daemon-reload&&systemctl reset-failed")
|
2023-05-23 22:26:14 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(Err("exec cmd error: ", err))
|
|
|
|
fmt.Println(Err("卸载失败"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(Ok("卸载成功"))
|
|
|
|
}
|