mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
d53ed7d487
* Bump version to v23.02.2 * Fix hash * Reduce timeout on clightning startup, its absurdly long causing slow test iteration * Try to specify the OS version clightning tests run on to ubuntu-20.04 * Rework downloadClightning to be conscious of the ubuntu OS version * Empty commit to re-run CI * Empty commit to re-run CI * Empty commit to re-run CI
93 lines
3.1 KiB
Scala
93 lines
3.1 KiB
Scala
import java.nio.file._
|
|
import java.security.MessageDigest
|
|
import scala.util.Properties
|
|
|
|
name := "bitcoin-s-clightning-rpc"
|
|
|
|
libraryDependencies ++= Deps.clightningRpc
|
|
|
|
CommonSettings.prodSettings
|
|
|
|
TaskKeys.downloadCLightning := {
|
|
val logger = streams.value.log
|
|
import scala.sys.process._
|
|
|
|
val binaryDir = CommonSettings.binariesPath.resolve("clightning")
|
|
|
|
if (Files.notExists(binaryDir)) {
|
|
logger.info(s"Creating directory for clightning binaries: $binaryDir")
|
|
Files.createDirectories(binaryDir)
|
|
}
|
|
|
|
val version = "23.02.2"
|
|
|
|
val (platform, suffix) =
|
|
if (Properties.isLinux) {
|
|
//from: https://stackoverflow.com/a/51614324/967713
|
|
val processBuilder = new java.lang.ProcessBuilder("lsb_release", "-rs")
|
|
val inputStream = new java.io.InputStreamReader(processBuilder.start().getInputStream())
|
|
val version = new java.io.BufferedReader(inputStream).readLine()
|
|
if (version == "22.04") {
|
|
("Ubuntu-22.04", "tar.xz")
|
|
} else {
|
|
("Ubuntu-20.04", "tar.xz")
|
|
}
|
|
}
|
|
// else if (Properties.isMac) ("darwin-amd64", "tar.gz") // todo c-lightning adding in a future release
|
|
else sys.error(s"Unsupported OS: ${Properties.osName}")
|
|
|
|
logger.debug(s"(Maybe) downloading clightning binaries for version: $version")
|
|
|
|
val versionDir = binaryDir resolve version
|
|
val location =
|
|
s"https://github.com/ElementsProject/lightning/releases/download/v$version/clightning-v$version-$platform.tar.xz"
|
|
|
|
if (Files.exists(versionDir)) {
|
|
logger.debug(
|
|
s"Directory $versionDir already exists, skipping download of clightning $version")
|
|
} else {
|
|
Files.createDirectories(versionDir)
|
|
val archiveLocation = binaryDir resolve s"$version.$suffix"
|
|
logger.info(
|
|
s"Downloading clightning version $version from location: $location")
|
|
logger.info(s"Placing the file in $archiveLocation")
|
|
val downloadCommand = url(location) #> archiveLocation.toFile
|
|
downloadCommand.!!
|
|
|
|
val bytes = Files.readAllBytes(archiveLocation)
|
|
val hash = MessageDigest
|
|
.getInstance("SHA-256")
|
|
.digest(bytes)
|
|
.map("%02x" format _)
|
|
.mkString
|
|
|
|
val expectedHash =
|
|
if (platform == "Ubuntu-20.04") {
|
|
"0068852306bca9df3d213c6a29bb90451eb538be83e413d6838e9e2d2729ff7f"
|
|
} else if (platform == "Ubuntu-22.04") {
|
|
"0c0763ff41656e0d76c955e4843894ea0c23c401ccde29e4ae369808862d4c0b"
|
|
}
|
|
else sys.error(s"Unsupported OS: ${Properties.osName}")
|
|
|
|
val success = hash.equalsIgnoreCase(expectedHash)
|
|
if (hash.equalsIgnoreCase(expectedHash)) {
|
|
logger.info(s"Download complete and verified, unzipping result")
|
|
|
|
val extractCommand = s"tar -xf $archiveLocation --directory $versionDir"
|
|
logger.info(s"Extracting archive with command: $extractCommand")
|
|
extractCommand.!!
|
|
} else {
|
|
logger.error(
|
|
s"Downloaded invalid version of c-lightning, got $hash, expected $expectedHash")
|
|
}
|
|
|
|
logger.info(s"Deleting archive")
|
|
Files.delete(archiveLocation)
|
|
|
|
if (!success) {
|
|
throw new RuntimeException(
|
|
s"Failed to download and verify clightning v$version")
|
|
}
|
|
}
|
|
}
|