Skip to content

Commit f6a34a8

Browse files
committed
fix(uninstall): ensure uninstall succeeds if using ghost user
no issue - with the permissions change in #296, the ownership of the ghost directory was changed. Because of this we need to sudo remove the directory on uninstall
1 parent ba54099 commit f6a34a8

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

extensions/linux/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ class LinuxExtension extends cli.Extension {
4141
task: () => this.ui.sudo(`chown -R ghost:ghost ${path.join(ctx.instance.dir, 'content')}`)
4242
}], false);
4343
}
44+
45+
uninstall(instance) {
46+
if (os.platform() !== 'linux') {
47+
return Promise.resolve();
48+
}
49+
50+
// because we have changed the ownership of the ghost content folder,
51+
// we need to remove it manually here via sudo
52+
return this.ui.sudo(`rm -rf ${path.join(instance.dir, 'content')}`);
53+
}
4454
}
4555

4656
module.exports = LinuxExtension;

lib/commands/uninstall.js

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const fs = require('fs-extra');
3+
const path = require('path');
34

45
const StopCommand = require('./stop');
56
const Command = require('../command');
@@ -27,23 +28,29 @@ class UninstallCommand extends Command {
2728
return Promise.reject(false);
2829
}
2930

30-
if (!instance.running) {
31-
return Promise.resolve();
32-
}
33-
34-
instance.loadRunningEnvironment(true);
35-
36-
// If the instance is currently running we need to make
37-
// sure it gets stopped
38-
return this.runCommand(StopCommand);
39-
}).then(() => {
40-
this.system.setEnvironment(!fs.existsSync('config.production.json'));
41-
42-
return this.ui.run(this.system.hook('uninstall', instance), 'Removing related configuration');
43-
}).then(() => this.ui.run(() => {
44-
this.system.removeInstance(instance);
45-
return Promise.all(fs.readdirSync('.').map(file => fs.remove(file)));
46-
}, 'Removing Ghost installation'));
31+
return this.ui.listr([{
32+
title: 'Stopping Ghost',
33+
skip: () => !instance.running,
34+
task: () => {
35+
instance.loadRunningEnvironment(true);
36+
// If the instance is currently running we need to make
37+
// sure it gets stopped
38+
return this.runCommand(StopCommand, {quiet: true});
39+
}
40+
}, {
41+
title: 'Removing related configuration',
42+
task: () => {
43+
this.system.setEnvironment(!fs.existsSync(path.join(instance.dir, 'config.production.json')));
44+
return this.system.hook('uninstall', instance);
45+
}
46+
}, {
47+
title: 'Removing Ghost installation',
48+
task: () => {
49+
this.system.removeInstance(instance);
50+
return Promise.all(fs.readdirSync('.').map(file => fs.remove(file)));
51+
}
52+
}]);
53+
});
4754
}
4855
}
4956

0 commit comments

Comments
 (0)