From bc1bb28d7f452bd431833aa3ee8d4685f76c54f1 Mon Sep 17 00:00:00 2001 From: Compey Date: Sat, 26 Nov 2022 18:51:09 +0530 Subject: [PATCH] fix: verify signature of dynamic filename & initial untarring --- .gitignore | 6 ++++++ lib/checkers/verifySignature.go | 10 +++++----- lib/core/core.go | 24 +++++++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 9f7f152..ee7a43f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,9 @@ vendor/ # Go workspace file go.work + +# Arch bootstrap files +archlinux-bootstrap-*.tar.gz +archlinux-bootstrap-*.tar.gz.sig +root.x86_64 +root.x86_64/* diff --git a/lib/checkers/verifySignature.go b/lib/checkers/verifySignature.go index 1c0378b..e373357 100644 --- a/lib/checkers/verifySignature.go +++ b/lib/checkers/verifySignature.go @@ -18,7 +18,7 @@ func VerifySignature(mirrorUrl string) { bar.Suffix = " Verifying signature of RootFS..." bar.Start() - success, _ := pullSig(mirrorUrl) + success, version, _ := pullSig(mirrorUrl) if !success { logger.Error("Failed to download signature of RootFS. Refusing to continue.") @@ -40,7 +40,7 @@ func VerifySignature(mirrorUrl string) { unixWd := fmt.Sprintf("/mnt/c/%s", strings.ReplaceAll(strings.Split(userHomeDir, `C:\`)[1], `\`, "/")) + strings.ReplaceAll(strings.Split(cwd, userHomeDir)[1], `\`, "/") logger.Info(fmt.Sprintf("Looking for verification signature in Unix Directory %s", unixWd)) - cmd := exec.Command("wsl.exe", `bash`, `-c`, `gpg --keyserver-options auto-key-retrieve --verify archlinux-bootstrap-2022.11.01-x86_64.tar.gz.sig`) + cmd := exec.Command("wsl.exe", `bash`, `-c`, fmt.Sprintf(`gpg --keyserver-options auto-key-retrieve --verify archlinux-bootstrap-%s-x86_64.tar.gz.sig`, version)) getAuthenticity, authenticityErr := cmd.CombinedOutput() if authenticityErr != nil { bar.Stop() @@ -57,7 +57,7 @@ func VerifySignature(mirrorUrl string) { } -func pullSig(url string) (isSuccessful bool, error error) { +func pullSig(url string) (isSuccessful bool, ver string, error error) { bar := spinner.New(spinner.CharSets[14], 100*time.Millisecond) bar.Prefix = " " bar.Suffix = " Downloading Signature..." @@ -68,10 +68,10 @@ func pullSig(url string) (isSuccessful bool, error error) { if err != nil { logger.Error("Failed to download Signature.") - return false, err + return false, version, err } logger.Info(fmt.Sprintf("Downloaded Signature %s", res.Filename)) - return true, nil + return true, version, nil } diff --git a/lib/core/core.go b/lib/core/core.go index 8d86271..cf50bee 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "os" + "os/exec" "strings" "time" @@ -65,7 +66,7 @@ func Build() { bar.Suffix = fmt.Sprintf(" Using mirror %s...", mirror) time.Sleep(time.Second * 5) bar.Stop() - isSuccessful_1, _ := pullArchive(mirror) + isSuccessful_1, version, _ := pullArchive(mirror) if !isSuccessful_1 { logger.Warn("Attempt #1 to pull RootFS failed, trying again with Worldwide mirror...") @@ -75,7 +76,7 @@ func Build() { bar.Start() globalMirror := getMirror("Worldwide") - isSuccessful_2, _ := pullArchive(globalMirror) + isSuccessful_2, _, _ := pullArchive(globalMirror) if !isSuccessful_2 { logger.Error("Attempt #2 to pull RootFS failed. Please try again.") @@ -89,6 +90,19 @@ func Build() { checkers.VerifySignature(mirror) } + bar.Suffix = " Untarring archive..." + bar.Start() + + stdoute, untarErr := exec.Command("wsl.exe", "bash", "-c", fmt.Sprintf(`tar -xzvf archlinux-bootstrap-%s-x86_64.tar.gz`, version)).CombinedOutput() + + if untarErr != nil { + println(untarErr) + logger.Error("Failed to untar archive; this is a non-recoverable error. Quitting.") + } + println(stdoute) + bar.Stop() + logger.Info("Successfully untarred archive!") + } func getMirror(country string) string { @@ -106,7 +120,7 @@ func getMirror(country string) string { return mirrorLink } -func pullArchive(url string) (isSuccessful bool, error error) { +func pullArchive(url string) (isSuccessful bool, ver string, error error) { bar := spinner.New(spinner.CharSets[14], 100*time.Millisecond) bar.Prefix = " " bar.Suffix = " Downloading RootFS..." @@ -117,9 +131,9 @@ func pullArchive(url string) (isSuccessful bool, error error) { if err != nil { logger.Error("Failed to download RootFS.") - return false, err + return false, "UNKNOWN", err } logger.Info(fmt.Sprintf("Downloaded RootFS %s", res.Filename)) - return true, nil + return true, version, nil }