mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/cli: add "--cleanup" flag to remove ctrld's files
This commit is contained in:
committed by
Cuong Manh Le
parent
80cf79b9cb
commit
50ef00526e
@@ -599,11 +599,41 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
|
||||
os.Exit(deactivationPinInvalidExitCode)
|
||||
}
|
||||
uninstall(p, s)
|
||||
if cleanup {
|
||||
var files []string
|
||||
// Config file.
|
||||
files = append(files, v.ConfigFileUsed())
|
||||
// Log file.
|
||||
files = append(files, cfg.Service.LogPath)
|
||||
// Socket files.
|
||||
if dir, _ := socketDir(); dir != "" {
|
||||
files = append(files, filepath.Join(dir, ctrldControlUnixSock))
|
||||
files = append(files, filepath.Join(dir, ctrldLogUnixSock))
|
||||
}
|
||||
// Binary itself.
|
||||
if bin, _ := os.Executable(); bin != "" {
|
||||
files = append(files, bin)
|
||||
}
|
||||
for _, file := range files {
|
||||
if file == "" {
|
||||
continue
|
||||
}
|
||||
if err := os.Remove(file); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
mainLog.Load().Warn().Err(err).Msg("failed to remove file")
|
||||
} else {
|
||||
mainLog.Load().Debug().Msgf("file removed: %s", file)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
uninstallCmd.Flags().StringVarP(&iface, "iface", "", "", `Reset DNS setting for iface, use "auto" for the default gateway interface`)
|
||||
uninstallCmd.Flags().Int64VarP(&deactivationPin, "pin", "", defaultDeactivationPin, `Pin code for uninstalling ctrld`)
|
||||
_ = uninstallCmd.Flags().MarkHidden("pin")
|
||||
uninstallCmd.Flags().BoolVarP(&cleanup, "cleanup", "", false, `Removing ctrld binary and config files`)
|
||||
|
||||
listIfacesCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
@@ -752,7 +782,7 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
|
||||
},
|
||||
}
|
||||
uninstallCmdAlias.Flags().StringVarP(&ifaceStartStop, "iface", "", "auto", `Reset DNS setting for iface, "auto" means the default interface gateway`)
|
||||
uninstallCmdAlias.Flags().AddFlagSet(stopCmd.Flags())
|
||||
uninstallCmdAlias.Flags().AddFlagSet(uninstallCmd.Flags())
|
||||
rootCmd.AddCommand(uninstallCmdAlias)
|
||||
|
||||
listClientsCmd := &cobra.Command{
|
||||
|
||||
@@ -36,6 +36,7 @@ var (
|
||||
cdUpstreamProto string
|
||||
deactivationPin int64
|
||||
skipSelfChecks bool
|
||||
cleanup bool
|
||||
|
||||
mainLog atomic.Pointer[zerolog.Logger]
|
||||
consoleWriter zerolog.ConsoleWriter
|
||||
|
||||
Reference in New Issue
Block a user