-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapache.ts
56 lines (48 loc) · 1.76 KB
/
apache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import fs from 'fs';
import { normalize } from 'path';
import sh from '../../modules/sh.js';
import { escapeQuotes } from '../../modules/escape-quotes.js';
import { setApache } from '../../modules/configs/apache.js';
import { MOUNT } from '../../types/mount.js';
import { rootSVPS } from '../../modules/root.js';
export default (configs: MOUNT) => {
const apache = setApache(configs);
if (!apache) return [] as string[];
const default_000 = `${rootSVPS}/resources/apache/virtual-host/000-default.conf`;
const commands = [
`echo "${sh.startTitle}Setting up Apache2${sh.endTitle}"`,
'sudo apt-get update',
'sudo apt-get install apache2 -y',
'sudo mkdir -p /var/www',
'sudo rm -rf /var/www/html',
'sudo mkdir -p /var/www/host',
`echo "${sh.startTitle}Setting up Rewrite Virtual Hosts${sh.endTitle}"`,
`echo ${escapeQuotes(
fs.readFileSync(normalize(default_000), 'utf-8')
)} | sudo tee /etc/apache2/sites-available/000-default.conf > /dev/null`,
'sudo a2enmod proxy proxy_http rewrite headers expires',
];
if (!apache.accessFromIP) {
const htaccess = `${rootSVPS}/resources/apache/html/.htaccess`;
const _403 = `${rootSVPS}/resources/apache/html/403.html`;
Object.assign(commands, [
...commands,
...[
`echo ${escapeQuotes(
fs.readFileSync(normalize(htaccess), 'utf-8')
)} | sudo tee /var/www/host/.htaccess > /dev/null`,
`echo ${escapeQuotes(
fs.readFileSync(normalize(_403), 'utf-8')
)} | sudo tee /var/www/host/403.html > /dev/null`,
'sudo chmod 0755 /var/www/host',
],
]);
}
Object.assign(commands, [
...commands,
'sudo systemctl restart apache2',
'sudo systemctl reload apache2',
sh.done,
]);
return commands;
};