Skip to content

Commit

Permalink
Merge pull request #1001 from ubports/restart
Browse files Browse the repository at this point in the history
- 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
NeoTheThird authored Nov 5, 2019
2 parents 6be99ab + a513a9d commit ed555dc
Show file tree
Hide file tree
Showing 33 changed files with 906 additions and 533 deletions.
221 changes: 130 additions & 91 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

"use strict"
"use strict";

/*
Expand All @@ -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");
Expand All @@ -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!");
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ubports-installer",
"version": "0.4.6-beta",
"version": "0.4.7-beta",
"description": "The easy way to install Ubuntu Touch on UBports devices. A friendly cross-platform Installer for Ubuntu Touch. Just connect a supported device to your PC, follow the on-screen instructions and watch this awesome tool do all the rest.",
"keywords": [
"Ubuntu",
Expand Down Expand Up @@ -30,8 +30,8 @@
"dist:linux:appimage": "node ./build.js -o 'linux' -p 'AppImage'",
"dist:linux:deb": "node ./build.js -o 'linux' -p 'deb'",
"dist:linux:snap": "snapcraft cleanbuild",
"lint": "./node_modules/.bin/eslint src/*.js",
"lint-fix": "./node_modules/.bin/eslint src/*.js --fix"
"lint": "./node_modules/.bin/eslint *.js src/*.js src/html/scripts/*.js",
"lint-fix": "./node_modules/.bin/eslint *.js src/*.js src/html/scripts/*.js --fix"
},
"devDependencies": {
"electron": "^1.8.8",
Expand Down
Loading

0 comments on commit ed555dc

Please sign in to comment.