Created
February 17, 2021 19:01
-
-
Save sl5net/c05902b26e82f2aca7137cacf0bd8cb2 to your computer and use it in GitHub Desktop.
tested in Kubuntu v20.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//# here SH-file is autogenerated by a kotlin script. | |
//# it reads revision number from website, gets it, and starts 0ad | |
//# works in kubuntu v 20.04 | |
import java.io.File | |
import java.lang.Exception | |
import java.net.URL | |
import java.net.URLConnection | |
import java.util.* | |
fun main(args: Array<String>) { | |
val userHome = System.getProperty("user.home") | |
val path = System.getProperty(userHome) | |
val scriptPre = """ | |
# this file is autogenerated by a kotlin script. | |
# it reads revision number from website, gets it, and starts 0ad | |
# works in kubuntu v 20.04 | |
# maybe check here manuel: https://wildfiregames.com/forum/topic/36379-release-candidate-2-alpha-24-x%C5%A1ay%C4%81r%C5%A1%C4%81 | |
cd ~/svn; | |
svn up -r """ | |
val scriptPost = """; # <== sets working back to this revision number | |
cd ~/svn/0ad/build/workspaces ; ./update-workspaces.sh -j13 | |
cd ~/svn/0ad/build/workspaces/gcc ; make -j13 | |
~/svn/0ad/binaries/system/pyrogenesis & | |
""" | |
val regex = """(?<preSting>Revision[ ]*:[ ]*[rP]*)(?<revNumber>\d+)""".toRegex() // Revision: rP24928 | |
var content: String? = null | |
var connection: URLConnection? = null | |
try { | |
connection = URL("https://wildfiregames.com/forum/topic/36379-release-candidate-2-alpha-24-x%C5%A1ay%C4%81r%C5%A1%C4%81").openConnection() | |
val scanner = Scanner(connection.getInputStream()) | |
scanner.useDelimiter("\\Z") | |
content = scanner.next() | |
var matchResult = regex.find(content) | |
val (preSting, revNumber) = matchResult!!.destructured | |
if (matchResult != null) { | |
matchResult = matchResult.next() | |
println(matchResult!!.value) | |
println(matchResult!!.groupValues) | |
println("revNumber= $revNumber" ) | |
scanner.close() | |
val scriptAll = scriptPre + revNumber + scriptPost | |
File("$userHome/sh-scripts/0ad-get-Revision-and-start.sh").bufferedWriter().use { out -> | |
out.write(scriptAll) | |
} | |
} // next returns null when there are no more matches. | |
scanner.close() | |
} catch (ex: Exception) { | |
ex.printStackTrace() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment