May fixing the linux updater
This commit is contained in:
parent
48b53e9de5
commit
f1cdd38d8a
@ -285,33 +285,33 @@ export async function ensureTargetFilesAreWriteable(updateFile: string) : Promis
|
|||||||
|
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
const tester = async (header: Headers) => {
|
const tester = async (header: Headers) => {
|
||||||
const entry_path = path.normalize(path.join(parentPath, header.name));
|
const entryPath = path.normalize(path.join(parentPath, header.name));
|
||||||
if(header.type == "file") {
|
if(header.type == "file") {
|
||||||
if(originalFs.existsSync(entry_path)) {
|
if(originalFs.existsSync(entryPath)) {
|
||||||
code = await testAccess(entry_path, originalFs.constants.W_OK);
|
code = await testAccess(entryPath, originalFs.constants.W_OK);
|
||||||
if(code) {
|
if(code) {
|
||||||
errors.push("Failed to acquire write permissions for file " + entry_path + " (Code " + code.code + ")");
|
errors.push("Failed to acquire write permissions for file " + entryPath + " (Code " + code.code + ")");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let directory = path.dirname(entry_path);
|
let directory = path.dirname(entryPath);
|
||||||
while(directory.length != 0 && !originalFs.existsSync(directory)) {
|
while(directory.length != 0 && !originalFs.existsSync(directory)) {
|
||||||
directory = path.normalize(path.join(directory, ".."));
|
directory = path.normalize(path.join(directory, ".."));
|
||||||
}
|
}
|
||||||
|
|
||||||
code = await testAccess(directory, originalFs.constants.W_OK);
|
code = await testAccess(directory, originalFs.constants.W_OK);
|
||||||
if(code) {
|
if(code) {
|
||||||
errors.push("Failed to acquire write permissions for directory " + entry_path + " (Code " + code.code + ". Target directory " + directory + ")");
|
errors.push("Failed to acquire write permissions for directory " + entryPath + " (Code " + code.code + ". Target directory " + directory + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(header.type == "directory") {
|
} else if(header.type == "directory") {
|
||||||
let directory = path.dirname(entry_path);
|
let directory = path.dirname(entryPath);
|
||||||
while(directory.length != 0 && !originalFs.existsSync(directory)) {
|
while(directory.length != 0 && !originalFs.existsSync(directory)) {
|
||||||
directory = path.normalize(path.join(directory, ".."));
|
directory = path.normalize(path.join(directory, ".."));
|
||||||
}
|
}
|
||||||
|
|
||||||
code = await testAccess(directory, originalFs.constants.W_OK);
|
code = await testAccess(directory, originalFs.constants.W_OK);
|
||||||
if(code) {
|
if(code) {
|
||||||
errors.push("Failed to acquire write permissions for directory " + entry_path + " (Code " + code.code + ". Target directory " + directory + ")");
|
errors.push("Failed to acquire write permissions for directory " + entryPath + " (Code " + code.code + ". Target directory " + directory + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -667,31 +667,10 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac
|
|||||||
}
|
}
|
||||||
|
|
||||||
callbackStats("Downloading update", 0);
|
callbackStats("Downloading update", 0);
|
||||||
|
|
||||||
const updateFilePath = await downloadClientVersion(targetVersion.channel, targetVersion.version, status => {
|
const updateFilePath = await downloadClientVersion(targetVersion.channel, targetVersion.version, status => {
|
||||||
callbackStats("Downloading update", status.percent);
|
callbackStats("Downloading update", status.percent);
|
||||||
}, callbackLog);
|
}, callbackLog);
|
||||||
|
|
||||||
/* TODO: Remove this step and let the actual updater so this. If this fails we'll already receiving appropriate error messages. */
|
|
||||||
if(os.platform() !== "win32") {
|
|
||||||
callbackLog("info", "Checking file permissions");
|
|
||||||
callbackStats("Checking file permissions", .25);
|
|
||||||
|
|
||||||
/* We must be on a unix based system */
|
|
||||||
const inaccessiblePaths = await ensureTargetFilesAreWriteable(updateFilePath);
|
|
||||||
if(inaccessiblePaths.length > 0) {
|
|
||||||
console.log("Failed to access the following files:");
|
|
||||||
for(const fail of inaccessiblePaths) {
|
|
||||||
console.log(" - " + fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
const executeCommand = "sudo " + path.normalize(app.getPath("exe")) + " --no-sandbox --update-execute";
|
|
||||||
throw "Failed to access target files.\nPlease execute this app with administrator (sudo) privileges.\nUse the following command:\n" + executeCommand;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* the windows update already requests admin privileges */
|
|
||||||
}
|
|
||||||
|
|
||||||
callbackStats("Extracting update", .5);
|
callbackStats("Extracting update", .5);
|
||||||
const { updateSourceDirectory, updateInstallerExecutable } = await extractUpdateFile(updateFilePath, callbackLog);
|
const { updateSourceDirectory, updateInstallerExecutable } = await extractUpdateFile(updateFilePath, callbackLog);
|
||||||
|
|
||||||
@ -722,8 +701,31 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac
|
|||||||
if(os.platform() == "linux") {
|
if(os.platform() == "linux") {
|
||||||
console.log("Executing update install on linux");
|
console.log("Executing update install on linux");
|
||||||
|
|
||||||
|
/* We must be on a unix based system */
|
||||||
|
callbackLog("info", "Checking file permissions");
|
||||||
|
const inaccessiblePaths = await ensureTargetFilesAreWriteable(updateFilePath);
|
||||||
|
if(inaccessiblePaths.length > 0) {
|
||||||
|
console.log("Failed to access the following files:");
|
||||||
|
for(const fail of inaccessiblePaths) {
|
||||||
|
console.log(" - " + fail);
|
||||||
|
}
|
||||||
|
console.log("Will prompt the user to execute a command");
|
||||||
|
}
|
||||||
|
|
||||||
//We have to unpack it later
|
//We have to unpack it later
|
||||||
executeCallback = () => {
|
executeCallback = () => {
|
||||||
|
if(inaccessiblePaths.length > 0) {
|
||||||
|
dialog.showMessageBoxSync({
|
||||||
|
buttons: [ "Ok" ],
|
||||||
|
title: "Update available",
|
||||||
|
message:
|
||||||
|
"We don't have permissions to write to all files.\n" +
|
||||||
|
"Please execute the following command to execute the update:\n" +
|
||||||
|
`sudo "${updateInstallerExecutable}" "${installLogFile}" "${installConfigFile}"`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Executing command %s with args %o", updateInstallerExecutable, [installLogFile, installConfigFile]);
|
console.log("Executing command %s with args %o", updateInstallerExecutable, [installLogFile, installConfigFile]);
|
||||||
try {
|
try {
|
||||||
let result = child_process.spawnSync(updateInstallerExecutable, [installLogFile, installConfigFile]);
|
let result = child_process.spawnSync(updateInstallerExecutable, [installLogFile, installConfigFile]);
|
||||||
@ -736,6 +738,7 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac
|
|||||||
"Failed to execute update installer\n" +
|
"Failed to execute update installer\n" +
|
||||||
"Installer exited with code " + result.status
|
"Installer exited with code " + result.status
|
||||||
} as MessageBoxOptions);
|
} as MessageBoxOptions);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.error("Failed to execute update installer (%o)", error);
|
console.error("Failed to execute update installer (%o)", error);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as electron from "electron";
|
import * as electron from "electron";
|
||||||
|
|
||||||
import {app, Menu, protocol} from "electron";
|
import {app, Menu} from "electron";
|
||||||
import MessageBoxOptions = electron.MessageBoxOptions;
|
import MessageBoxOptions = electron.MessageBoxOptions;
|
||||||
|
|
||||||
import {processArguments, parseProcessArguments, Arguments} from "../shared/process-arguments";
|
import {processArguments, parseProcessArguments, Arguments} from "../shared/process-arguments";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user