mirror of
https://github.com/CompeyDev/wsl-archlinux-manager.git
synced 2024-12-12 12:40:36 +00:00
fix: verify signature of dynamic filename & initial untarring
This commit is contained in:
parent
a3905bd21e
commit
bc1bb28d7f
3 changed files with 30 additions and 10 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -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/*
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue