From 7cc032cdf4b3e39be0ee8b538fe9beb3e50fbe07 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Fri, 3 May 2019 00:59:47 +0200 Subject: [PATCH] Add afterPack script --- scripts/afterAllArtifactBuild.ts | 1 - scripts/afterPack.ts | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 scripts/afterPack.ts diff --git a/scripts/afterAllArtifactBuild.ts b/scripts/afterAllArtifactBuild.ts index cac4cfd..bc40b77 100644 --- a/scripts/afterAllArtifactBuild.ts +++ b/scripts/afterAllArtifactBuild.ts @@ -15,7 +15,6 @@ export default async function(info: any) { await exec('sudo', ['chmod', '-R', 'g-s', 'squashfs-root']) // Add command line argument to disable the sandbox - await exec('sudo', ['sed', "-i''", 's/^exec \\([^;]*\\)$/exec \\1 --no-sandbox/g', 'squashfs-root/command.sh']) await exec('sudo', ['snap', 'run', 'snapcraft', 'pack', 'squashfs-root', '--output', snapFile]) await exec('sudo', ['rm', '-rf', 'squashfs-root']) diff --git a/scripts/afterPack.ts b/scripts/afterPack.ts new file mode 100644 index 0000000..dda0ed5 --- /dev/null +++ b/scripts/afterPack.ts @@ -0,0 +1,36 @@ +import * as fs from 'fs-extra' +import * as path from 'path' +import { chdir } from 'process' +import { exec } from './util' + + +interface Target { + name: 'appImage' | string +} + +interface Context { + appOutDir: string // .../build/clean/build/linux-unpacked + outDir: string // .../build/clean/build + targets: [Target] +} + +export default async function(context: Context) { + console.log(context) + const isLinux = context.targets.find(target => target.name === 'appImage' || target.name === 'snap') + if (!isLinux) { + return + } + + const originalDir = process.cwd() + const dirname = context.appOutDir + chdir(dirname) + + await exec('mv', ['mqtt-explorer', 'mqtt-explorer.bin']) + const wrapperScript = `#!/bin/bash + "\${BASH_SOURCE%/*}"/mqtt-explorer.bin "$@" --no-sandbox + ` + fs.writeFileSync('mqtt-explorer', wrapperScript) + await exec('chmod', ['+x', 'mqtt-explorer']) + + chdir(originalDir) +}