From bf6ed9b7ac5f71a133e679e1dc55dbd7e1afb639 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Wed, 18 Sep 2024 16:53:35 +0700 Subject: [PATCH] Add root folder --- src/executor/runner.js | 2 +- src/executor/runnersub.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/executor/runner.js b/src/executor/runner.js index b8f959b..cc6a45e 100644 --- a/src/executor/runner.js +++ b/src/executor/runner.js @@ -225,7 +225,7 @@ export default async function runConfig(config, domain, writer, sandbox = false) domaindata = await virtualminExec.getDomainInfo(domain); break; case 'disable': - await sshExec(`mkdir -p ${domaindata['Home directory']}`); + await sshExec(`mkdir -p '${domaindata['Home directory']}'`); await writeLog("$> virtualmin disable-domain"); await virtExec("disable-domain", value, { domain, diff --git a/src/executor/runnersub.js b/src/executor/runnersub.js index 64c35d8..417bc81 100644 --- a/src/executor/runnersub.js +++ b/src/executor/runnersub.js @@ -330,15 +330,15 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, } var absolutePath = path.join(subdomaindata['Home directory'], value); if (absolutePath !== subdomaindata['HTML directory']) { - await writeLog("$> Changing root folder"); - await sshExec(`mkdir -p ${absolutePath}`); + await writeLog("$> Changing root path to " + value); + await sshExec(`mkdir -p '${absolutePath}'`); await virtExec("modify-web", { domain: subdomain, 'document-dir': value, }); subdomaindata['HTML directory'] = absolutePath; } else { - await writeLog("$> root folder is set unchanged"); + await writeLog("$> root path is set unchanged"); } break; } @@ -347,7 +347,7 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, if (config.source || config.commands || config.services) { await sshExec(`shopt -s dotglob`, false); await sshExec(`export DOMAIN='${subdomain}'`, false); - await sshExec(`mkdir -p ${subdomaindata['Home directory']}/public_html && cd "$_"`); + await sshExec(`mkdir -p '${subdomaindata['Home directory']}/public_html' && cd "$_"`); } if (config.nginx && config.nginx.root) { @@ -467,11 +467,16 @@ export async function runConfigSubdomain(config, domaindata, subdomain, sshExec, } if (config.services) { + const htmlDir = subdomaindata['Home directory'] + '/public_html'; const addFlags = typeof config.services == 'string' ? `-f ${config.services} --progress quiet` : '--progress quiet'; + if (htmlDir == subdomaindata['HTML directory']) { + await writeLog("$> Changing root path for safety"); + await featureRunner("root public_html/public"); + } await writeLog("$> Removing docker compose services if exists"); await sshExec(`docker compose ${addFlags} down --remove-orphans --rmi all || true`); await writeLog("$> Configuring NGINX forwarding for docker"); - let d = await dockerExec.executeServices(config.services, subdomaindata['Home directory'] + '/public_html', subdomain, writeLog); + let d = await dockerExec.executeServices(config.services, htmlDir, subdomain, writeLog); await writeLog("$> Writing docker compose services"); await writeLog(d.split('\n').map(x => ` ${x}`).join('\n')); await writeLog("$> Applying compose services");