Skip to content

Commit

Permalink
Added uninstall method
Browse files Browse the repository at this point in the history
  • Loading branch information
JezerM committed Nov 21, 2021
1 parent 4751c77 commit 5cbd3ac
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 16 deletions.
18 changes: 10 additions & 8 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ const asar = require("asar");
const fs = require("fs-extra");
const path = require("path");
const child_process = require("child_process");
const progress = require("cli-progress");
const {
makeCopy,
iterateCopy,
getFileSize,
makeCopyFromTo,
} = require("./build/utils.js");
const { makeCopy, makeCopyFromTo } = require("./build/utils.js");
const yargs = require("yargs");
const ora = require("ora");

let DEST_DIR = "/";
let PREFIX = "/usr";
Expand Down Expand Up @@ -208,8 +203,15 @@ async function build_asar() {
let asar_dest = path.join(nody_path, "resources/app.asar");

console.log(`Creating 'asar' package in '${asar_dest}'`);

let spinner = ora({
text: `Creating package...`,
spinner: "dots",
});
spinner.start();

await asar.createPackage(ASAR_ROOT, asar_dest);
console.log("'asar' package created");
spinner.succeed('"asar" package created');
}

async function build() {
Expand Down
2 changes: 1 addition & 1 deletion build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ async function makeCopyFromTo(array) {
copy_bar.stop();
}

module.exports = { iterateCopy, makeCopy, makeCopyFromTo, getFileSize };
module.exports = { iterateCopy, makeCopy, makeCopyFromTo, getFileSize, wait };
2 changes: 1 addition & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PREFIX = argv.PREFIX;
DEST_DIR = argv.DEST_DIR;

async function install() {
console.log(`Copying nody-greeter to ${DEST_DIR}...`);
console.log(`Copying nody-greeter to "${DEST_DIR}"...`);
await makeCopy(INSTALL_ROOT, DEST_DIR);
fs.createSymlinkSync(
path.join(DEST_DIR, "opt/nody-greeter/nody-greeter"),
Expand Down
9 changes: 9 additions & 0 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let argv = yargs
.usage("$0 [args]")
.command("install", "Install nody-greeter")
.command("build", "Build nody-greeter")
.command("uninstall", "Uninstall nody-greeter")
.option("DEST_DIR", {
type: "string",
describe: "Where to install nody-greeter",
Expand Down Expand Up @@ -55,10 +56,18 @@ async function do_build() {
build();
}

async function do_uninstall() {
const { uninstall } = require("./uninstall.js");

uninstall();
}

if (argv._[0] == "install") {
do_install();
} else if (argv._[0] == "build") {
do_build();
} else if (argv._[0] == "uninstall") {
do_uninstall();
} else {
yargs.showHelp();
process.exit(1);
Expand Down
13 changes: 7 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"electron-builder": "^22.11.7",
"electron-rebuild": "^2.3.5",
"fs-extra": "^8.1.0",
"ora": "^5.4.1",
"typescript": "^4.3.5"
},
"dependencies": {
Expand Down
89 changes: 89 additions & 0 deletions uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const fs = require("fs-extra");
const path = require("path");
const yargs = require("yargs");
const { wait } = require("./build/utils.js");
const ora = require("ora");

let DEST_DIR = "/";
let PREFIX = "/usr";

yargs.parserConfiguration({
"short-option-groups": true,
"camel-case-expansion": false,
"dot-notation": true,
"parse-numbers": true,
"parse-positional-numbers": true,
"boolean-negation": true,
"deep-merge-config": false,
});

let argv = yargs
.scriptName("install")
.option("DEST_DIR", {
type: "string",
describe: "Where to install nody-greeter",
default: DEST_DIR,
})
.option("PREFIX", {
type: "string",
describe: "Prefix to install at",
default: PREFIX,
})
.help("h")
.alias("h", "help")
.version(false).argv;

PREFIX = argv.PREFIX;
DEST_DIR = argv.DEST_DIR;

// Some global variables

let nody_path = path.join(DEST_DIR, "opt/nody-greeter");
let bin_path = path.join(DEST_DIR, PREFIX, "bin");
let lightdm_path = path.join(DEST_DIR, "etc/lightdm");
let webg_path = path.join(DEST_DIR, PREFIX, "share/web-greeter");
let xgreeters_path = path.join(DEST_DIR, PREFIX, "share/xgreeters");
let applications_path = path.join(DEST_DIR, PREFIX, "share/applications");
let xdg_ldm_path = path.join(DEST_DIR, "etc/xdg/lightdm/lightdm.conf.d/");

let uninstall_paths = [
//path.join(lightdm_path, "web-greeter.yml"),
//path.join(webg_path, "themes/"),
path.join(xgreeters_path, "nody-greeter.desktop"),
path.join(applications_path, "nody-greeter.desktop"),
path.join(xdg_ldm_path, "90-greeter-wrapper.conf"),
path.join(lightdm_path, "Xgreeter"),
nody_path,
path.join(bin_path, "nody-greeter"),
];

async function uninstall() {
console.log(`Uninstalling nody-greeter inside "${DEST_DIR}"...`);
let spinner = ora({ text: "Uninstalling...", spinner: "dots" });
spinner.start();

for (let i = 0; i < uninstall_paths.length; i++) {
let file = uninstall_paths[i];
spinner.text = "Uninstalling: " + file;
fs.rmSync(file, { force: true, recursive: true });
//await wait(500);
}

spinner.succeed("nody-greeter was uninstalled");
console.log("\x1b[92mSUCCESS!\x1b[0m");

console.log(
"Themes are not uninstalled. Remove them manually:",
`\n\t${webg_path}`
);
console.log(
"nody-greeter config was not uninstalled. Remove it manually:",
`\n\t${path.join(lightdm_path, "web-greeter.yml")}`
);
}

if (require.main == module) {
uninstall();
}

module.exports = { uninstall };

0 comments on commit 5cbd3ac

Please sign in to comment.