EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
quick_inventory.js
Go to the documentation of this file.
1#!/usr/bin/env node
2
3const { execSync } = require('child_process');
4const fs = require('fs');
5const path = require('path');
6
7const SSH_KEY = `${process.env.HOME}/PreciseITServices.pem`;
8const SSH_USER = 'centos';
9const WHM_HOST = 'precisewebhosting.com.au';
10const OUTPUT_DIR = 'exports/wordpress-inventory';
11
12if (!fs.existsSync(OUTPUT_DIR)){
13 fs.mkdirSync(OUTPUT_DIR, { recursive: true });
14}
15
16console.log('========================================');
17console.log('WordPress Quick Inventory');
18console.log('========================================\n');
19
20// Get list of WordPress sites
21const findCmd = `ssh -i "${SSH_KEY}" ${SSH_USER}@${WHM_HOST} "ls /home/*/public_html/wp-config.php 2>/dev/null"`;
22const wpPaths = execSync(findCmd, { encoding: 'utf8' }).trim().split('\n').filter(p => p);
23
24console.log(`Found ${wpPaths.length} WordPress sites\n`);
25
26const sites = wpPaths.map(wpConfigPath => {
27 const wpPath = path.dirname(wpConfigPath);
28 const username = wpPath.split('/')[2];
29
30 console.log(`āœ… ${username}`);
31
32 return {
33 username,
34 path: wpPath,
35 wpConfigPath,
36 location: 'public_html'
37 };
38});
39
40const outputFile = path.join(OUTPUT_DIR, 'wordpress_sites.json');
41fs.writeFileSync(outputFile, JSON.stringify(sites, null, 2));
42
43console.log(`\nāœ… Inventory saved: ${outputFile}`);
44console.log(`šŸ“Š Ready to migrate ${sites.length} sites\n`);
45console.log('Next step: ./migration-scripts/migrate_wordpress_to_github.sh\n');