diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 464ef3f..3495217 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -13,6 +13,7 @@ import java.io.BufferedInputStream import java.io.FileInputStream import java.nio.file.Files import java.nio.file.Paths +import kotlin.collections.listOf as listOf fun uncompressXZFile(inputFile: String, outputFile: String) { @@ -52,18 +53,23 @@ fun md5(input:String): String { return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0') } -suspend fun main() { - println("Welcome to Mapm! What would you like to do? Type help for some help.") - - val userInput = readln() - if (userInput == "grab") { - println("What would you like to grab?") - val userInput = readln() +suspend fun main(args: Array) { + var userInput: String = args[0] + println(userInput) + if (userInput == "g") { + val userInput: String = args[1] val linkToUse = "https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput" val dingus = Fuel.get(linkToUse).body.string() - println(dingus) - val file = File("/usr/mapm/tmp/$userInput.tar.xz") - // file.writeBytes((Fuel.get(dingus).body.string()).toByteArray()) + println("Package $userInput found at $dingus") + // val packageList = listOf($userInput) + println("Downloading package $userInput") + println("Is this okay?") + val userInputInteractive: String = readln() + if (userInputInteractive != "y") { + 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() @@ -79,12 +85,16 @@ suspend fun main() { 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) } - } else if (userInput == "delete") { - println("What would you like to delete?") - val userInput = readln() - } else if (userInput == "checksum") { - println("What file would you like to generate a checksum of? Type the whole path") - val userInput = readln() + } 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() + } + } else if (userInput == "c") { + val userInput = args[1] val file = File(userInput) println("Checksum of that file is ${md5(file.readText())}") }