aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2022-12-18 00:05:50 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-12-18 00:05:50 +0100
commit2c8063a1697ce4c737a2296b8d6385c9cf761f07 (patch)
treeb46312848930f3f2e590f94c61587902eade3d54 /src
parent1e588718a855ae2871a8841f6c6e621f49795454 (diff)
downloadLuxcena-Neo-2c8063a1697ce4c737a2296b8d6385c9cf761f07.tar.gz
Luxcena-Neo-2c8063a1697ce4c737a2296b8d6385c9cf761f07.zip
Make the updater work properly
Diffstat (limited to 'src')
-rw-r--r--src/SelfUpdater/index.js57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/SelfUpdater/index.js b/src/SelfUpdater/index.js
index f54af51..2d8d137 100644
--- a/src/SelfUpdater/index.js
+++ b/src/SelfUpdater/index.js
@@ -1,6 +1,6 @@
import { existsSync, readFileSync } from 'fs';
-import { ensureDirSync } from 'fs-extra';
-import { copyFile, rm } from 'fs/promises';
+import { ensureDirSync, copy } from 'fs-extra';
+import { rm, stat } from 'fs/promises';
import url from 'node:url';
import { spawn } from 'child_process';
import { EventEmitter } from 'events';
@@ -143,16 +143,11 @@ class Updater {
// Create backup
this.setStep("Creating backup (2/7)");
- this.setCommand("Create backupdir");
- this.backupdir = createUniqueDir("/var/luxcena-neo/backups", "backup");
- this.setCommand(`Copy ${__appdir} into ${this.backupdir}`);
- await copyFile(__appdir, this.backupdir);
- this.backupcomplete = true;
-
+ await this.createBackup();
+
// Install dependencies
this.setStep("Installing dependencies (3/7)");
await this.installDependencies();
- return
// Install package
this.setStep("Installing package (4/7)");
@@ -160,8 +155,7 @@ class Updater {
// Install update
this.setStep("Installing update (5/7)");
- this.setCommand(`Copy ${this.updatedir} into ${__appdir}`);
- await copyFile(this.updatedir, __appdir);
+ await this.installPackageFiles(this.updatedir);
// Cleanup
this.setStep("Cleaning up (6/7)");
@@ -191,8 +185,9 @@ class Updater {
try {
if (this.backupcomplete && (this.backupdir != null)) {
this.setStep("Restoring backup");
- this.setCommand(`Copy ${this.backupdir} into /opt/luxcena-neo`);
- await copyFile(this.backupdir, __appdir);
+ this.setCommand(`Copy ${this.backupdir} into ${__appdir}`);
+ await copy(this.backupdir, __appdir);
+ await this.run("chown", ['-R', `${s.uid}:${s.gid}`, __appdir]);
}
this.setStep("Cleaning up");
await this.cleanup();
@@ -215,6 +210,19 @@ class Updater {
}
/**
+ * This creates a temporary directory, and creates a backup of the current installation.
+ */
+ async createBackup() {
+ this.setCommand("Create backupdir");
+ this.backupdir = createUniqueDir("/var/luxcena-neo/backups", "backup");
+ this.setCommand(`Copy ${__appdir} into ${this.backupdir}`);
+ await copy(__appdir, this.backupdir);
+ let s = await stat(__appdir);
+ await this.run("chown", ['-R', `${s.uid}:${s.gid}`, this.backupdir]);
+ this.backupcomplete = true;
+ }
+
+ /**
* Determine the currently used remote and branch, and download the newest commit
* into the temporary folder
*/
@@ -240,18 +248,37 @@ class Updater {
await this.run("pip3", ["install", "virtualenv"]);
}
+ /**
+ * Install the downloaded package file
+ */
async installPackage(tmpdir) {
await this.run("sh", ["-c", `export NODE_ENV=production; npm --prefix "${tmpdir}/luxcena-neo/" install "${tmpdir}/${this.latestRelease["assets"][0]["name"]}"`]);
}
+ /**
+ * Replace the current installation with the newly extracted files
+ */
+ async installPackageFiles(tmpdir) {
+ this.setCommand(`Stat current installation`);
+ let s = await stat(__appdir);
+ await this.run("chown", ['-R', `${s.uid}:${s.gid}`, tmpdir]);
+
+ this.setCommand(`Delete current installation`);
+ await rm(`${__appdir}`, {recursive: true});
+
+ this.setCommand(`Copy ${tmpdir} into ${__appdir}`);
+ await copy(`${tmpdir}/luxcena-neo/node_modules/luxcena-neo/`, __appdir);
+ await this.run("chown", ['-R', `${s.uid}:${s.gid}`, __appdir]);
+ }
+
async cleanup() {
if (this.updatedir != null) {
this.setCommand(`Removing temporary update files ${this.updatedir}`);
- await rm(this.updatedir);
+ await rm(this.updatedir, {recursive: true});
}
if (this.backupdir != null) {
this.setCommand(`Removing ${this.backupdir}, thinking everything went fine :)`);
- await rm(this.backupdir);
+ await rm(this.backupdir, {recursive: true});
}
}