diff --git a/bbootimg/src/main/kotlin/ota/Payload.kt b/bbootimg/src/main/kotlin/ota/Payload.kt index 87089e9..0301b34 100644 --- a/bbootimg/src/main/kotlin/ota/Payload.kt +++ b/bbootimg/src/main/kotlin/ota/Payload.kt @@ -18,6 +18,7 @@ import cc.cfig.io.Struct import cfig.helper.CryptoHelper.Hasher import cfig.helper.Dumpling import cfig.helper.Helper +import cfig.utils.EnvironmentVerifier import chromeos_update_engine.UpdateMetadata import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.ObjectMapper @@ -45,6 +46,7 @@ class Payload { companion object { private val log = LoggerFactory.getLogger(Payload::class.java) val workDir = Helper.prop("payloadDir") + val envv = EnvironmentVerifier() fun parse(inFileName: String): Payload { val ret = Payload() @@ -172,6 +174,8 @@ class Payload { } private fun decompress(inBytes: ByteArray, opType: UpdateMetadata.InstallOperation.Type): ByteArray { + check(envv.hasXzcat) { "xzcat not found" } + check(envv.hasBzcat) { "bzcat not found" } val baosO = ByteArrayOutputStream() val baosE = ByteArrayOutputStream() val bais = ByteArrayInputStream(inBytes) diff --git a/bbootimg/src/main/kotlin/utils/EnvironmentVerifier.kt b/bbootimg/src/main/kotlin/utils/EnvironmentVerifier.kt index cd203ed..53815f6 100644 --- a/bbootimg/src/main/kotlin/utils/EnvironmentVerifier.kt +++ b/bbootimg/src/main/kotlin/utils/EnvironmentVerifier.kt @@ -54,6 +54,34 @@ class EnvironmentVerifier { return true } + val hasXzcat: Boolean + get(): Boolean { + var ret = false + try { + val process = Runtime.getRuntime().exec(arrayOf("xzcat", "-V"), null, null) + log.debug("xzcat available") + val exitCode = process.waitFor() + ret = (exitCode == 0 && process.exitValue() == 0) + } catch (e: Exception) { + log.warn("xzcat unavailable") + } + return ret + } + + val hasBzcat: Boolean + get(): Boolean { + var ret = false + try { + val process = Runtime.getRuntime().exec(arrayOf("bzcat", "-V"), null, null) + log.debug("bzcat available") + val exitCode = process.waitFor() + ret = (exitCode == 0 && process.exitValue() == 0) + } catch (e: Exception) { + log.warn("bzcat unavailable") + } + return ret + } + val has7z: Boolean get(): Boolean { try { diff --git a/bbootimg/src/test/kotlin/EnvironmentVerifierTest.kt b/bbootimg/src/test/kotlin/EnvironmentVerifierTest.kt index cd70233..e0146ee 100644 --- a/bbootimg/src/test/kotlin/EnvironmentVerifierTest.kt +++ b/bbootimg/src/test/kotlin/EnvironmentVerifierTest.kt @@ -14,26 +14,40 @@ import cfig.utils.EnvironmentVerifier import org.junit.Test +import org.slf4j.LoggerFactory class EnvironmentVerifierTest { private val envv = EnvironmentVerifier() + private val log = LoggerFactory.getLogger(EnvironmentVerifier::class.java) @Test fun getHasDtc() { val hasDtc = envv.hasDtc - println("hasDtc = $hasDtc") + log.info("hasDtc = $hasDtc") } @Test fun getHasXz() { val hasXz = envv.hasXz - println("hasXz = $hasXz") + log.info("hasXz = $hasXz") } @Test fun getGzip() { val h = envv.hasGzip - println("hasGzip = $h") + log.info("hasGzip = $h") + } + + @Test + fun getXzcat() { + val h = envv.hasXzcat + log.info("hasXzcat = $h") + } + + @Test + fun getBzcat() { + val h = envv.hasBzcat + log.info("hasBzcat = $h") } } diff --git a/tools/release.mk b/tools/release.mk index 00d49e2..719e6ef 100644 --- a/tools/release.mk +++ b/tools/release.mk @@ -1,9 +1,9 @@ # # release.mk -# yu, 2020-12-20 00:19 +# yuyezhong@gmail.com, 2020-12-20 00:19 # define gw -#!/usr/bin/env sh\n +#!/usr/bin/bash\n if [ "x$$1" = "xassemble" ]; then\n echo "already assembled"\n exit\n @@ -16,7 +16,13 @@ if [ "x$$1" = "xclean" ]; then\n echo "no cleaning is needed"\n exit 0\n fi\n -java -jar bbootimg/bbootimg.jar $$* +if [[ "$$2" == "-Dpart="* ]]; then\n + set -x\n + java $$2 -jar bbootimg/bbootimg.jar $$1\n +else\n + set -x\n + java -jar bbootimg/bbootimg.jar $$*\n +fi endef