const isRootInstall = function isRootInstall() { const path = require('path'); const cliFile = path.join(process.cwd(), '.ghost-cli'); return fs.existsSync(cliFile) && fs.statSync(cliFile).uid === 0; }
fs.lstat(configstore).then((stats) => { if (stats.uid === process.getuid() && stats.gid === process.getgid()) { return; } const {USER} = process.env; return ui.sudo(`chown -R ${USER}:${USER} ${configstore}`); })
function loggedInGhostUser() { const uid = process.getuid(); const contentDirStats = fs.lstatSync(path.join(process.cwd(), 'content')); const ghostStats = ghostUser.getGhostUid(); // check if ghost user exists and if it's currently used if (ghostStats && ghostStats.uid && ghostStats.uid === uid) { // The ghost user might have been set up on the system and also used, // but only when it owns the content folder, it's an indication that it's also used // as the linux user and shall not be used as current user. if (contentDirStats.uid === ghostStats.uid) { throw new errors.SystemError({ message: 'You can\'t run commands with the "ghost" user. Switch to your own user and try again.', help: `${chalk.green('https://ghost.org/docs/install/ubuntu/#create-a-new-user-')}`, task: taskTitle }); } } }
/** * Check that the content folder is owned by the current user * * @param {String} cwd current working directory * @return {Boolean} true if ownership is correct, otherwise false */ _checkContentFolder(cwd) { if (this.system.platform.windows) { return true; } const stat = fs.lstatSync(path.join(cwd, 'content')); if (stat.uid === process.getuid()) { return true; } const Mode = require('stat-mode'); const mode = new Mode(stat); return mode.others.write && mode.others.read; }
const shouldUseGhostUser = function shouldUseGhostUser(contentDir) { if (os.platform() !== 'linux') { return false; } // get the ghost uid and gid const ghostUser = getGhostUid(); if (!ghostUser) { return false; } const stats = fs.lstatSync(contentDir); if (stats.uid !== ghostUser.uid && stats.gid !== ghostUser.gid) { return false; } return process.getuid() !== ghostUser.uid; }
function loggedInUserOwner(ctx) { // TODO: switch to require('os').userInfo() and output username in errors const uid = process.getuid(); const gid = process.getgroups(); const dir = process.cwd(); const dirStats = fs.lstatSync(path.join(dir)); // check if the current user is the owner of the current dir if (dirStats.uid !== uid) { if (gid.indexOf(dirStats.gid) < 0) { throw new errors.SystemError({ message: `Your user does not own the directory ${dir} and is also not a member of the owning group. You must either log in with the user that owns the directory or add your user to the owning group.`, help: `${chalk.green('https://ghost.org/docs/install/ubuntu/#create-a-new-user-')}`, task: taskTitle }); } // Yup current user is not the owner, but in the same group, so just show a warning ctx.ui.log(`Your user does not own the directory ${dir}. This might cause permission issues.`, 'yellow'); } }