-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (122 loc) · 2.75 KB
/
main.go
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"os"
"path"
"path/filepath"
"github.com/Urethramancer/multitool/md5cmd"
pwgen "github.com/Urethramancer/multitool/pwgencmd"
"github.com/Urethramancer/multitool/rn"
"github.com/Urethramancer/multitool/sha1cmd"
"github.com/Urethramancer/multitool/sha512cmd"
"github.com/Urethramancer/signor/files"
"github.com/Urethramancer/signor/log"
)
func main() {
app := path.Base(os.Args[0])
switch app {
case "Multitool.exe":
fallthrough
case "multitool.exe":
fallthrough
case "Multitool":
fallthrough
case "multitool":
usage()
case "pwgen.exe":
fallthrough
case "pwgen":
pwgen.Run()
case "sha1.exe":
fallthrough
case "sha1":
sha1cmd.Run()
case "sha3.exe":
fallthrough
case "sha512.exe":
fallthrough
case "sha512":
sha512cmd.Run()
case "md5.exe":
fallthrough
case "md5":
md5cmd.Run()
case "rn.exe":
fallthrough
case "rn":
rn.Run()
}
}
func usage() {
m := log.Default.Msg
e := log.Default.Err
bin, err := os.Executable()
if err != nil {
m("Error getting path: %s", err.Error())
return
}
ret := false
path := filepath.Dir(bin)
md5path := filepath.Join(path, "md5")
if !files.FileExists(md5path) {
m("Creating symlink '%s'", md5path)
err = os.Symlink(bin, md5path)
if err != nil {
e("Error creating symlink for %s: %s", md5path, err.Error())
os.Exit(2)
}
ret = true
}
sha1path := filepath.Join(path, "sha1")
if !files.FileExists(sha1path) {
m("Creating symlink '%s'", sha1path)
err = os.Symlink(bin, sha1path)
if err != nil {
e("Error creating symlink for %s: %s", sha1path, err.Error())
os.Exit(2)
}
ret = true
}
sha512path := filepath.Join(path, "sha512")
if !files.FileExists(sha512path) {
m("Creating symlink '%s'", sha512path)
err = os.Symlink(bin, sha512path)
if err != nil {
e("Error creating symlink for %s: %s", sha512path, err.Error())
os.Exit(2)
}
ret = true
}
pwgenpath := filepath.Join(path, "pwgen")
if !files.FileExists(pwgenpath) {
m("Creating symlink '%s'", pwgenpath)
err = os.Symlink(bin, pwgenpath)
if err != nil {
e("Error creating symlink for %s: %s", pwgenpath, err.Error())
os.Exit(2)
}
ret = true
}
rnpath := filepath.Join(path, "rn")
if !files.FileExists(rnpath) {
m("Creating symlink '%s'", rnpath)
err = os.Symlink(bin, rnpath)
if err != nil {
e("Error creating symlink for %s: %s", rnpath, err.Error())
os.Exit(2)
}
ret = true
}
if ret {
return
}
m("Multitool\n")
m("Do not call directly. Link program names to this binary.\n\n")
m("Admin utilities:\n")
m("\tpwgen\tPassword generator\n")
m("\nChecksumming:\n")
m("\tmd5\tMD5 checksummer\n")
m("\tsha1\tSHA-1 checksummer\n")
m("\tsha3\tSHA-3 Keccak 512 checksummer\n")
m("\nFile utilities:\n")
m("\trn\tBulk renamer/name stripper\n")
}