-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (88 loc) · 2.33 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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"slices"
)
type Config struct {
Package_Managers []string `json:"packagemanagers"`
}
type Pac_Out struct {
Package_name string `json:"package"`
Version string `json:"version"`
}
// LoadingSpinner starts a loading spinner while the provided task runs.
func parse() {
isDangerous := flag.Bool("dangerous", false, "turns on danger mode if set, which bypasses all user checks. Tread lightly when using this flag.")
flag.Parse()
configPath := getConfigPath("config.json")
file, err := os.Open(configPath)
check(err)
defer file.Close()
var config Config
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
check(err)
main_loop(*isDangerous, config)
}
func main_loop(isDangerous bool, config Config) {
fmt.Println("Welcome to Dill! The meta-package-manager.")
if isDangerous {
fmt.Println("Danger mode enabled! Here be dragons...")
}
if !isRoot() {
fmt.Println("ERROR: Dill must be run as root.")
panic("Permission Denied.")
}
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
println("ERROR: do NOT run Dill in a non-interactive terminal.")
panic("Dill is designed to be run interactively.")
} else {
fmt.Println("Running interactively, continuing...")
}
fmt.Println("checking package managers...")
managers := config.Package_Managers
if slices.Contains(managers, "pacman") {
fmt.Println("pacman detected")
pacman_list()
}
if slices.Contains(managers, "apt") {
fmt.Println("apt detected")
// Call apt list or other actions
}
if slices.Contains(managers, "dnf") {
fmt.Println("dnf detected")
// Call dnf list or other actions
}
if slices.Contains(managers, "flatpak") {
fmt.Println("flatpak detected")
flatpak_list()
}
if slices.Contains(managers, "apk") {
fmt.Println("apk detected")
alpine_list()
}
if len(managers) == 0 {
fmt.Println("no package managers found in config.json. exiting...")
os.Exit(1)
}
horizontalLine := "_"
bottomLeft := "⎣"
// Print the bottom line
fmt.Printf("%s%s\n", bottomLeft, horizontalLine)
confirm_choice()
if slices.Contains(managers, "pacman") {
LoadingSpinner(pac_update)
}
if slices.Contains(managers, "flatpak") {
LoadingSpinner(flat_update)
}
if slices.Contains(managers, "apk") {
LoadingSpinner(alpine_update)
}
}
func main() {
parse()
}