lxrunoffline

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 7 Imported by: 0

README

LxRunOffline on Golang

LxRunOffline on golang.

Still on going development

Prerequisite

This package uses lxrunoffline to process some task. The basic requirements are just to install lxrunoffline into your Windows 10 machine. You can follow the installation here. Recommended to install using Choco method.

Installing

Install

$ go get github.com/mkhuda/go-lxrunoffline

Usage

package main

import (
	"encoding/json"
	"fmt"

	"github.com/mkhuda/go-lxrunoffline"
)

func main() {
	lx, err := lxrunoffline.New()
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("lx.Options.LibsPath: %v\n", lx.Options.LibsPath)

	listInstalled, err := lx.ListInstalled()
	if err != nil {
		fmt.Println("error listinstalled", err)
		return
	}

	defaultDistroName, defaultDistroUid, _ := lx.GetDefaultDistro()

	fmt.Println("List of installed WSL: ")
	for i, distros := range listInstalled {
		fmt.Println(i+1, distros.DistroName)
	}

	distroSummary, err := lx.GetDistroSummary(defaultDistroUid)
	if err != nil {
		fmt.Println("error summary", err)
		return
	}
	distroJson, err := json.Marshal(distroSummary)
	if err != nil {
		fmt.Println("error summary", err)
		return
	}

	fmt.Printf("Summary of default distro (marshalled): %v\n", string(distroJson))

	summaryOfDefaultDistro, cmd, err := lx.GetSummaryCmd(defaultDistroName)
	if err != nil {
		fmt.Println("error summary cmd", err, cmd)
		return
	}

	fmt.Printf("Summary of default distro: %v\n%v", defaultDistroName, summaryOfDefaultDistro)
}


Credits

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WhereLx

func WhereLx() (string, error)
WhereLx()

Show current lxrunoffline installation from system.

Types

type Distro

type Distro struct {
	DistroId              string
	DistroName            string
	WslVersion            uint64
	FileSystemVersion     uint64
	InstallationDirectory string
}

func (*Distro) DirSize

func (ds *Distro) DirSize() string
*Distro.DirSize()

Return a prettier string of size of distro installation folder on disk

type LxRunOffline

type LxRunOffline struct {
	Options
}

func Init

func Init(options Options) *LxRunOffline

Init(options) can be used to obtain custom location of lxrunoffline.exe

func New

func New() (*LxRunOffline, error)
New()

Initialize and find where lxrunoffline.exe is installed to the machine. Use this initialize method if you have installed lxrunoffline via Chocolatey or Scoop. Also if you correctly install lxrunoffline.exe manually then added to Windows PATH

func (*LxRunOffline) ClearASCII

func (lx *LxRunOffline) ClearASCII(values []byte, shouldGetFirstLine bool) string

func (*LxRunOffline) ExportDistro

func (lx *LxRunOffline) ExportDistro(distributionName string, tarDirFile string) error
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 (*LxRunOffline) GetDefaultDistro

func (lx *LxRunOffline) GetDefaultDistro() (string, string, error)
lx.GetDefaultDistro()

Return distro name, distro_uid. Empty string will return if error occured. This function read Windows Registry

func (*LxRunOffline) GetDefaultDistroCmd

func (lx *LxRunOffline) GetDefaultDistroCmd() (string, *exec.Cmd, error)
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 (*LxRunOffline) GetDistroSummary

func (lx *LxRunOffline) GetDistroSummary(distro_uid string) (*Distro, error)
lx.GetDistroSummary(distro_uid string)

Return a distro with the info it has. This function read Windows Registry

func (*LxRunOffline) GetFirstLine

func (lx *LxRunOffline) GetFirstLine(s string) string

func (*LxRunOffline) GetRegistrySubkey

func (lx *LxRunOffline) GetRegistrySubkey(path string, value string) (v []string, err error)

func (*LxRunOffline) GetRegistryValue

func (lx *LxRunOffline) GetRegistryValue(path string, value string) (v string, vtype uint32, err error)

func (*LxRunOffline) GetRegistryValueInt

func (lx *LxRunOffline) GetRegistryValueInt(path string, value string) (v uint64, vtype uint32, err error)

func (*LxRunOffline) GetSummaryCmd

func (lx *LxRunOffline) GetSummaryCmd(distributionName string) (string, *exec.Cmd, error)
lx.GetSummaryCmd(distributionName string)

Will show current summary by distributionName. This function provided by LxRunOffline.exe

func (*LxRunOffline) IsWSL2

func (lx *LxRunOffline) IsWSL2(flag uint64) bool

func (*LxRunOffline) ListInstalled

func (lx *LxRunOffline) ListInstalled() ([]*Distro, error)
lx.ListInstalled()

Return list of distro with some infos. This function read Windows Registrys

func (*LxRunOffline) ListInstalledCmd

func (lx *LxRunOffline) ListInstalledCmd() ([]string, *exec.Cmd, error)
lx.ListInstalledCmd()

Get list of installed distro on your machine. This function provided by LxRunOffline.exe and return list of distroName string

type Options

type Options struct {
	LibsPath string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL