From 06ada8850cf43c41e06fc75ba14db1ef332db984 Mon Sep 17 00:00:00 2001 From: Compey Date: Tue, 20 Dec 2022 18:52:42 +0530 Subject: [PATCH] feat: complete build steps --- lib/core/core.go | 39 +++++++++++++++++++++++---------------- src/main.go | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/core/core.go b/lib/core/core.go index 07d6c69..2d2dbfa 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -95,21 +95,7 @@ func Build() { archiveName := fmt.Sprintf(`archlinux-bootstrap-%s-x86_64.tar.gz`, version) untarArchive(archiveName, bar) - - bar.Suffix = " Building bootstrap package..." - - bar.Start() - - _d, buildErr := exec.Command("wsl.exe", "bash", "-c", "cd root.x86_64 && tar -zcvf arch_bootstrap_package.tar.gz .").CombinedOutput() - - if buildErr != nil { - bar.Stop() - println(buildErr.Error()) - println(string(_d)) - logger.Error("Failed to build bootstrap package; fatal. Aborting installation...") - } - bar.Stop() - logger.Progress("Successfully built bootstrap package, proceeeding!") + preserveOwnership("root.x86_64", bar) } func untarArchive(archiveName string, bar *spinner.Spinner) { @@ -137,6 +123,7 @@ func untarArchive(archiveName string, bar *spinner.Spinner) { pb := progressbar.NewOptions(1000, progressbar.OptionEnableColorCodes(true), progressbar.OptionShowBytes(true), + progressbar.OptionShowBytes(true), progressbar.OptionSetPredictTime(true), progressbar.OptionSetDescription("[yellow][1/3][reset] Untarring archive..."), progressbar.OptionSetTheme(progressbar.Theme{ @@ -147,7 +134,7 @@ func untarArchive(archiveName string, bar *spinner.Spinner) { BarEnd: "]", })) - progressbar.DefaultBytes(untarSize) + progressbar.DefaultBytesSilent(untarSize*2 ^ 64) untarCmd := exec.Command("wsl.exe", "bash", "-c", fmt.Sprintf("tar -xzvf %s", archiveName)) @@ -169,6 +156,25 @@ func untarArchive(archiveName string, bar *spinner.Spinner) { logger.Info("Successfully untarred archive!") } +func preserveOwnership(extractedDir string, bar *spinner.Spinner) { + bar.Suffix = " Building bootstrap package..." + + bar.Start() + + _d, buildErr := exec.Command("wsl.exe", "bash", "-c", fmt.Sprintf("cd %s && tar -zcvf arch_bootstrap_package.tar.gz .", extractedDir)).CombinedOutput() + + if buildErr != nil { + bar.Stop() + println(buildErr.Error()) + println(string(_d)) + logger.Error("Failed to build bootstrap package; fatal. Aborting installation...") + } + bar.Stop() + logger.Progress("Successfully built bootstrap package, proceeeding!") +} + +// TODO: Distro importing with user-provided name prompt or autogenerated prompts + func getMirror(country string) string { resp, err := http.Get("https://archlinux.org/download/") if err != nil { @@ -180,6 +186,7 @@ func getMirror(country string) string { logger.Error("An internal error occurred when attempting to pull the RootFS. This is probably a bug; you might want to report this.") } + // Hackily get the mirror by filtering (splitting) the HTML a bunch of times mirrorLink := strings.Split(strings.Split(strings.Split(strings.Split(strings.Split(strings.Split(string(body), fmt.Sprintf(`title="%s"`, country))[1], `title="Download from`)[0], fmt.Sprintf(`> %s`, country))[1], `