Skip to content

Commit

Permalink
Replace shell2http -> httpshd in code and in backgrond cmd start broa…
Browse files Browse the repository at this point in the history
…d cast
  • Loading branch information
puutaro committed Jul 8, 2024
1 parent a7c127c commit 29dad15
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ enum class UbuntuServerIntentExtra(
ubuntuStartCommand("ubuntu_start_command"),
ubuntuRestoreSign("ubuntu_restore_sign"),
ubuntuCroutineJobTypeListForKill("ubuntu_coroutine_job_type"),
adminShellPath("shell_path"),
adminArgsTabSepaStr("args"),
adminMonitorFileName("monitor_file_name"),
// adminShellPath("shell_path"),
// adminArgsTabSepaStr("args"),
// adminMonitorFileName("monitor_file_name"),
backgroundShellPath("shell_path"),
backgroundArgsTabSepaStr("args"),
backgroundMonitorFileName("monitor_file_name"),
Expand All @@ -18,4 +18,6 @@ enum class UbuntuServerIntentExtra(
foregroundShellPath("shell_path"),
foregroundArgsTabSepaStr("args"),
foregroundTimeout("foreground_timeout"),
// foregroundResFilePath("res_file_path"),
// foregroundAsProc("as_proc"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ enum class BroadCastIntentSchemeUbuntu(
"com.puutaro.commandclick.ubuntu_service.background_cmd_start",
"background_cmd_start",
),
ADMIN_CMD_START(
"com.puutaro.commandclick.ubuntu_service.admin_cmd_start",
"admin_cmd_start",
),
// ADMIN_CMD_START(
// "com.puutaro.commandclick.ubuntu_service.admin_cmd_start",
// "admin_cmd_start",
// ),
RESTART_UBUNTU_SERVICE_FROM_ACTIVITY(
"com.puutaro.commandclick.ubuntu_service.restart",
"restart",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ import com.puutaro.commandclick.common.variable.path.UsePath
import com.puutaro.commandclick.fragment.TerminalFragment
import com.puutaro.commandclick.fragment_lib.terminal_fragment.js_interface.dialog.JsDialog
import com.puutaro.commandclick.proccess.broadcast.BroadcastSender
import com.puutaro.commandclick.proccess.ubuntu.ResAndProcess
import com.puutaro.commandclick.proccess.ubuntu.Shell2Http
import com.puutaro.commandclick.proccess.ubuntu.SshManager
import com.puutaro.commandclick.proccess.ubuntu.UbuntuController
import com.puutaro.commandclick.proccess.ubuntu.UbuntuFiles
import com.puutaro.commandclick.proccess.ubuntu.UbuntuProcessChecker
import com.puutaro.commandclick.util.CcPathTool
import com.puutaro.commandclick.util.CommandClickVariables
import com.puutaro.commandclick.util.Intent.CurlManager
import com.puutaro.commandclick.util.JavaScriptLoadUrl
import com.puutaro.commandclick.util.file.ReadText
import com.puutaro.commandclick.util.shell.LinuxCmd
import io.ktor.http.ContentDisposition.Companion.File
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File


class JsUbuntu(
Expand All @@ -36,30 +42,35 @@ class JsUbuntu(
executeShellPath:String,
tabSepaArgs: String,
): String {
return execScriptF(
if(
!UbuntuProcessChecker.isExist(
context,
null
)
) return String()
return Shell2Http.runScript(
context,
executeShellPath,
tabSepaArgs,
2000,
)
}



@JavascriptInterface
fun execScriptF(
executeShellPath:String,
tabSepaArgs: String,
timeMilisec: Int,
): String {
if (
context == null
if(
!UbuntuProcessChecker.isExist(
context,
null
)
) return String()
if (
!UbuntuFiles(context).ubuntuLaunchCompFile.isFile
) {
ToastUtils.showShort("Launch ubuntu")
return String()
}
return Shell2Http.runCmd(
return Shell2Http.runScript(
context,
executeShellPath,
tabSepaArgs,
Expand All @@ -68,30 +79,30 @@ class JsUbuntu(
}


@JavascriptInterface
fun execScriptBySsh(
executeShellPath:String,
tabSepaArgs: String,
monitorNum: Int,
): String {
if(
context == null
) return String()
if(
!UbuntuFiles(context).ubuntuLaunchCompFile.isFile
) {
ToastUtils.showShort("Launch ubuntu")
return String()
}
val monitorFileName = UsePath.decideMonitorName(monitorNum)
return SshManager.execScript(
context,
executeShellPath,
tabSepaArgs,
monitorFileName,
true,
)
}
// @JavascriptInterface
// fun execScriptBySsh(
// executeShellPath:String,
// tabSepaArgs: String,
// monitorNum: Int,
// ): String {
// if(
// context == null
// ) return String()
// if(
// !UbuntuFiles(context).ubuntuLaunchCompFile.isFile
// ) {
// ToastUtils.showShort("Launch ubuntu")
// return String()
// }
// val monitorFileName = UsePath.decideMonitorName(monitorNum)
// return SshManager.execScript(
// context,
// executeShellPath,
// tabSepaArgs,
// monitorFileName,
// true,
// )
// }

@JavascriptInterface
fun execScriptByBackground(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.puutaro.commandclick.proccess.ubuntu

import android.content.Context
import com.puutaro.commandclick.common.variable.broadcast.extra.UbuntuServerIntentExtra
import com.puutaro.commandclick.common.variable.broadcast.scheme.BroadCastIntentSchemeUbuntu
import com.puutaro.commandclick.proccess.broadcast.BroadcastSender
import com.puutaro.commandclick.util.shell.LinuxCmd
import kotlinx.coroutines.delay
import java.io.File

object ResAndProcess {
suspend fun wait(
context: Context?,
resFilePath: String,
procName: String,
){
var beforeLength = 0L
val resFilePathObj = File(resFilePath)
val twoSec = 2000
val waitMilliSec = 200L
val waitTimes = 200
for (i in 1..waitTimes) {
delay(waitMilliSec)
val soFarWaitTime = i * waitMilliSec
if(
soFarWaitTime > twoSec
&& !LinuxCmd.isProcessCheck(
context,
procName
)
) break
if (
!resFilePathObj.isFile
) {
continue
}
val resFileLen = resFilePathObj.length()
if(beforeLength != resFileLen){
beforeLength = resFileLen
continue
}
if(
LinuxCmd.isProcessCheck(
context,
procName
)
) continue
break
}
BroadcastSender.normalSend(
context,
BroadCastIntentSchemeUbuntu.CMD_KILL_BY_ADMIN.action,
listOf(
UbuntuServerIntentExtra.ubuntuCroutineJobTypeListForKill.schema to
procName
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.puutaro.commandclick.proccess.ubuntu

import com.puutaro.commandclick.util.str.QuoteTool

object UbuntuCmdTool {
fun makeRunBashScript(
shellPath: String,
tabSepaArgs: String
): String {
val args =
tabSepaArgs.replace(Regex("[\t]+"), "\t")
.split("\t")
.map {
QuoteTool.compBothQuote(
it,
"\""
)
}.joinToString("\t")
return listOf(
"bash",
"\"${shellPath}\"",
args
).joinToString(" ")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.puutaro.commandclick.BuildConfig


object UbuntuInfo {
val user = "cmdclick"
const val user = "cmdclick"

private const val devFalseInRelease = false
private val createImageSwitchOffInRelease = CreateImageSwitch.off.name
private val createImageSwitchForRelease = CreateImageSwitch.off.name
private val buildConfigDebug = BuildConfig.DEBUG

// for development
Expand All @@ -19,7 +19,7 @@ object UbuntuInfo {
val createImageSwitch = if(
buildConfigDebug
) CreateImageSwitch.on.name
else createImageSwitchOffInRelease
else createImageSwitchForRelease

val arm64UbuntuRootfsUrl =
decideArm64UbuntuRootfsUrl(createImageSwitch)
Expand All @@ -32,7 +32,7 @@ object UbuntuInfo {
-> "https://partner-images.canonical.com/core/jammy/" +
"current/ubuntu-jammy-core-cloudimg-arm64-root.tar.gz"
else
-> "https://github.com/puutaro/CommandClick-Linux/releases/download/v1.1.5/rootfs.tar.gz"
-> "https://github.com/puutaro/CommandClick-Linux/releases/download/v1.1.6/rootfs.tar.gz"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.puutaro.commandclick.proccess.ubuntu

import android.content.Context
import com.blankj.utilcode.util.ToastUtils
import com.puutaro.commandclick.common.variable.broadcast.scheme.BroadCastIntentSchemeUbuntu
import com.puutaro.commandclick.proccess.broadcast.BroadcastSender
import com.puutaro.commandclick.util.shell.LinuxCmd

object UbuntuProcessChecker {
fun isExist(
context: Context?,
ubuntuFilesSrc: UbuntuFiles?
): Boolean {
if(
context == null
) return false
val ubuntuFiles = when(ubuntuFilesSrc == null){
true -> UbuntuFiles(context)
false -> ubuntuFilesSrc
}
if (
!ubuntuFiles.ubuntuLaunchCompFile.isFile
) {
ToastUtils.showShort("Launch ubuntu")
return false
}
if(
!LinuxCmd.isBasicProcess(context)
) {
BroadcastSender.normalSend(
context,
BroadCastIntentSchemeUbuntu.STOP_UBUNTU_SERVICE.action
)
return false
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class UbuntuService:
BroadCastIntentSchemeUbuntu.UPDATE_PROCESS_NUM_NOTIFICATION.action,
BroadCastIntentSchemeUbuntu.ON_SLEEPING_NOTIFICATION.action,
BroadCastIntentSchemeUbuntu.OPEN_FANNEL.action,
BroadCastIntentSchemeUbuntu.ADMIN_CMD_START.action,
// BroadCastIntentSchemeUbuntu.ADMIN_CMD_START.action,
BroadCastIntentSchemeUbuntu.BACKGROUND_CMD_START.action,
BroadCastIntentSchemeUbuntu.FOREGROUND_CMD_START.action,
BroadCastIntentSchemeUbuntu.CMD_KILL_BY_ADMIN.action,
Expand Down
Loading

0 comments on commit 29dad15

Please sign in to comment.