Skip to content

Commit

Permalink
fix: properly handle SSL in nginx configure
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan D Shaw committed Jul 11, 2022
1 parent dabc7e2 commit 861dd5a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
14 changes: 13 additions & 1 deletion finalize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ export const finalize = (config) => {
);
})

commands.push(`kusanagi nginx --reload;`);
const rootcs = [];
rootcs.push('cd /etc/opt/kusanagi/nginx/conf.d;');
config.subsites.forEach((site) => {
rootcs.push(`
sudo sed -i 's/server_name\\\s${site.profile};/server_name ${site.profile}_ssl;/g' ${site.profile}.conf;
sudo sed -i '0,/server_name\\\s${site.profile}_ssl;/{s/server_name\\\s${site.profile}_ssl;/server_name ${site.profile};/}' ${site.profile}.conf;
sudo sed -i 's/https:\\/\\/${site.profile}\\$request_uri/https:\\/\\/${site.profile}_ssl\\$request_uri/' ${site.profile}.conf;
sudo sed -i 's/#rewrite/rewrite/' ${site.profile}.conf;
`)
});

client.sshKusanagi(commands.join(' '));
client.sshCentos(rootcs.join(' '));

client.sshKusanagi('kusanagi nginx --reload;');
};
60 changes: 37 additions & 23 deletions wp-install.mjs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,55 @@ const prepareFiles = (config, site) => {

let dumpFile = null;
let wpContent = null;
let extraFiles = [];
if (site.dumpFileZip) {
dumpFile = getFnameFromZip(site.dumpFileZip);
}
if (site.wpContentZip) {
wpContent = getFnameFromZip(site.wpContentZip);
}
if (site.extraFiles && Array.isArray(site.extraFiles)) {
extraFiles = site.extraFiles;
}

if (site.dumpFileZip || site.wpContentZip) {
client.sshKusanagi(
`mkdir -p /home/kusanagi/${site.profile}/DocumentRoot/zips`
);
}

const commands = [];
commands.push(`cd /home/kusanagi/${site.profile}/DocumentRoot;`);
if (site.dumpFileZip) {
client.uploadKusanagi(
site.dumpFileZip,
`/home/kusanagi/${site.profile}/DocumentRoot/zips/`
);
commands.push(`cd zips;`);
commands.push(`unzip -o ${dumpFile}.zip;`);
commands.push(`mv ${dumpFile}.sql ../;`);
commands.push(`cd ../;`);
}
if (site.wpContentZip) {
client.uploadKusanagi(
site.wpContentZip,
`/home/kusanagi/${site.profile}/DocumentRoot/zips/`
);
commands.push(`cd zips;`);
commands.push(`unzip -o ${wpContent}.zip;`);
commands.push(`cp -af ${wpContent}/* ../wp-content/;`);
commands.push(`cd ../;`);
}
commands.push(`rm -rf zips;`);

extraFiles.forEach(({ zip, destination }) => {
client.uploadKusanagi(zip, destination);
const fname = getFnameFromZip(zip);
commands.push(`cd ${destination};`);
commands.push(`unzip -o ${destination}${fname}.zip;`);
commands.push(`rm -rf ${destination}${fname}.zip;`);
});

client.sshKusanagi(commands.join(" "));
};

Expand Down Expand Up @@ -80,6 +106,12 @@ const performInstall = (config, site) => {
);
}

if (site.customSearchReplace && Array.isArray(site.customSearchReplace)) {
site.customSearchReplace.forEach(({ pattern, replacement }) => {
commands.push(`wp search-replace ${pattern} ${replacement};`);
})
}

client.sshKusanagi(commands.join(" "));

client.sshCentos(`
Expand All @@ -103,6 +135,10 @@ const performInstall = (config, site) => {
const updatePermissions = (config, site) => {
const client = new SSH(config);

let extra = '';
if (site.permissionsUpdateTargets && Array.isArray(site.permissionsUpdateTargets)) {
extra = `sudo chown -R httpd:www ${site.permissionsUpdateTargets.join(' ')};`;
}
client.sshCentos(`
cd /home/kusanagi/${site.profile};
[ -f ./DocumentRoot/wp-config.php ] && sudo mv ./DocumentRoot/wp-config.php ./ || sudo mv ./wp-config.php ./;
Expand All @@ -112,36 +148,14 @@ const updatePermissions = (config, site) => {
cd DocumentRoot/wp-content;
sudo chmod 644 index.php advanced-cache.php replace-class.php;
sudo chmod 755 translate-accelerator;
sudo chown -R httpd:www replace-class.php translate-accelerator uploads/*;
sudo chown -R httpd:www replace-class.php translate-accelerator uploads/*; ${extra}
`);
};


export const wpInstall = (config) => {
const client = new SSH(config);

const ccopy = _.cloneDeep(config);
[config.rootsite, ...config.subsites].forEach((site, i) => {
if (site.dumpFileZip || site.wpContentZip) {
client.sshKusanagi(
`mkdir -p /home/kusanagi/${site.profile}/DocumentRoot/zips`
);
}

if (site.dumpFileZip) {
client.uploadKusanagi(
site.dumpFileZip,
`/home/kusanagi/${site.profile}/DocumentRoot/zips/`
);
}

if (site.wpContentZip) {
client.uploadKusanagi(
site.wpContentZip,
`/home/kusanagi/${site.profile}/DocumentRoot/zips/`
);
}

prepareFiles(config, site);
const updateds = performInstall(config, site);
if (i === 0) {
Expand Down

0 comments on commit 861dd5a

Please sign in to comment.