Skip to content

Commit

Permalink
torizonEmulatorManager: add recipe to fetch and deploy the scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Castello <[email protected]>
  • Loading branch information
microhobby committed Jun 4, 2024
1 parent 0d6902a commit 307c91c
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
70 changes: 70 additions & 0 deletions cookbook/recipes-wsl/torizonEmulatorManager/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/opt/bun/bin/bun

import PATH from "path"
import FS from "fs"
import logger from "node-color-log"
import { execSync } from "child_process"

const ARCH = process.env.ARCH as string
const MACHINE = process.env.MACHINE as string
const MAX_IMG_SIZE = process.env.MAX_IMG_SIZE as string
const BUILD_PATH = process.env.BUILD_PATH as string
const DISTRO_MAJOR = process.env.DISTRO_MAJOR as string
const DISTRO_MINOR = process.env.DISTRO_MINOR as string
const DISTRO_PATCH = process.env.DISTRO_PATCH as string
const USER_PASSWD = process.env.USER_PASSWD as string

// get the actual script path, not the process.cwd
const _path = PATH.dirname(process.argv[1])
const meta = JSON.parse(process.env.META as string)

const IMAGE_MNT_BOOT = `${BUILD_PATH}/tmp/${MACHINE}/mnt/boot`
const IMAGE_MNT_ROOT = `${BUILD_PATH}/tmp/${MACHINE}/mnt/root`
process.env.IMAGE_MNT_BOOT = IMAGE_MNT_BOOT
process.env.IMAGE_MNT_ROOT = IMAGE_MNT_ROOT

logger.info(`deploy ${meta.name} ...`)

// create the path only in case
execSync(
`echo ${USER_PASSWD} | sudo -E -S ` +
`mkdir -p ${IMAGE_MNT_ROOT}/opt/${meta.name}`,
{
shell: "/bin/bash",
stdio: "inherit",
encoding: "utf-8",
env: process.env
})

for (let _file of meta.files) {
const _file_path = `${BUILD_PATH}/tmp/${MACHINE}/${meta.name}/${_file}`

// copy the files to the rootfs
execSync(
`echo ${USER_PASSWD} | sudo -E -S ` +
`cp ${_file_path} ${IMAGE_MNT_ROOT}/opt/${meta.name}/${_file}`,
{
shell: "/bin/bash",
stdio: "inherit",
encoding: "utf-8",
env: process.env
})
}

// create a symlink to the /usr/bin
execSync(
`echo ${USER_PASSWD} | sudo -E -S ` +
`chroot ${IMAGE_MNT_ROOT} /bin/bash -c "` +
`ln -sf /opt/${meta.name}/torizon-emulator-manager /usr/bin/emulator && ` +
`ln -sf /opt/${meta.name}/torizon-emulator-manager /usr/bin/torizon-emulator-manager && ` +
`chmod +x /usr/bin/torizon-emulator-manager && ` +
`chmod +x /usr/bin/emulator` +
`"`,
{
shell: "/bin/bash",
stdio: "inherit",
encoding: "utf-8",
env: process.env
})

logger.success(`Deployed ${meta.name}!`)
44 changes: 44 additions & 0 deletions cookbook/recipes-wsl/torizonEmulatorManager/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/opt/bun/bin/bun

import PATH from "path"
import FS from "fs"
import logger from "node-color-log"
import { execSync } from "child_process"

const ARCH = process.env.ARCH as string
const MACHINE = process.env.MACHINE as string
const MAX_IMG_SIZE = process.env.MAX_IMG_SIZE as string
const BUILD_PATH = process.env.BUILD_PATH as string
const DISTRO_MAJOR = process.env.DISTRO_MAJOR as string
const DISTRO_MINOR = process.env.DISTRO_MINOR as string
const DISTRO_PATCH = process.env.DISTRO_PATCH as string
const USER_PASSWD = process.env.USER_PASSWD as string

// get the actual script path, not the process.cwd
const _path = PATH.dirname(process.argv[1])
const meta = JSON.parse(process.env.META as string)


logger.info(`fetch ${meta.name} ...`)

// create the path only in case
FS.mkdirSync(
`${BUILD_PATH}/tmp/${MACHINE}/${meta.name}`, { recursive: true }
)

logger.info(`Fetching ${meta.source} ...`)

for (let _file of meta.files) {
const _file_path = `${BUILD_PATH}/tmp/${MACHINE}/${meta.name}/${_file}`

execSync(
`wget ${meta.source}/${_file} -O ${_file_path}`,
{
shell: "/bin/bash",
stdio: "inherit",
encoding: "utf-8"
}
)
}

logger.success(`Fetched ${meta.name}!`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "torizon-emulator-manager",
"type": "application",
"priority": 0,
"support": [
"linux/amd64"
],
"source": "https://github.com/commontorizon/torizonEmulatorManager/releases/download/0.0.22/",
"files": [
"docker-compose.yml",
"torizon-emulator-manager"
],
"hostDeps": [
"unzip"
],
"targetDeps": [
"libfontconfig1",
"mesa-utils",
"x11-xserver-utils",
"libxkbcommon-x11-0",
"xkb-data",
"libfreetype6",
"libgbm1",
"libinput10",
"libxkbcommon0"
],
"fetchRecipes": [
"fetch.ts"
],
"deployRecipes": [
"deploy.ts"
]
}

0 comments on commit 307c91c

Please sign in to comment.