Skip to content

Commit

Permalink
feat: add AWS and arm64 support (#8)
Browse files Browse the repository at this point in the history
* chore: update packages

* chore: remove blank issue template

* ci: exit on `1` when the return isn't `true`

* feat: arm64 architecture support

* feat: AWS support

* ci: fix bad finish

* ci: fix bad finish

* ci: fix bad finish

* ci: fix bad finish

* ci: fix bad finish

* ci: fix bad finish
  • Loading branch information
wellwelwel authored Oct 11, 2023
1 parent 0b3f1ba commit f906102
Show file tree
Hide file tree
Showing 44 changed files with 478 additions and 897 deletions.
7 changes: 0 additions & 7 deletions .github/ISSUE_TEMPLATE/blank-📄.md

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ jobs:
- name: 🧪 Testing Service - Upload
run: npm run tests:upload

- name: 🧪 Testing Service - Virtual Hosts
run: npm run tests:virtual-hosts
# Temporarily removing due to limited storage space for GitHub Actions.
# - name: 🧪 Testing Service - Virtual Hosts
# run: npm run tests:virtual-hosts

- name: ✅ Finishing
run: npm run tests:reset >/dev/null 2>&1 || true
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ const svps = new SVPS({
},
});

/** For AWS */
const svps = new SVPS({
access: {
host: '***.amazonaws.com',
username: 'ubuntu',
privateKey: fs.readFileSync('./your_rsa.pem'),
},
});

/** Available methods
* svps.mount
* svps.commands
Expand Down
728 changes: 115 additions & 613 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"svps": "bin/index.js"
},
"dependencies": {
"@types/ssh2": "^1.11.13",
"@types/ssh2": "^1.11.14",
"ssh2": "^1.14.0"
},
"devDependencies": {
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"eslint": "^8.46.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.28.0",
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"eslint": "^8.51.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"packages-update": "^1.2.1",
"prettier": "^3.0.0",
"typescript": "^5.1.6"
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"scripts": {
"build": "rm -rf ./bin ./lib ./tests && npx tsc",
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions resources/sources-list/18.04-arm.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
File renamed without changes.
4 changes: 4 additions & 0 deletions resources/sources-list/20.04-arm.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
File renamed without changes.
4 changes: 4 additions & 0 deletions resources/sources-list/22.04-arm.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
File renamed without changes.
4 changes: 4 additions & 0 deletions resources/sources-list/23.04-arm.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://ports.ubuntu.com/ubuntu-ports/ lunar main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ lunar-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ lunar-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ lunar-security main restricted universe multiverse
12 changes: 6 additions & 6 deletions src/lib/modules/basic-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const basicPermissions = async (options: {
const { remote, user, group } = options;

if (user && group) {
await catchExec(`chown -R ${user}:${group} "${remote}"`);
await catchExec(`chmod -R 0775 "${remote}"`);
await catchExec(`sudo chown -R ${user}:${group} "${remote}"`);
await catchExec(`sudo chmod -R 0775 "${remote}"`);
} else if (user) {
await catchExec(`chown -R ${user}: "${remote}"`);
await catchExec(`chmod -R 0755 "${remote}"`);
await catchExec(`sudo chown -R ${user}: "${remote}"`);
await catchExec(`sudo chmod -R 0755 "${remote}"`);
} else if (group) {
await catchExec(`chown -R :${group} "${remote}"`);
await catchExec(`chmod -R 0775 "${remote}"`);
await catchExec(`sudo chown -R :${group} "${remote}"`);
await catchExec(`sudo chmod -R 0775 "${remote}"`);
}
};
12 changes: 6 additions & 6 deletions src/lib/modules/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export const setCommands = async (options: {

const initialCommands = [
/** Resolving `dpkg` and `apt` */
'rm -rf /var/lib/apt/lists/lock',
'rm -rf /var/lib/dpkg/lock',
'rm -rf /var/lib/dpkg/lock-frontend',
'rm -rf /var/cache/apt/archives/lock',
'echo "Y" | dpkg --configure -a',
'echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections',
'sudo rm -rf /var/lib/apt/lists/lock',
'sudo rm -rf /var/lib/dpkg/lock',
'sudo rm -rf /var/lib/dpkg/lock-frontend',
'sudo rm -rf /var/cache/apt/archives/lock',
'echo "Y" | sudo dpkg --configure -a',
'echo "debconf debconf/frontend select Noninteractive" | sudo debconf-set-selections',
];

