-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (55 loc) · 1.12 KB
/
Copy pathmain.go
File metadata and controls
68 lines (55 loc) · 1.12 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
package main
import (
"fmt"
"os"
"github.com/charmbracelet/huh"
)
type Buffsize int
const (
Byte Buffsize = 1
Kilobyte Buffsize = Byte * 1024
Megabyte Buffsize = Kilobyte * 1024
)
const DefaultBuffsize = 1 * Megabyte
func main() {
checkOS()
isRoot := checkRoot()
modeSelect := huh.NewSelect[int]().
Title("Select action").
Options(
huh.NewOption("Flash image file to drive", 0),
huh.NewOption("Create image file from drive", 1),
huh.NewOption("Image to image conversion", 3),
huh.NewOption("Transfer image file over SSH (WiP)", 2),
huh.NewOption("Exit", 99),
)
err := modeSelect.Run()
if err != nil {
return
}
switch modeSelect.GetValue() {
case 0:
err = requireRoot(isRoot, flashImageToDisk)
case 1:
err = requireRoot(isRoot, createImageFromDisk)
case 2:
err = requireRoot(isRoot, createImageToSSH)
case 3:
err = imageToImage()
case 99:
return
}
if err != nil {
fmt.Println(err)
main()
}
}
func requireRoot(isRoot bool, action func() error) error {
if isRoot {
return action()
} else {
fmt.Println("This action must be run as root")
os.Exit(1)
return nil
}
}