fix: verify signature of dynamic filename & initial untarring

This commit is contained in:
Erica Marigold 2022-11-26 18:51:09 +05:30
parent a3905bd21e
commit bc1bb28d7f
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2
3 changed files with 30 additions and 10 deletions

6
.gitignore vendored
View file

@ -18,3 +18,9 @@ vendor/
# Go workspace file # Go workspace file
go.work go.work
# Arch bootstrap files
archlinux-bootstrap-*.tar.gz
archlinux-bootstrap-*.tar.gz.sig
root.x86_64
root.x86_64/*

View file

@ -18,7 +18,7 @@ func VerifySignature(mirrorUrl string) {
bar.Suffix = " Verifying signature of RootFS..." bar.Suffix = " Verifying signature of RootFS..."
bar.Start() bar.Start()
success, _ := pullSig(mirrorUrl) success, version, _ := pullSig(mirrorUrl)
if !success { if !success {
logger.Error("Failed to download signature of RootFS. Refusing to continue.") 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], `\`, "/") 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)) 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() getAuthenticity, authenticityErr := cmd.CombinedOutput()
if authenticityErr != nil { if authenticityErr != nil {
bar.Stop() 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 := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
bar.Prefix = " " bar.Prefix = " "
bar.Suffix = " Downloading Signature..." bar.Suffix = " Downloading Signature..."
@ -68,10 +68,10 @@ func pullSig(url string) (isSuccessful bool, error error) {
if err != nil { if err != nil {
logger.Error("Failed to download Signature.") logger.Error("Failed to download Signature.")
return false, err return false, version, err
} }
logger.Info(fmt.Sprintf("Downloaded Signature %s", res.Filename)) logger.Info(fmt.Sprintf("Downloaded Signature %s", res.Filename))
return true, nil return true, version, nil
} }

View file

@ -5,6 +5,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@ -65,7 +66,7 @@ func Build() {
bar.Suffix = fmt.Sprintf(" Using mirror %s...", mirror) bar.Suffix = fmt.Sprintf(" Using mirror %s...", mirror)
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
bar.Stop() bar.Stop()
isSuccessful_1, _ := pullArchive(mirror) isSuccessful_1, version, _ := pullArchive(mirror)
if !isSuccessful_1 { if !isSuccessful_1 {
logger.Warn("Attempt #1 to pull RootFS failed, trying again with Worldwide mirror...") logger.Warn("Attempt #1 to pull RootFS failed, trying again with Worldwide mirror...")
@ -75,7 +76,7 @@ func Build() {
bar.Start() bar.Start()
globalMirror := getMirror("Worldwide") globalMirror := getMirror("Worldwide")
isSuccessful_2, _ := pullArchive(globalMirror) isSuccessful_2, _, _ := pullArchive(globalMirror)
if !isSuccessful_2 { if !isSuccessful_2 {
logger.Error("Attempt #2 to pull RootFS failed. Please try again.") logger.Error("Attempt #2 to pull RootFS failed. Please try again.")
@ -89,6 +90,19 @@ func Build() {
checkers.VerifySignature(mirror) 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 { func getMirror(country string) string {
@ -106,7 +120,7 @@ func getMirror(country string) string {
return mirrorLink 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 := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
bar.Prefix = " " bar.Prefix = " "
bar.Suffix = " Downloading RootFS..." bar.Suffix = " Downloading RootFS..."
@ -117,9 +131,9 @@ func pullArchive(url string) (isSuccessful bool, error error) {
if err != nil { if err != nil {
logger.Error("Failed to download RootFS.") logger.Error("Failed to download RootFS.")
return false, err return false, "UNKNOWN", err
} }
logger.Info(fmt.Sprintf("Downloaded RootFS %s", res.Filename)) logger.Info(fmt.Sprintf("Downloaded RootFS %s", res.Filename))
return true, nil return true, version, nil
} }