This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
91 lines (72 loc) · 2.23 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
package main
import (
"fmt"
"io/fs"
"os"
"os/exec"
"path"
"runtime"
"strings"
"time"
"github.com/CompeyDev/wsl-archlinux-manager/lib/core"
logger "github.com/CompeyDev/wsl-archlinux-manager/util"
"github.com/briandowns/spinner"
"github.com/gookit/color"
)
func main() {
if runtime.GOOS == "windows" {
// checks()
core.Build()
} else {
fmt.Println("WSL is reserved for windows users only.")
os.Exit(1)
}
}
func checks() {
color.Blueln("======> Pre-installation checks")
fmt.Println("🔃 Running checks...")
_, permsErr := os.Open("\\\\.\\PHYSICALDRIVE0")
if permsErr != nil {
fmt.Println("Please run this command with elevated priveleges.")
os.Exit(1)
}
bar := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
bar.Prefix = " "
bar.Suffix = " Checking for WSL..."
bar.Start()
getAvailability, availabilityErr := exec.Command("powershell.exe", "(Get-WindowsOptionalFeature -Online -FeatureName *Subsystem*).State").Output()
if availabilityErr != nil {
logger.Error("Failed to check for WSL availability.")
}
if strings.Trim(string(getAvailability), "\n\r") == "Enabled" {
logger.Info("WSL is enabled.")
bar.Stop()
bar.Prefix = " "
bar.Suffix = " Checking for existing WSL distributions..."
bar.Start()
preInstalledDistro, installedDistroErr := exec.Command("powershell.exe", "wsl").Output()
if installedDistroErr != nil {
logger.Error("Failed to check for preinstalled distributions.")
bar.Stop()
}
if strings.Contains(string(preInstalledDistro), "no installed distributions") {
logger.Error("Preinstalled distributions do not exist. (Please make sure the default WSL distribution is Debian-based)")
bar.Stop()
}
}
userHomeDir, homeDirErr := os.UserHomeDir()
bar.Suffix = " Creating install directory..."
bar.Start()
time.Sleep(1 * time.Second)
if homeDirErr != nil {
logger.Error("Failed to initialize installation directory.")
}
installDir := path.Join(userHomeDir, ".wslm")
archDir := path.Join(installDir, "arch")
os.Mkdir(installDir, fs.FileMode(os.O_RDWR))
os.Mkdir(archDir, fs.FileMode(os.O_RDWR))
bar.Stop()
logger.Info("Successfully initialized installation directory.")
logger.Progress("Initialized WSLm.")
color.Blueln("===============================")
}