-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.go
More file actions
86 lines (65 loc) · 1.5 KB
/
uninstall.go
File metadata and controls
86 lines (65 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
)
func uninstallDevcert() (err error) {
devcertDir, err := buildDevcertDir()
if err != nil {
return
}
// Get the devcert executable path
executable, err := os.Executable()
if err != nil {
err = fmt.Errorf("cleaning up CA failed: %w", err)
return
}
// Check for symlinks
realExecutable, err := filepath.EvalSymlinks(executable)
if err != nil {
err = fmt.Errorf("cleaning up CA failed: %w", err)
return
}
color.Set(color.FgWhite, color.Bold)
fmt.Printf("The uninstall command will:")
color.Unset()
fmt.Printf("\n - Remove the")
color.Set(color.FgCyan)
fmt.Printf(" %s ", devcertDir)
color.Unset()
fmt.Printf("directory and all the files in it.")
fmt.Printf("\n - Remove the")
color.Set(color.FgCyan)
fmt.Printf(" %s ", realExecutable)
color.Unset()
fmt.Printf("executable.")
fmt.Printf("\n - Remove the local devcert Certificate Authority (CA).\n")
prompt := promptui.Prompt{
Label: "Do you want to continue?",
IsConfirm: true,
}
_, err = prompt.Run()
if err != nil {
if errors.Is(err, promptui.ErrAbort) {
err = nil
return
}
err = fmt.Errorf("prompt failed: %w", err)
return
}
// Remove CA from the trust stores
err = cleanupCA()
if err != nil {
err = fmt.Errorf("cleaning up CA failed: %w", err)
return
}
// Remove ~/.devcert
attemptCleanupDevcertDir()
// Remove the exeuctable
os.Remove(realExecutable)
return
}