-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1001 from ubports/restart
- Fix a couple restart-related issues. Fixes #963, fixes #959. - Only restart current step on oem unlock - Basic support for ubports/installer-configs#7 - Work around #961 by showing a particle screen as soon as we're waiting for the super slow api, so the user knows something is going on - Always show OS select screen to give our users a chance to get acquainted with the concept of having more than one os available
- Loading branch information
Showing
33 changed files
with
906 additions
and
533 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
"use strict" | ||
"use strict"; | ||
|
||
/* | ||
|
@@ -10,63 +10,92 @@ Author: Marius Gripsgard <[email protected]> | |
*/ | ||
|
||
const builder = require("electron-builder") | ||
const builder = require("electron-builder"); | ||
const cli = require("commander"); | ||
const unzip = require("unzipper"); | ||
const path = require("path"); | ||
const fs = require("fs-extra"); | ||
const download = require('download'); | ||
const download = require("download"); | ||
const events = require("events"); | ||
class event extends events {} | ||
const Platform = builder.Platform | ||
const platformToolsPath = "./platform-tools" | ||
const Platform = builder.Platform; | ||
const platformToolsPath = "./platform-tools"; | ||
const platformToolsUrls = { | ||
"linux": "https://dl.google.com/android/repository/platform-tools-latest-linux.zip", | ||
"mac": "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip", | ||
"win": "https://dl.google.com/android/repository/platform-tools-latest-windows.zip" | ||
} | ||
linux: | ||
"https://dl.google.com/android/repository/platform-tools-latest-linux.zip", | ||
mac: | ||
"https://dl.google.com/android/repository/platform-tools-latest-darwin.zip", | ||
win: | ||
"https://dl.google.com/android/repository/platform-tools-latest-windows.zip" | ||
}; | ||
|
||
function getAndroidPlatformTools() { | ||
return [{ | ||
url: platformToolsUrls[cli.os], | ||
path: platformToolsPath, | ||
target: cli.os | ||
}]; | ||
return [ | ||
{ | ||
url: platformToolsUrls[cli.os], | ||
path: platformToolsPath, | ||
target: cli.os | ||
} | ||
]; | ||
} | ||
|
||
function extractPlatformTools(platformToolsArray, callback) { | ||
var i = platformToolsArray[0]; | ||
fs.createReadStream(path.join(i.path, path.basename(i.url))).pipe(unzip.Extract({ | ||
path: path.join(i.path, i.target + "_tmp") | ||
})).on("close", () => { | ||
fs.move(path.join(i.path, i.target + "_tmp", "platform-tools"), path.join(i.path, i.target), { | ||
overwrite: true | ||
}, (e) => { | ||
fs.removeSync(path.join(i.path, i.target + "_tmp")); | ||
if (cli.os !== "win") { | ||
fs.chmodSync(path.join(i.path, i.target, "fastboot"), 0o755); | ||
fs.chmodSync(path.join(i.path, i.target, "adb"), 0o755); | ||
fs.chmodSync(path.join(i.path, i.target, "mke2fs"), 0o755); | ||
} | ||
if (platformToolsArray.length <= 1) { | ||
callback() | ||
} else { | ||
platformToolsArray.shift(); | ||
extractPlatformTools(platformToolsArray, callback); | ||
} | ||
fs.createReadStream(path.join(i.path, path.basename(i.url))) | ||
.pipe( | ||
unzip.Extract({ | ||
path: path.join(i.path, i.target + "_tmp") | ||
}) | ||
) | ||
.on("close", () => { | ||
fs.move( | ||
path.join(i.path, i.target + "_tmp", "platform-tools"), | ||
path.join(i.path, i.target), | ||
{ | ||
overwrite: true | ||
}, | ||
e => { | ||
fs.removeSync(path.join(i.path, i.target + "_tmp")); | ||
if (cli.os !== "win") { | ||
fs.chmodSync(path.join(i.path, i.target, "fastboot"), 0o755); | ||
fs.chmodSync(path.join(i.path, i.target, "adb"), 0o755); | ||
fs.chmodSync(path.join(i.path, i.target, "mke2fs"), 0o755); | ||
} | ||
if (platformToolsArray.length <= 1) { | ||
callback(); | ||
} else { | ||
platformToolsArray.shift(); | ||
extractPlatformTools(platformToolsArray, callback); | ||
} | ||
} | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
cli | ||
.version(require('./package.json').version) | ||
.usage('./build.js -o <os> -p <package> [options]') | ||
.option('-o, --os <os>', 'Target operating system') | ||
.option('-p, --package [package]', 'Target package') | ||
.option('-e, --extra-metadata [JSON]', 'Inject JSON into package.json', JSON.parse, "") | ||
.option('-d, --download-only', 'Only download platform tools', undefined, false) | ||
.option('-n, --no-platform-tools', 'Build without platform tools', undefined, false) | ||
.parse(process.argv) | ||
.version(require("./package.json").version) | ||
.usage("./build.js -o <os> -p <package> [options]") | ||
.option("-o, --os <os>", "Target operating system") | ||
.option("-p, --package [package]", "Target package") | ||
.option( | ||
"-e, --extra-metadata [JSON]", | ||
"Inject JSON into package.json", | ||
JSON.parse, | ||
"" | ||
) | ||
.option( | ||
"-d, --download-only", | ||
"Only download platform tools", | ||
undefined, | ||
false | ||
) | ||
.option( | ||
"-n, --no-platform-tools", | ||
"Build without platform tools", | ||
undefined, | ||
false | ||
) | ||
.parse(process.argv); | ||
|
||
var targetOs; | ||
var buildConfig = require("./buildconfig-generic.json"); | ||
|
@@ -80,38 +109,44 @@ switch (cli.os) { | |
case "linux": | ||
targetOs = Platform.LINUX; | ||
buildConfig = Object.assign(buildConfig, { | ||
"linux": { | ||
"target": cli.package, | ||
"icon": "build/icons", | ||
"synopsis": "Install Ubuntu Touch on UBports devices", | ||
"category": "Utility" | ||
}, | ||
"deb": { | ||
"depends": ["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3", "android-tools-adb", "android-tools-fastboot"] | ||
} | ||
linux: { | ||
target: cli.package, | ||
icon: "build/icons", | ||
synopsis: "Install Ubuntu Touch on UBports devices", | ||
category: "Utility" | ||
}, | ||
deb: { | ||
depends: [ | ||
"gconf2", | ||
"gconf-service", | ||
"libnotify4", | ||
"libappindicator1", | ||
"libxtst6", | ||
"libnss3", | ||
"android-tools-adb", | ||
"android-tools-fastboot" | ||
] | ||
} | ||
); | ||
}); | ||
break; | ||
case "win": | ||
targetOs = Platform.WINDOWS; | ||
buildConfig = Object.assign(buildConfig, { | ||
"win": { | ||
"target": ["portable"], | ||
"icon": "build/icons/icon.ico" | ||
} | ||
win: { | ||
target: ["portable"], | ||
icon: "build/icons/icon.ico" | ||
} | ||
); | ||
}); | ||
break; | ||
case "mac": | ||
targetOs = Platform.MAC; | ||
buildConfig = Object.assign(buildConfig, { | ||
"mac": { | ||
"target": "dmg", | ||
"icon": "build/icons/icon.icns", | ||
"category": "public.app-category.utilities" | ||
} | ||
mac: { | ||
target: "dmg", | ||
icon: "build/icons/icon.icns", | ||
category: "public.app-category.utilities" | ||
} | ||
); | ||
}); | ||
break; | ||
default: | ||
console.log("Please specify a target operating system!"); | ||
|
@@ -154,42 +189,46 @@ switch (cli.package) { | |
var build = () => { | ||
// Build | ||
if (!cli.downloadOnly) { | ||
builder.build({ | ||
builder | ||
.build({ | ||
targets: builder.createTargets([targetOs]), | ||
config: Object.assign(buildConfig, | ||
{ "extraMetadata": | ||
(cli.package ? | ||
Object.assign(cli.extraMetadata, { "package": cli.package }) : | ||
cli.extraMetadata | ||
) | ||
} | ||
) | ||
}).then(() => { | ||
console.log("Done"); | ||
}).catch((e) => { | ||
if(e.message.indexOf("GitHub Personal Access Token is not set") !== -1) { | ||
config: Object.assign(buildConfig, { | ||
extraMetadata: cli.package | ||
? Object.assign(cli.extraMetadata, { package: cli.package }) | ||
: cli.extraMetadata | ||
}) | ||
}) | ||
.then(() => { | ||
console.log("Done"); | ||
process.exit(0); | ||
} else { | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
}); | ||
}) | ||
.catch(e => { | ||
if ( | ||
e.message.indexOf("GitHub Personal Access Token is not set") !== -1 | ||
) { | ||
console.log("Done"); | ||
process.exit(0); | ||
} else { | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
// Download platform tools | ||
if (cli.platformTools) { | ||
download(getAndroidPlatformTools()[0].url,getAndroidPlatformTools()[0].path).then(() => { | ||
console.log('files downloaded!'); | ||
extractPlatformTools(getAndroidPlatformTools(), () => { | ||
console.log("Platform tools downloaded successfully!"); | ||
if (!cli.downloadOnly) build(); | ||
download(getAndroidPlatformTools()[0].url, getAndroidPlatformTools()[0].path) | ||
.then(() => { | ||
console.log("files downloaded!"); | ||
extractPlatformTools(getAndroidPlatformTools(), () => { | ||
console.log("Platform tools downloaded successfully!"); | ||
if (!cli.downloadOnly) build(); | ||
}); | ||
}) | ||
.catch(() => { | ||
console.error("Failed to download files!"); | ||
process.exit(1); | ||
}); | ||
}).catch(() => { | ||
console.error("Failed to download files!"); | ||
process.exit(1); | ||
}); | ||
} else { | ||
build(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.