-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.go
78 lines (61 loc) · 2.57 KB
/
cmd.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
package lxrunoffline
import (
"os/exec"
"strings"
)
/* WhereLx()
Show current lxrunoffline installation from system. */
func WhereLx() (string, error) {
cmd := exec.Command("where", lxRunOffline_libs_main)
out, err := cmd.Output()
lx_location := strings.Split(string(out), "\r")
if len(lx_location) > 0 {
lx_location = lx_location[:len(lx_location)-1]
}
return strings.TrimSuffix(lx_location[0], "\r"), err
}
/* lx.ListInstalledCmd()
Get list of installed distro on your machine. This function provided by LxRunOffline.exe and return list of distroName string */
func (lx *LxRunOffline) ListInstalledCmd() ([]string, *exec.Cmd, error) {
args := append(args_powershell, lx.LibsPath)
start_command := append(args, args_list_installed...)
cmd := exec.Command(powershell, start_command...)
out, err := cmd.Output()
sOutput := strings.Split(string(out), "\r")
if len(sOutput) > 0 {
sOutput = sOutput[:len(sOutput)-1]
}
return sOutput, cmd, err
}
/* lx.GetSummaryCmd(distributionName string)
Will show current summary by distributionName. This function provided by LxRunOffline.exe */
func (lx *LxRunOffline) GetSummaryCmd(distributionName string) (string, *exec.Cmd, error) {
args := append(args_powershell, lx.LibsPath)
summary_args := append(args_summary, distributionName)
start_command := append(args, summary_args...)
cmd := exec.Command(powershell, start_command...)
output, err := cmd.Output()
return string(output), cmd, err
}
/* lx.GetDefaultDistroCmd()
Will show your default distro if you run `wsl` on command prompt.
This function provided by LxRunOffline.exe. Return is string of distroName */
func (lx *LxRunOffline) GetDefaultDistroCmd() (string, *exec.Cmd, error) {
args := append(args_powershell, lx.LibsPath)
start_command := append(args, args_get_default...)
cmd := exec.Command(powershell, start_command...)
out, err := cmd.Output()
output := lx.ClearASCII(out, true)
return output, cmd, err
}
/* lx.ExportDistro(distributionName string, tarDirFile string)
Will export a distro into `*.tar.gz` file. You should provide the full path with name for `tarDirFile` params, e.g: "G:\WSL_Backup\debian.tar.gz". This function provided by LxRunOffline.exe */
func (lx *LxRunOffline) ExportDistro(distributionName string, tarDirFile string) error {
args := append(args_powershell, lx.LibsPath)
export_args := args_export(distributionName, tarDirFile)
start_command := append(args, export_args...)
cmd := exec.Command(powershell, start_command...)
_, err := cmd.Output()
cmd.Wait()
return err
}