Skip to content

Commit

Permalink
Fixes. Wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Mar 31, 2024
1 parent e2bd09a commit 29e5d63
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions korv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Korv!");
6 changes: 3 additions & 3 deletions lib/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function main(inputArgs: string[]) {
if (baseArgument === "generate") {
console.log(result.serviceFileContent);
} else {
if (result.manualSteps) {
if (result.manualSteps && result.manualSteps.length) {
console.log("To complete the installation, carry out these manual steps:");
console.log(result.manualSteps);
} else {
Expand All @@ -86,15 +86,15 @@ async function main(inputArgs: string[]) {
} else if (baseArgument === "uninstall") {
try {
const result = await uninstallService({ system, name, home });
if (result.manualSteps) {
if (result.manualSteps && result.manualSteps.length) {
console.log(`Carry out these manual steps to complete the unistallation of '${name}'`);
console.log(result.manualSteps);
} else {
console.log(`Service '${name}' at '${result.servicePath}' is now uninstalled.`);
}
exit(0);
} catch (e) {
console.error(`Could not install service, error: ${e.message}`);
console.error(`Could not uninstall service, error: ${e.message}`);
exit(1);
}
} else {
Expand Down
38 changes: 29 additions & 9 deletions lib/managers/systemd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class SystemdService {
} else if (config.system) {
// Store temporary file
const tempFilePath = await mktempdir("svcinstall");
await writeFile(join(tempFilePath, "cfg"), serviceFileContent);
const tempFileFullPath = join(tempFilePath, "cfg");
await writeFile(tempFileFullPath, serviceFileContent);
const manualSteps: ServiceManualStep[] = [];
manualSteps.push({
text: "The systemd configuration has been saved to a temporary file. Copy this file to the correct location using the following command:",
command: `sudo cp ${tempFilePath} ${servicePath}`,
command: `sudo cp ${tempFileFullPath} ${servicePath}`,
});
manualSteps.push({
text: "Reload the systemd configuration:",
Expand Down Expand Up @@ -153,15 +154,34 @@ class SystemdService {
if (!await exists(servicePath)) {
throw new Error(`Service '${config.name}' does not exist.`);
}

try {
await unlink(servicePath);
const manualSteps: ServiceManualStep[] = [];
const reloadCommand = config.system ? "sudo systemctl daemon-reload" : "systemctl --user daemon-reload";
manualSteps.push({
text: `Please run the following command to reload the systemctl daemon:`,
command: reloadCommand,
});
if (config.system) {
const removeCommand = `sudo rm ${servicePathSystem}`;
const stopCommand = `sudo systemctl stop ${config.name}`;
const reloadCommand = "sudo systemctl daemon-reload";
manualSteps.push(
{
text: `Please run this command to stop the service:`,
command: stopCommand,
},
{
text: `Please run the following command to remove the service:`,
command: removeCommand,
},
{
text: `And this command to reload the systemctl daemon:`,
command: reloadCommand,
},
);
} else {
const stopServiceCommand = await spawn(["systemctl", "--user", "stop", config.name]);
await unlink(servicePath);
const reloadServiceCommand = await spawn(["systemctl", "--user", "daemon-reload"]);
if (!(stopServiceCommand.code === 0 && reloadServiceCommand.code === 0)) {
throw new Error("Could not remove the service.");
}
}
return {
servicePath,
manualSteps: manualSteps,
Expand Down

0 comments on commit 29e5d63

Please sign in to comment.