Compare commits

...

4 Commits

Author SHA1 Message Date
Maxwell Jeffress
2a8f65c953 I can't remember what I worked on just have a look 2024-09-19 13:17:06 +10:00
Maxwell Jeffress
75b49147df Add help dialog 2024-09-11 13:24:42 +10:00
Maxwell Jeffress
ea5bb86f7e Update package version 2024-09-11 13:17:12 +10:00
Maxwell Jeffress
4271b28acd Start work on deletions, command line arguments 2024-09-11 13:15:05 +10:00
3 changed files with 47 additions and 19 deletions

2
.gitignore vendored
View File

@ -9,6 +9,8 @@ gradlew
gradlew.bat gradlew.bat
.kotlin .kotlin
test
### IntelliJ IDEA ### ### IntelliJ IDEA ###
.idea .idea
.idea/modules.xml .idea/modules.xml

View File

@ -10,7 +10,7 @@ application {
} }
group = "xyz.maxwellj.mapm" group = "xyz.maxwellj.mapm"
version = "0.0.1" version = "0.0.2"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -13,6 +13,7 @@ import java.io.BufferedInputStream
import java.io.FileInputStream import java.io.FileInputStream
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.collections.listOf as listOf
fun uncompressXZFile(inputFile: String, outputFile: String) { fun uncompressXZFile(inputFile: String, outputFile: String) {
@ -52,21 +53,26 @@ fun md5(input:String): String {
return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0') return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0')
} }
suspend fun main() { suspend fun main(args: Array<String>) {
println("Welcome to Mapm! What would you like to do? Type help for some help.") var userInput: String = args[0]
println(userInput)
val userInput = readln() if (userInput == "g") {
if (userInput == "grab") { val userInput: String = args[1]
println("What would you like to grab?") val linkToUse = "https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput/source"
val userInput = readln()
val linkToUse = "https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput"
val dingus = Fuel.get(linkToUse).body.string() val dingus = Fuel.get(linkToUse).body.string()
println(dingus) 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 file = File("/usr/mapm/tmp/$userInput.tar.xz")
// file.writeBytes((Fuel.get(dingus).body.string()).toByteArray())
val fileBytes = Fuel.get(dingus).body.bytes() val fileBytes = Fuel.get(dingus).body.bytes()
file.writeBytes(fileBytes) file.writeBytes(fileBytes)
val fileChecksum = Fuel.get("https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput.hash").body.string() val fileChecksum = Fuel.get("https://git.maxwellj.xyz/mapm/stable/raw/branch/main/$userInput/hash").body.string()
if (fileChecksum == md5(file.readText())) { if (fileChecksum == md5(file.readText())) {
println("Checksum matches!") println("Checksum matches!")
uncompressXZFile(inputFile = "/usr/mapm/tmp/${userInput}.tar.xz", outputFile = "/usr/mapm/tmp/${userInput}.tar") uncompressXZFile(inputFile = "/usr/mapm/tmp/${userInput}.tar.xz", outputFile = "/usr/mapm/tmp/${userInput}.tar")
@ -79,13 +85,33 @@ 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.") 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) exitProcess(1)
} }
} else if (userInput == "delete") { } else if (userInput == "r") {
println("What would you like to delete?") val executable = File("/usr/mapm/${args[1]}")
val userInput = readln() println("Deleting package ${args[1]}")
} else if (userInput == "checksum") { println("Is this okay? (y/n)")
println("What file would you like to generate a checksum of? Type the whole path") var userInput = readln()
val userInput = readln() if (userInput != "y") {
executable.delete()
}
} else if (userInput == "c") {
val userInput = args[1]
val file = File(userInput) val file = File(userInput)
println("Checksum of that file is ${md5(file.readText())}") println("Checksum of that file is ${md5(file.readText())}")
} else if (userInput == "m") {
println("this feature is in progress")
} else {
println("mapm - Max's Package Manager")
println("Version 0.0.2")
println("(C) Maxwell Jeffress 2024, licensed under the GNU GPL V3")
println("")
println("---Help---")
println("Arguments that can be run")
println("g Grab a package from the internet")
println("r Remove a package")
println("c Generate a checksum for a package")
println("")
println("More info at the following links:")
println("https://maxwellj.xyz/mapm")
println("https://git.maxwellj.xyz/max/mapm")
} }
} }