Skip to content

Commit

Permalink
somehow working cloud install.sh downloader (todo add_os)
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Jul 31, 2024
1 parent 333445c commit 1fe0d4d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) {
Input(vm)
}, WizardPage("shSel",
NavButton(vm.activity.getString(R.string.prev)) { it.navigate("input") },
NavButton(vm.activity.getString(R.string.next)) {}
NavButton("") {}
) {
SelectInstallSh(vm)
}, WizardPage("select",
Expand Down Expand Up @@ -150,7 +150,7 @@ fun SelectDroidBoot(vm: WizardActivityState) {
val json = JSONTokener(jsonText).nextValue() as JSONObject
val bl = json.getJSONObject("bootloader")
val url = bl.getString("url")
val sha = bl.getString("sha256")
val sha = if (bl.has("sha256")) bl.getString("sha256") else null
vm.flashes[flashType] = Pair(Uri.parse(url), sha)
nextButtonAvailable.value = true
} catch (e: Exception) {
Expand Down Expand Up @@ -181,7 +181,7 @@ fun SelectInstallSh(vm: WizardActivityState) {
vm.nextText.value = stringResource(id = R.string.next)
vm.onNext.value = { it.navigate(if (!vm.deviceInfo!!.isBooted(vm.logic)) "select" else "flash") }
} else {
Text(stringResource(R.string.choose_droidboot_online))
Text(stringResource(R.string.choose_install_s_online))
Button(onClick = {
vm.activity.chooseFile("*/*") {
vm.flashes[flashType] = Pair(it, null)
Expand All @@ -197,16 +197,16 @@ fun SelectInstallSh(vm: WizardActivityState) {
val jsonText =
URL("https://raw.githubusercontent.com/Android-Boot-Manager/ABM-json/master/devices/" + vm.codename + ".json").readText()
val json = JSONTokener(jsonText).nextValue() as JSONObject
val bl = json.getJSONObject("installScript")
val url = bl.getString("url")
val sha = bl.getString("sha256")
val i = json.getJSONObject("installScript")
val url = i.getString("url")
val sha = if (i.has("sha256")) i.getString("sha256") else null
vm.flashes[flashType] = Pair(Uri.parse(url), sha)
nextButtonAvailable.value = true
} catch (e: Exception) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(ctx, R.string.dl_error, Toast.LENGTH_LONG).show()
}
Log.e("ABM droidboot json", Log.getStackTraceString(e))
Log.e("ABM install json", Log.getStackTraceString(e))
}
}.start()
}) {
Expand Down Expand Up @@ -345,6 +345,7 @@ private fun Flash(vm: WizardActivityState) {
"BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=true " +
"${tmpFile.absolutePath} real"
).to(terminal).exec()
tmpFile.delete()
}
terminal.add(vm.activity.getString(R.string.term_success))
vm.logic.unmountBootset()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private fun Flash(vm: WizardActivityState) {
"BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=true " +
"${tmpFile.absolutePath} real"
).to(terminal).exec()
tmpFile.delete()
}
terminal.add(vm.activity.getString(R.string.term_success))
vm.activity.runOnUiThread {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/andbootmgr/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,11 @@ private fun PartTool(vm: MainActivityState) {
Button(onClick = {
processing = true
delete = false
val wasMounted = vm.logic!!.mounted
vm.logic!!.unmountBootset()
vm.logic!!.delete(p).submit {
vm.logic!!.mountBootset(vm.deviceInfo!!)
if (wasMounted != vm.logic!!.mounted) vm.activity!!.finish()
processing = false
editPartID = null
parts = SDUtils.generateMeta(vm.deviceInfo!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private fun Flash(vm: WizardActivityState) {
"BOOTED=${vm.deviceInfo.isBooted(vm.logic)} SETUP=false " +
"${tmpFile.absolutePath} real"
).to(terminal).exec()
tmpFile.delete()
}
terminal.add(vm.activity.getString(R.string.term_success))
vm.activity.runOnUiThread {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/andbootmgr/app/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActionAbortedCleanlyError(e: Exception?) : ActionAbortedError(e)

@Throws(IOException::class)
private fun generateFile(prefix: String, suffix: String, dir: File?): File {
var n = Math.random().toLong()
var n = (Math.random() * Long.MAX_VALUE).toLong()
n = if (n == Long.MIN_VALUE) {
0 // corner case
} else {
Expand All @@ -44,7 +44,7 @@ fun createTempFileSu(
var f: File
do {
f = generateFile(prefix, suffix ?: ".tmp", tmpdir)
} while (!f.exists())
} while (f.exists())
val ff = SuFile.open(f.toURI())

if (!ff.createNewFile()) throw IOException("Unable to create temporary file")
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/org/andbootmgr/app/util/Toolkit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Toolkit(private val ctx: Context) {
private val targetPath = File(ctx.filesDir.parentFile, "assets")

fun copyAssets(uinf: Runnable, callback: Consumer<Boolean>) {
if (!targetPath.exists()) fail = fail or !targetPath.mkdir()
if (!File(ctx.filesDir.parentFile, "files").exists()) fail = fail or !File(ctx.filesDir.parentFile, "files").mkdir()
if (!File(ctx.filesDir.parentFile, "cache").exists()) fail = fail or !File(ctx.filesDir.parentFile, "cache").mkdir()
val shell = Shell.Builder.create().setFlags(FLAG_NON_ROOT_SHELL).setTimeout(30).setContext(ctx).build()
var input: InputStream
var b: ByteArray
try {
Expand All @@ -40,12 +38,15 @@ class Toolkit(private val ctx: Context) {
val s2 = String(b).trim()
if (s != s2) {
uinf.run()
shell.newJob().add("rm -rf " + targetPath.absolutePath).exec()
if (!targetPath.exists()) fail = fail or !targetPath.mkdir()
if (!File(ctx.filesDir.parentFile, "files").exists()) fail = fail or !File(ctx.filesDir.parentFile, "files").mkdir()
if (!File(ctx.filesDir.parentFile, "cache").exists()) fail = fail or !File(ctx.filesDir.parentFile, "cache").mkdir()
copyAssets("Toolkit", "Toolkit")
copyAssets("Scripts", "Scripts")
copyAssets("cp", "")
}
Shell.Builder.create().setFlags(FLAG_NON_ROOT_SHELL).setTimeout(30).setContext(ctx).build().newJob()
.add("chmod -R +x " + targetPath.absolutePath).exec()
shell.newJob().add("chmod -R +x " + targetPath.absolutePath).exec()
callback.accept(fail)
}

Expand Down

0 comments on commit 1fe0d4d

Please sign in to comment.