diff --git a/cmd/dcrinstall/bitcoin.go b/cmd/dcrinstall/bitcoin.go index 07369bd..edd80fe 100644 --- a/cmd/dcrinstall/bitcoin.go +++ b/cmd/dcrinstall/bitcoin.go @@ -31,6 +31,7 @@ var ( } bitcoinVersionRE = regexp.MustCompile(`[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+`) + bitcoinArchiveRE = regexp.MustCompile(`bitcoin-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+`) bitcoinf = []decredFiles{ { @@ -289,15 +290,24 @@ func bitcoinDownloadAndVerify() error { log.Printf("Attempting to upgrade to Bitcoin version: %v", manifestBitcoinVersion) - // Download bitcoin bundle - err = downloadBitcoinBundle(digest, filename) - if err != nil { - return fmt.Errorf("Download bitcoin bundle: %v", err) - } + // Work around bitcoin not having a default name. + filenameMunged := bitcoinArchiveRE.FindString(filename) + ".tar.gz" - err = extractBitcoinBundle() - if err != nil { - return fmt.Errorf("Extract bitcoin bundle: %v", err) + // Don't download bundle if it has been extracted. + if filenameMunged == ".tar.gz" || + forceDownload || !seenBefore(filenameMunged) { + // Download bitcoin bundle + err = downloadBitcoinBundle(digest, filename) + if err != nil { + return fmt.Errorf("Download bitcoin bundle: %v", err) + } + + err = extractBitcoinBundle() + if err != nil { + return fmt.Errorf("Extract bitcoin bundle: %v", err) + } + } else { + log.Printf("Using cached archive: %v", filename) } err = preconditionsBitcoinInstall() diff --git a/cmd/dcrinstall/dcrdex.go b/cmd/dcrinstall/dcrdex.go index b2f6b1a..f35fcc6 100644 --- a/cmd/dcrinstall/dcrdex.go +++ b/cmd/dcrinstall/dcrdex.go @@ -230,15 +230,20 @@ func dcrdexDownloadAndVerify() error { log.Printf("Attempting to upgrade to Dcrdex version: %v", manifestDcrdexVersion) - // Download dcrdex bundle - err = downloadDcrdexBundle(digest, filename) - if err != nil { - return fmt.Errorf("Download dcrdex bundle: %v", err) - } + // Don't download bundle if it has been extracted. + if forceDownload || !seenBefore(filename) { + // Download dcrdex bundle + err = downloadDcrdexBundle(digest, filename) + if err != nil { + return fmt.Errorf("Download dcrdex bundle: %v", err) + } - err = extractDcrdexBundle() - if err != nil { - return fmt.Errorf("Extract dcrdex bundle: %v", err) + err = extractDcrdexBundle() + if err != nil { + return fmt.Errorf("Extract dcrdex bundle: %v", err) + } + } else { + log.Printf("Using cached archive: %v", filename) } err = preconditionsDcrdexInstall() diff --git a/cmd/dcrinstall/dcrinstall.go b/cmd/dcrinstall/dcrinstall.go index 3af8839..b4b1d10 100644 --- a/cmd/dcrinstall/dcrinstall.go +++ b/cmd/dcrinstall/dcrinstall.go @@ -172,6 +172,7 @@ var ( bitcoinManifestDigest string // Bitcoin manifest digest, if used tuple string // Download tuple network string // Installing for network + forceDownload bool // Always download bundles dcrdex bool // Install dcrdex skipPGP bool // Don't download and verify PGP signatures quiet bool // Don't output anything but errors @@ -303,6 +304,8 @@ func _main() error { "bitcoin manifest URI override") tupleF := flag.String("tuple", defaultTuple, "OS-Arch tuple, e.g. windows-amd64") + forceDownloadF := flag.Bool("forcedownload", false, + "Force download bundles (default false)") dcrdexF := flag.Bool("dcrdex", false, "Install Dcrdex") skipPGPF := flag.Bool("skippgp", false, "skip download and "+ "verification of pgp signatures") @@ -324,6 +327,7 @@ func _main() error { // Prepare environment destination = cleanAndExpandPath(*destF) tuple = *tupleF + forceDownload = *forceDownloadF dcrdex = *dcrdexF skipPGP = *skipPGPF quiet = *quietF diff --git a/cmd/dcrinstall/decred.go b/cmd/dcrinstall/decred.go index 5284885..5385016 100644 --- a/cmd/dcrinstall/decred.go +++ b/cmd/dcrinstall/decred.go @@ -313,6 +313,7 @@ func decredDownloadAndVerify() error { // Download the decred manifest manifestDecredFilename = filepath.Join(tmpDir, filepath.Base(decredManifestURI)) + err := DownloadFile(decredManifestURI, manifestDecredFilename) if err != nil { return fmt.Errorf("Download manifest file: %v", err) @@ -365,15 +366,20 @@ func decredDownloadAndVerify() error { log.Printf("Attempting to upgrade to Decred version: %v", manifestDecredVersion) - // Download decred bundle - err = downloadDecredBundle(digest, filename) - if err != nil { - return fmt.Errorf("Download decred bundle: %v", err) - } + // Don't download bundle if it has been extracted. + if forceDownload || !seenBefore(filename) { + // Download decred bundle + err = downloadDecredBundle(digest, filename) + if err != nil { + return fmt.Errorf("Download decred bundle: %v", err) + } - err = extractDecredBundle() - if err != nil { - return fmt.Errorf("Extract decred bundle: %v", err) + err = extractDecredBundle() + if err != nil { + return fmt.Errorf("Extract decred bundle: %v", err) + } + } else { + log.Printf("Using cached archive: %v", filename) } err = preconditionsDecredInstall() diff --git a/cmd/dcrinstall/util.go b/cmd/dcrinstall/util.go index a8bbcd5..c1892c0 100644 --- a/cmd/dcrinstall/util.go +++ b/cmd/dcrinstall/util.go @@ -114,12 +114,12 @@ func (wc WriteCounter) PrintProgress() { // DownloadFile downloads the provided URL to the filepath. If the quiet flag // is not set it prints download progress. -func DownloadFile(url string, filepath string) error { - log.Printf("Download file: %v -> %v", url, filepath) +func DownloadFile(url string, path string) error { + log.Printf("Download file: %v -> %v", url, path) // Create the file with .tmp extension, so that we won't overwrite a // file until it's downloaded fully - out, err := os.Create(filepath + ".tmp") + out, err := os.Create(path + ".tmp") if err != nil { return err } @@ -173,7 +173,7 @@ func DownloadFile(url string, filepath string) error { out.Close() // Rename the tmp file back to the original file - err = os.Rename(filepath+".tmp", filepath) + err = os.Rename(path+".tmp", path) if err != nil { return err } @@ -474,6 +474,9 @@ func getDownloadURI(uri string) (string, error) { func runtimeTuple() string { return runtime.GOOS + "-" + runtime.GOARCH } + +// printConfigError prints a list of installed and not installed configuration +// files. func printConfigError(installedConfigs, notInstalledConfigs []string) string { rv := "Installed configuration files:\n" for _, v := range installedConfigs { @@ -485,3 +488,17 @@ func printConfigError(installedConfigs, notInstalledConfigs []string) string { } return rv } + +// seenBefore looks to see if bundle has been extracted before. +func seenBefore(bundle string) bool { + b := filepath.Base(bundle) + switch { + case strings.HasSuffix(bundle, ".zip"): + return exists((filepath.Join(destination, + strings.TrimRight(b, ".zip")))) + case strings.HasSuffix(bundle, ".tar.gz"): + return exists((filepath.Join(destination, + strings.TrimRight(b, ".tar.gz")))) + } + return false +}