if (verbose) console.log('# Initial Commands', '\n', initialCommands);
Expand Down
13 changes: 10 additions & 3 deletions src/lib/modules/configs/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import { NODE } from '../../types/node.js';
import { MOUNT } from '../../types/mount.js';

export const setNode = (configs: MOUNT): Required<NODE> | null => {
if (!configs?.node || typeof configs?.node !== 'object') return null;
if (!configs?.node) return null;

const defaults: Required<NODE> = {
version: 18,
packages: [],
};

if (configs.node === true) return defaults;

return {
version:
configs?.node && typeof configs.node.version === 'number'
? configs.node.version
: 18,
: defaults.version,
packages:
configs?.node && Array.isArray(configs.node.packages)
? configs.node.packages
: [],
: defaults.packages,
};
};
66 changes: 38 additions & 28 deletions src/lib/modules/configs/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,53 @@ import { PHP } from '../../types/php.js';
import { MOUNT } from '../../types/mount.js';

export const setPHP = (configs: MOUNT): Required<PHP> | null => {
if (!configs?.php || typeof configs?.php !== 'object') return null;
if (!configs?.php) return null;

return {
const defaults: Required<PHP> = {
version: 8.2,
modules: [
'cli',
'common',
'bz2',
'curl',
'gmp',
'readline',
'sqlite3',
'xml',
'bcmath',
'gd',
'imagick',
'imap',
'intl',
'json',
'mbstring',
'mysql',
'opcache',
'soap',
'tidy',
'xmlrpc',
'xsl',
'zip',
],
composer: true,
};

if (configs.php === true) return defaults;

const php: Required<PHP> = {
version:
configs?.php && typeof configs.php?.version === 'number'
? configs.php.version
: 8.2,
: defaults.version,
modules:
configs?.php && Array.isArray(configs.php?.modules)
? configs.php.modules
: [
'cli',
'common',
'bz2',
'curl',
'gmp',
'readline',
'sqlite3',
'xml',
'bcmath',
'gd',
'imagick',
'imap',
'intl',
'json',
'mbstring',
'mysql',
'opcache',
'soap',
'tidy',
'xmlrpc',
'xsl',
'zip',
],
: defaults.modules,
composer:
configs?.php && typeof configs.php?.composer === 'boolean'
? configs.php.composer
: true,
: defaults.composer,
};

return php;
};
2 changes: 1 addition & 1 deletion src/lib/modules/configs/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MOUNT } from '../../types/mount.js';
import { REQUIRED_USER } from '../../types/users.js';
import { forceArray } from '../force-array.js';

export const setUsers = (configs: MOUNT) => {
export const setUsers = (configs: MOUNT): REQUIRED_USER[] | null => {
if (!configs?.users) return null;

const mapUsers = forceArray(configs.users) as REQUIRED_USER[];
Expand Down
22 changes: 11 additions & 11 deletions src/lib/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const createSVPS = () => {

return class SVPS {
constructor(options: {
/** Set the SSH access for one or more VPS */
/** Set the SSH access */
access: ACCESS;
}) {
access = options.access;
Expand Down Expand Up @@ -93,13 +93,13 @@ const createSVPS = () => {
const invalidVirtualHosts: VIRTUAL_HOST[] = [];
const deployedVirtualHosts: VIRTUAL_HOST[] = [];
const commands = [
'echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections',
'mkdir -p /var/containers/images /var/containers/compositions /var/containers/domains /var/containers/databases',
'chmod 0755 /var/containers',
'chmod 0700 /var/containers/images',
'chmod 0700 /var/containers/compositions',
'chmod 0750 /var/containers/databases',
'chmod 0755 /var/containers/domains',
'echo "debconf debconf/frontend select Noninteractive" | sudo debconf-set-selections',
'sudo mkdir -p /var/containers/images /var/containers/compositions /var/containers/domains /var/containers/databases',
'sudo chmod 0755 /var/containers',
'sudo chmod 0700 /var/containers/images',
'sudo chmod 0700 /var/containers/compositions',
'sudo chmod 0750 /var/containers/databases',
'sudo chmod 0755 /var/containers/domains',
];

if (!virtualHosts) {
Expand Down Expand Up @@ -146,11 +146,11 @@ const createSVPS = () => {
...commands,
`echo "${sh.startTitle}Proxy Port: ${virtualHost.domain} on port ${virtualHost.port}${sh.endTitle}"`,
...createProxy(virtualHost),
'systemctl reload apache2',
'sudo systemctl reload apache2',
sh.done,
]);
});
commands.push('systemctl restart apache2');
commands.push('sudo systemctl restart apache2');
}

/** Basic Virtual Hosts Servers */
Expand All @@ -165,7 +165,7 @@ const createSVPS = () => {
...createBasicVirtualHost(virtualHost),
]);
});
commands.push('systemctl restart apache2');
commands.push('sudo systemctl restart apache2');
}

