feat: complete build steps

This commit is contained in:
Erica Marigold 2022-12-20 18:52:42 +05:30
parent e4a01a315d
commit 06ada8850c
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2
2 changed files with 24 additions and 17 deletions

View file

@ -95,21 +95,7 @@ func Build() {
archiveName := fmt.Sprintf(`archlinux-bootstrap-%s-x86_64.tar.gz`, version) archiveName := fmt.Sprintf(`archlinux-bootstrap-%s-x86_64.tar.gz`, version)
untarArchive(archiveName, bar) untarArchive(archiveName, bar)
preserveOwnership("root.x86_64", 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!")
} }
func untarArchive(archiveName string, bar *spinner.Spinner) { func untarArchive(archiveName string, bar *spinner.Spinner) {
@ -137,6 +123,7 @@ func untarArchive(archiveName string, bar *spinner.Spinner) {
pb := progressbar.NewOptions(1000, pb := progressbar.NewOptions(1000,
progressbar.OptionEnableColorCodes(true), progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true), progressbar.OptionShowBytes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetPredictTime(true), progressbar.OptionSetPredictTime(true),
progressbar.OptionSetDescription("[yellow][1/3][reset] Untarring archive..."), progressbar.OptionSetDescription("[yellow][1/3][reset] Untarring archive..."),
progressbar.OptionSetTheme(progressbar.Theme{ progressbar.OptionSetTheme(progressbar.Theme{
@ -147,7 +134,7 @@ func untarArchive(archiveName string, bar *spinner.Spinner) {
BarEnd: "]", BarEnd: "]",
})) }))
progressbar.DefaultBytes(untarSize) progressbar.DefaultBytesSilent(untarSize*2 ^ 64)
untarCmd := exec.Command("wsl.exe", "bash", "-c", fmt.Sprintf("tar -xzvf %s", archiveName)) 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!") 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 { func getMirror(country string) string {
resp, err := http.Get("https://archlinux.org/download/") resp, err := http.Get("https://archlinux.org/download/")
if err != nil { 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.") 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(`></span> %s</h5>`, country))[1], `<ul>`)[1], `<li><a href="`)[1], `"`)[0] 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(`></span> %s</h5>`, country))[1], `<ul>`)[1], `<li><a href="`)[1], `"`)[0]
return mirrorLink return mirrorLink
} }

View file

@ -18,7 +18,7 @@ import (
func main() { func main() {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
checks() // checks()
core.Build() core.Build()
} else { } else {
fmt.Println("WSL is reserved for windows users only.") fmt.Println("WSL is reserved for windows users only.")