Update src/main/kotlin/Main.kt
This commit is contained in:
parent
f73a32e72c
commit
7ff00d7cf0
|
@ -15,7 +15,6 @@ import java.nio.file.Files
|
|||
import java.nio.file.Paths
|
||||
import kotlin.collections.listOf as listOf
|
||||
|
||||
|
||||
fun uncompressXZFile(inputFile: String, outputFile: String) {
|
||||
XZInputStream(FileInputStream(inputFile)).use { input ->
|
||||
FileOutputStream(outputFile).use { output ->
|
||||
|
@ -53,6 +52,33 @@ fun md5(input:String): String {
|
|||
return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0')
|
||||
}
|
||||
|
||||
suspend fun grabDependencies(input:String): String {
|
||||
val dependencyList = Fuel.get("https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$input/dependencies").body.string()
|
||||
return(dependencyList)
|
||||
}
|
||||
|
||||
suspend fun grabPackage(input:String): Int {
|
||||
println("Downloading package $input...")
|
||||
val linkToUse = "https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$input/source"
|
||||
val packageLocation = Fuel.get(linkToUse).body.string()
|
||||
val file = File("/usr/mapm/tmp/$input.tar.xz")
|
||||
val fileBytes = Fuel.get(packageLocation).body.bytes()
|
||||
file.writeBytes(fileBytes)
|
||||
val fileChecksum = Fuel.get("https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$input/hash").body.string()
|
||||
if (fileChecksum == md5(file.readText())) {
|
||||
println("Checksum matches!")
|
||||
uncompressXZFile(inputFile = "/usr/mapm/tmp/${input}.tar.xz", outputFile = "/usr/mapm/tmp/${input}.tar")
|
||||
unarchiveTarFile(tarFilePath = "/usr/mapm/tmp/${input}.tar", outputDirectoryPath = "/usr/mapm/")
|
||||
Runtime.getRuntime().exec("chmod +x /usr/mapm/${input}")
|
||||
println("Finished!")
|
||||
return(0)
|
||||
} else {
|
||||
println("Checksum doesn't match! Aborting...")
|
||||
println("Please tell Max or your app's developer to use mapm to generate a new checksum. If the checksum is right, check your internet connection security.")
|
||||
return(1)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun main(args: Array<String>) {
|
||||
if (args.size < 2) {
|
||||
if (args.size == 1) {
|
||||
|
@ -84,39 +110,32 @@ suspend fun main(args: Array<String>) {
|
|||
if (userInput == "g") {
|
||||
val userInput: String = args[1]
|
||||
val linkToUse = "https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput/source"
|
||||
val dingus = Fuel.get(linkToUse).body.string()
|
||||
println("Package $userInput found at $dingus")
|
||||
// val packageList = listOf($userInput)
|
||||
println("Downloading package $userInput")
|
||||
val packageLocation = Fuel.get(linkToUse).body.string()
|
||||
val dependencies = grabDependencies(userInput)
|
||||
println("Downloading packages $userInput $dependencies")
|
||||
println("Is this okay?")
|
||||
val userInputInteractive: String = readln()
|
||||
if (userInputInteractive != "y") {
|
||||
println("Confirmation not given. Exiting...")
|
||||
exitProcess(0)
|
||||
println("Confirmation not given. Exiting...")
|
||||
exitProcess(0)
|
||||
}
|
||||
val file = File("/usr/mapm/tmp/$userInput.tar.xz")
|
||||
val fileBytes = Fuel.get(dingus).body.bytes()
|
||||
file.writeBytes(fileBytes)
|
||||
val fileChecksum = Fuel.get("https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput/hash").body.string()
|
||||
if (fileChecksum == md5(file.readText())) {
|
||||
println("Checksum matches!")
|
||||
uncompressXZFile(inputFile = "/usr/mapm/tmp/${userInput}.tar.xz", outputFile = "/usr/mapm/tmp/${userInput}.tar")
|
||||
unarchiveTarFile(tarFilePath = "/usr/mapm/tmp/${userInput}.tar", outputDirectoryPath = "/usr/mapm/")
|
||||
Runtime.getRuntime().exec("chmod +x /usr/mapm/${userInput}")
|
||||
println("Finished!")
|
||||
exitProcess(0)
|
||||
} else {
|
||||
println("Checksum doesn't match! Aborting...")
|
||||
println("Please tell Max or your app's developer to use mapm to generate a new checksum. If the checksum is right, check your internet connection security.")
|
||||
exitProcess(1)
|
||||
}
|
||||
var currentPackage = ""
|
||||
for (char in dependencies) {
|
||||
if (char.toString() != " ") {
|
||||
currentPackage += char.toString()
|
||||
} else {
|
||||
grabPackage(currentPackage)
|
||||
var currentPackage = ""
|
||||
}
|
||||
}
|
||||
grabPackage(userInput)
|
||||
} else if (userInput == "r") {
|
||||
val executable = File("/usr/mapm/${args[1]}")
|
||||
println("Deleting package ${args[1]}")
|
||||
println("Is this okay? (y/n)")
|
||||
var userInput = readln()
|
||||
if (userInput != "y") {
|
||||
executable.delete()
|
||||
executable.delete()
|
||||
}
|
||||
} else if (userInput == "c") {
|
||||
val userInput = args[1]
|
||||
|
@ -140,4 +159,4 @@ suspend fun main(args: Array<String>) {
|
|||
println("https://maxwellj.xyz/mapm")
|
||||
println("https://git.maxwellj.xyz/max/mapm")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user