if (deployedVirtualHosts.length === 0)
Expand Down
24 changes: 12 additions & 12 deletions src/lib/tasks/steps/apache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export default (configs: MOUNT) => {

const commands = [
`echo "${sh.startTitle}Setting up Apache2${sh.endTitle}"`,
'apt-get update',
'apt-get install apache2 -y',
'mkdir -p /var/www',
'rm -rf /var/www/html',
'mkdir -p /var/www/host',
'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')
)} | cat > /etc/apache2/sites-available/000-default.conf`,
'a2enmod proxy proxy_http rewrite headers expires',
)} | sudo tee /etc/apache2/sites-available/000-default.conf > /dev/null`,
'sudo a2enmod proxy proxy_http rewrite headers expires',
];

if (!apache.accessFromIP) {
Expand All @@ -36,19 +36,19 @@ export default (configs: MOUNT) => {
...[
`echo ${escapeQuotes(
fs.readFileSync(normalize(htaccess), 'utf-8')
)} | cat > /var/www/host/.htaccess`,
)} | sudo tee /var/www/host/.htaccess > /dev/null`,
`echo ${escapeQuotes(
fs.readFileSync(normalize(_403), 'utf-8')
)} | cat > /var/www/host/403.html`,
'chmod 0755 /var/www/host',
)} | sudo tee /var/www/host/403.html > /dev/null`,
'sudo chmod 0755 /var/www/host',
],
]);
}

Object.assign(commands, [
...commands,
'systemctl restart apache2',
'systemctl reload apache2',
'sudo systemctl restart apache2',
'sudo systemctl reload apache2',
sh.done,
]);

Expand Down
10 changes: 5 additions & 5 deletions src/lib/tasks/steps/apt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import sh from '../../modules/sh.js';

export default () => [
`echo "${sh.startTitle}Preparing the Environment${sh.endTitle}"`,
'apt-get update',
'DEBIAN_FRONTEND="noninteractive" apt -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade 2>/dev/null',
'apt-get autoremove -y --purge',
'apt-get clean -y',
'apt-get autoclean -y',
'sudo apt-get update',
'DEBIAN_FRONTEND="noninteractive" sudo apt -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade 2>/dev/null',
'sudo apt-get autoremove -y --purge',
'sudo apt-get clean -y',
'sudo apt-get autoclean -y',
sh.done,
];
2 changes: 1 addition & 1 deletion src/lib/tasks/steps/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (configs: MOUNT) => {

const commands = [
'echo "Generating Open SSL RSA Certificate..."',
`--catch openssl req -x509 -nodes -days ${certificate.days} -new -newkey rsa:${certificate.rsa} -keyout /etc/ssl/private/cert.pem -out /etc/ssl/private/cert.pem -subj "/C=${country}/ST=${state}/L=${location}/O=${organization}/OU=${organizationUnit}/CN=${commonName}"`,
`--catch sudo openssl req -x509 -nodes -days ${certificate.days} -new -newkey rsa:${certificate.rsa} -keyout /etc/ssl/private/cert.pem -out /etc/ssl/private/cert.pem -subj "/C=${country}/ST=${state}/L=${location}/O=${organization}/OU=${organizationUnit}/CN=${commonName}"`,
sh.done,
];

Expand Down
13 changes: 6 additions & 7 deletions src/lib/tasks/steps/crontab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ export default (configs: MOUNT, VPS: ACCESS) => {
const crons = escapeQuotes(fs.readFileSync(normalize(crontab.path), 'utf-8'));
const commands = [
`echo "${sh.startTitle}Setting up cron jobs for '${VPS.username}'${sh.endTitle}"`,
'mkdir -p /var/spool/cron/crontabs/',
'apt-get update',
'apt-get install -y cron',
`echo ${crons} | ${append ? 'tee -a' : 'cat >'} /var/spool/cron/crontabs/${
'sudo mkdir -p /var/spool/cron/crontabs/',
'sudo apt-get update',
'sudo apt-get install -y cron',
`echo ${crons} | sudo tee${append ? ' -a' : ''} /var/spool/cron/crontabs/${
VPS.username
}`,
} > /dev/null`,
];

if (!append) commands.push(`echo ${crons}`);

commands.push(`echo ${crons}`);
commands.push(sh.done);

return commands;
Expand Down
Loading

0 comments on commit f906102

Please sign in to comment.