tr200 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -201
- package/WINDOWS/TR-200-MachineReport.ps1 +83 -12
- package/bin/tr200.js +193 -5
- package/machine_report.sh +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,45 +80,55 @@ If your system is different, things might break. Look up the offending line and
|
|
|
80
80
|
npm install -g tr200
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
**
|
|
84
|
-
|
|
83
|
+
**Run on-demand:**
|
|
85
84
|
```bash
|
|
86
85
|
tr200
|
|
87
86
|
# or
|
|
88
87
|
report
|
|
89
88
|
```
|
|
90
89
|
|
|
91
|
-
**
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
**Set up auto-run on terminal startup:**
|
|
91
|
+
```bash
|
|
92
|
+
tr200 --install
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Remove auto-run:**
|
|
96
|
+
```bash
|
|
97
|
+
tr200 --uninstall
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Completely uninstall:**
|
|
101
|
+
```bash
|
|
102
|
+
tr200 --uninstall
|
|
103
|
+
npm uninstall -g tr200
|
|
104
|
+
```
|
|
94
105
|
|
|
95
|
-
**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- Automatically detects your OS and runs the appropriate script
|
|
106
|
+
**Requirements:** Node.js 14.0.0 or later
|
|
107
|
+
|
|
108
|
+
---
|
|
99
109
|
|
|
100
|
-
|
|
110
|
+
## Quick Reference
|
|
111
|
+
|
|
112
|
+
| Command | Description |
|
|
113
|
+
|---------|-------------|
|
|
114
|
+
| `tr200` | Run the machine report |
|
|
115
|
+
| `tr200 --help` | Show help |
|
|
116
|
+
| `tr200 --version` | Show version |
|
|
117
|
+
| `tr200 --install` | Set up auto-run on terminal startup |
|
|
118
|
+
| `tr200 --uninstall` | Remove auto-run configuration |
|
|
101
119
|
|
|
102
120
|
---
|
|
103
121
|
|
|
104
|
-
## ⚡
|
|
122
|
+
## ⚡ Alternative: install.sh (No Node.js Required)
|
|
105
123
|
|
|
106
|
-
**
|
|
124
|
+
**For users without Node.js:**
|
|
107
125
|
|
|
108
126
|
```bash
|
|
109
127
|
cd ~/git-projects && gh repo clone RealEmmettS/usgc-machine-report && \
|
|
110
128
|
cd RealEmmettS-usgc-machine-report && ./install.sh
|
|
111
129
|
```
|
|
112
130
|
|
|
113
|
-
The `install.sh` script handles everything:
|
|
114
|
-
- Detects your OS and architecture
|
|
115
|
-
- Installs dependencies (lastlog2)
|
|
116
|
-
- Backs up existing installations
|
|
117
|
-
- Copies and configures the script
|
|
118
|
-
- Tests everything works
|
|
119
|
-
- Sets up the `report` alias
|
|
120
|
-
|
|
121
|
-
**That's it! Type `report` or open a new terminal to see it in action.**
|
|
131
|
+
The `install.sh` script handles everything: OS detection, dependency installation, backup, configuration, and auto-run setup.
|
|
122
132
|
|
|
123
133
|
---
|
|
124
134
|
|
|
@@ -146,194 +156,16 @@ The script creates `dist/tr-200-machine-report.zip` containing the launchers, `m
|
|
|
146
156
|
|
|
147
157
|
---
|
|
148
158
|
|
|
149
|
-
## 🤖 Claude Code
|
|
150
|
-
|
|
151
|
-
**Best for:** Using with [Claude Code](https://claude.ai/code) AI assistant
|
|
159
|
+
## 🤖 Claude Code Installation
|
|
152
160
|
|
|
153
161
|
Ask Claude Code:
|
|
154
162
|
|
|
155
163
|
```
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Or provide these specific instructions:
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
cd ~/git-projects && \
|
|
163
|
-
gh repo clone RealEmmettS/usgc-machine-report && \
|
|
164
|
-
cd RealEmmettS-usgc-machine-report && \
|
|
165
|
-
./install.sh
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Claude Code will automatically:
|
|
169
|
-
1. Clone this repository
|
|
170
|
-
2. Install `lastlog2` if on Debian/Raspberry Pi OS
|
|
171
|
-
3. Copy script to `~/.machine_report.sh`
|
|
172
|
-
4. Add to `.bashrc` with automatic run on login
|
|
173
|
-
5. Create convenient `report` alias
|
|
174
|
-
|
|
175
|
-
**Or provide these specific instructions to Claude Code:**
|
|
176
|
-
|
|
177
|
-
```bash
|
|
178
|
-
# 1. Clone the repository
|
|
179
|
-
cd ~/git-projects
|
|
180
|
-
gh repo clone RealEmmettS/usgc-machine-report
|
|
181
|
-
|
|
182
|
-
# 2. Install dependencies (Debian/Ubuntu/Raspberry Pi OS)
|
|
183
|
-
sudo apt install -y lastlog2
|
|
184
|
-
|
|
185
|
-
# 3. Install the script
|
|
186
|
-
cp ~/git-projects/RealEmmettS-usgc-machine-report/machine_report.sh ~/.machine_report.sh
|
|
187
|
-
chmod +x ~/.machine_report.sh
|
|
188
|
-
|
|
189
|
-
# 4. Add to .bashrc
|
|
190
|
-
cat >> ~/.bashrc << 'EOF'
|
|
191
|
-
|
|
192
|
-
# Machine Report alias - run anytime with 'report' command
|
|
193
|
-
alias report='~/.machine_report.sh'
|
|
194
|
-
|
|
195
|
-
# Run Machine Report only when in interactive mode
|
|
196
|
-
if [[ $- == *i* ]]; then
|
|
197
|
-
~/.machine_report.sh
|
|
198
|
-
fi
|
|
199
|
-
EOF
|
|
200
|
-
|
|
201
|
-
# 5. Test installation
|
|
202
|
-
~/.machine_report.sh
|
|
164
|
+
npm install -g tr200 && tr200 --install
|
|
203
165
|
```
|
|
204
166
|
|
|
205
167
|
---
|
|
206
168
|
|
|
207
|
-
## 🍎 macOS Installation
|
|
208
|
-
|
|
209
|
-
**Requirements:**
|
|
210
|
-
- macOS 10.13 (High Sierra) or later
|
|
211
|
-
- Bash 4.0+ recommended (install via `brew install bash`)
|
|
212
|
-
|
|
213
|
-
**Quick Install:**
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
cd ~/git-projects && gh repo clone RealEmmettS/usgc-machine-report && \
|
|
217
|
-
cd RealEmmettS-usgc-machine-report && ./install.sh
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
**What works on macOS:**
|
|
221
|
-
- ✅ OS version detection (via `sw_vers`)
|
|
222
|
-
- ✅ CPU info (via `sysctl`)
|
|
223
|
-
- ✅ Memory usage (via `vm_stat`)
|
|
224
|
-
- ✅ Disk usage (via `df`)
|
|
225
|
-
- ✅ Network info (via `scutil`)
|
|
226
|
-
- ✅ System uptime (calculated from boot time)
|
|
227
|
-
- ⚠️ Last login may show "unavailable" (macOS limitation)
|
|
228
|
-
|
|
229
|
-
**macOS-Specific Notes:**
|
|
230
|
-
- No package installation needed - uses built-in commands
|
|
231
|
-
- Default Bash 3.2 works but Bash 4+ recommended
|
|
232
|
-
- To install newer Bash: `brew install bash`
|
|
233
|
-
- Script automatically detects macOS and uses appropriate commands
|
|
234
|
-
|
|
235
|
-
### 🐚 zsh Installation (macOS Default Shell)
|
|
236
|
-
|
|
237
|
-
**Modern macOS (Catalina 10.15+) uses zsh by default**, not bash. If you're using zsh, follow these instructions:
|
|
238
|
-
|
|
239
|
-
**Quick Install for zsh:**
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
# Clone and install the script
|
|
243
|
-
cd ~/Downloads && git clone https://github.com/RealEmmettS/usgc-machine-report.git && \
|
|
244
|
-
cp ~/Downloads/usgc-machine-report/machine_report.sh ~/.machine_report.sh && \
|
|
245
|
-
chmod +x ~/.machine_report.sh
|
|
246
|
-
|
|
247
|
-
# Add to .zshrc (not .bashrc!)
|
|
248
|
-
cat >> ~/.zshrc << 'EOF'
|
|
249
|
-
|
|
250
|
-
# Machine Report alias - run anytime with 'report' command
|
|
251
|
-
alias report='~/.machine_report.sh'
|
|
252
|
-
|
|
253
|
-
# Run Machine Report only when in interactive mode
|
|
254
|
-
if [[ $- == *i* ]]; then
|
|
255
|
-
~/.machine_report.sh
|
|
256
|
-
fi
|
|
257
|
-
EOF
|
|
258
|
-
|
|
259
|
-
# Clean up cloned repo (optional)
|
|
260
|
-
rm -rf ~/Downloads/usgc-machine-report
|
|
261
|
-
|
|
262
|
-
echo "✅ Installation complete! Open a new terminal or type: source ~/.zshrc"
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
**Important zsh Notes:**
|
|
266
|
-
- ✅ Use `~/.zshrc` instead of `~/.bashrc`
|
|
267
|
-
- ✅ The script works identically in zsh - no code changes needed
|
|
268
|
-
- ✅ Test with: `zsh -c "source ~/.zshrc && report"`
|
|
269
|
-
- ℹ️ To check your shell: `echo $SHELL` (should show `/bin/zsh`)
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## 📦 Quick Install (Manual - Raspberry Pi OS / Debian)
|
|
274
|
-
|
|
275
|
-
**One-liner installation:**
|
|
276
|
-
|
|
277
|
-
```bash
|
|
278
|
-
cd ~/git-projects && gh repo clone RealEmmettS/usgc-machine-report && \
|
|
279
|
-
sudo apt install -y lastlog2 && \
|
|
280
|
-
cp ~/git-projects/RealEmmettS-usgc-machine-report/machine_report.sh ~/.machine_report.sh && \
|
|
281
|
-
chmod +x ~/.machine_report.sh && \
|
|
282
|
-
cat >> ~/.bashrc << 'EOF'
|
|
283
|
-
|
|
284
|
-
# Machine Report alias - run anytime with 'report' command
|
|
285
|
-
alias report='~/.machine_report.sh'
|
|
286
|
-
|
|
287
|
-
# Run Machine Report only when in interactive mode
|
|
288
|
-
if [[ $- == *i* ]]; then
|
|
289
|
-
~/.machine_report.sh
|
|
290
|
-
fi
|
|
291
|
-
EOF
|
|
292
|
-
echo "✅ Installation complete! Type 'report' or open a new terminal."
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
**Step-by-step installation:**
|
|
296
|
-
|
|
297
|
-
1. **Clone the repository**:
|
|
298
|
-
```bash
|
|
299
|
-
cd ~/git-projects
|
|
300
|
-
gh repo clone RealEmmettS/usgc-machine-report
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
2. **Install dependencies** (for modern Debian/Raspberry Pi OS):
|
|
304
|
-
```bash
|
|
305
|
-
sudo apt install -y lastlog2
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
*Note: On systems with the legacy `lastlog` command, this step is optional. The script automatically detects and uses whichever is available.*
|
|
309
|
-
|
|
310
|
-
3. **Copy the script to your home directory**:
|
|
311
|
-
```bash
|
|
312
|
-
cp ~/git-projects/RealEmmettS-usgc-machine-report/machine_report.sh ~/.machine_report.sh
|
|
313
|
-
chmod +x ~/.machine_report.sh
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
4. **Add to `.bashrc` for automatic display on login**:
|
|
317
|
-
```bash
|
|
318
|
-
cat >> ~/.bashrc << 'EOF'
|
|
319
|
-
|
|
320
|
-
# Machine Report alias - run anytime with 'report' command
|
|
321
|
-
alias report='~/.machine_report.sh'
|
|
322
|
-
|
|
323
|
-
# Run Machine Report only when in interactive mode
|
|
324
|
-
if [[ $- == *i* ]]; then
|
|
325
|
-
~/.machine_report.sh
|
|
326
|
-
fi
|
|
327
|
-
EOF
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
5. **Test the installation**:
|
|
331
|
-
```bash
|
|
332
|
-
~/.machine_report.sh
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
---
|
|
336
|
-
|
|
337
169
|
## 🛠️ Manual Installation (Advanced)
|
|
338
170
|
|
|
339
171
|
For login sessions over ssh, reference the script `~/.machine_report.sh` in your `.bashrc` file. Make sure the script is executable by running `chmod +x ~/.machine_report.sh`.
|
|
@@ -432,6 +264,24 @@ For ZFS systems, edit:
|
|
|
432
264
|
|
|
433
265
|
## 📝 Changelog (Fork-specific)
|
|
434
266
|
|
|
267
|
+
### v2.0.1 (2026-01-30) - **INSTALL FLAGS + PS 5.1 FIXES**
|
|
268
|
+
**New CLI Flags + PowerShell Compatibility**
|
|
269
|
+
|
|
270
|
+
- ✨ **`--install` flag**: Set up auto-run on terminal startup via npm
|
|
271
|
+
- ✨ **`--uninstall` flag**: Remove auto-run configuration cleanly
|
|
272
|
+
- ✨ **`--help` flag**: Show usage information (all scripts)
|
|
273
|
+
- ✨ **`--version` flag**: Show version information (all scripts)
|
|
274
|
+
- 🔧 **PowerShell 5.1 compatibility**: Fixed `[System.Net.Dns]::GetHostName()` and null-conditional operators
|
|
275
|
+
- 📚 **Simplified README**: npm + `--install` promoted as primary installation method
|
|
276
|
+
|
|
277
|
+
**Upgrade path:**
|
|
278
|
+
```bash
|
|
279
|
+
npm update -g tr200
|
|
280
|
+
tr200 --install # Re-run to update shell config if needed
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
435
285
|
### v2.0.0 (2026-01-30) - **SHAUGHV REBRAND + NPM RELEASE**
|
|
436
286
|
**Complete Rebrand + Auto-Run Enhancements + npm Publishing**
|
|
437
287
|
|
|
@@ -20,6 +20,58 @@
|
|
|
20
20
|
Tested : Windows PowerShell 5.1 and PowerShell 7+
|
|
21
21
|
#>
|
|
22
22
|
|
|
23
|
+
[CmdletBinding()]
|
|
24
|
+
param(
|
|
25
|
+
[Alias('h', '?')]
|
|
26
|
+
[switch]$Help,
|
|
27
|
+
|
|
28
|
+
[Alias('v')]
|
|
29
|
+
[switch]$Version,
|
|
30
|
+
|
|
31
|
+
[Parameter(ValueFromRemainingArguments = $true)]
|
|
32
|
+
[string[]]$RemainingArgs
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
$script:TR200Version = '2.0.1'
|
|
36
|
+
|
|
37
|
+
# Handle Unix-style --flags (PowerShell doesn't natively support double-dash)
|
|
38
|
+
if ($RemainingArgs) {
|
|
39
|
+
foreach ($arg in $RemainingArgs) {
|
|
40
|
+
if ($arg -eq '--help' -or $arg -eq '-help') { $Help = $true }
|
|
41
|
+
if ($arg -eq '--version' -or $arg -eq '-version') { $Version = $true }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function Show-TR200Help {
|
|
46
|
+
$helpText = @"
|
|
47
|
+
|
|
48
|
+
TR-200 Machine Report v$script:TR200Version
|
|
49
|
+
|
|
50
|
+
Usage: TR-200-MachineReport.ps1 [options]
|
|
51
|
+
report [options]
|
|
52
|
+
|
|
53
|
+
Displays system information in a formatted table with Unicode box-drawing.
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
--help, -h Show this help message
|
|
57
|
+
--version, -v Show version number
|
|
58
|
+
|
|
59
|
+
When installed via npm (tr200):
|
|
60
|
+
tr200 Run the machine report
|
|
61
|
+
tr200 --help Show help (includes install/uninstall options)
|
|
62
|
+
tr200 --install Set up auto-run on terminal startup
|
|
63
|
+
tr200 --uninstall Remove auto-run from shell startup
|
|
64
|
+
|
|
65
|
+
When installed via install_windows.ps1:
|
|
66
|
+
report Run the machine report (works in CMD and PowerShell)
|
|
67
|
+
uninstall Remove TR-200 Machine Report
|
|
68
|
+
|
|
69
|
+
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
70
|
+
|
|
71
|
+
"@
|
|
72
|
+
Write-Host $helpText
|
|
73
|
+
}
|
|
74
|
+
|
|
23
75
|
#region Encoding and box-drawing configuration
|
|
24
76
|
|
|
25
77
|
# Ensure UTF-8 output for proper box-drawing characters on Windows PowerShell 5.1
|
|
@@ -60,16 +112,20 @@ function New-TR200BarGraph {
|
|
|
60
112
|
[int] $Width
|
|
61
113
|
)
|
|
62
114
|
|
|
115
|
+
# Convert chars to strings for multiplication (PS 5.1 compatibility)
|
|
116
|
+
$barFilled = [string]$TR200Chars.BarFilled
|
|
117
|
+
$barEmpty = [string]$TR200Chars.BarEmpty
|
|
118
|
+
|
|
63
119
|
if ($Total -le 0) {
|
|
64
|
-
return ($
|
|
120
|
+
return ($barEmpty * [math]::Max($Width, 1))
|
|
65
121
|
}
|
|
66
122
|
|
|
67
123
|
$percent = [math]::Max([math]::Min(($Used / $Total) * 100.0, 100.0), 0.0)
|
|
68
124
|
$filledBars = [int]([math]::Round(($percent / 100.0) * $Width))
|
|
69
125
|
if ($filledBars -gt $Width) { $filledBars = $Width }
|
|
70
126
|
|
|
71
|
-
$filled = $
|
|
72
|
-
$empty = $
|
|
127
|
+
$filled = $barFilled * $filledBars
|
|
128
|
+
$empty = $barEmpty * ([math]::Max($Width,0) - $filledBars)
|
|
73
129
|
return "$filled$empty"
|
|
74
130
|
}
|
|
75
131
|
|
|
@@ -404,14 +460,21 @@ function Show-TR200Report {
|
|
|
404
460
|
}
|
|
405
461
|
|
|
406
462
|
# Total inner width of table (excluding outer borders)
|
|
407
|
-
|
|
463
|
+
# Row format: "│ <label> │ <value> │" = 1+1+label+1+1+1+data+1+1 = label+data+7
|
|
464
|
+
# Inner width is between outer │ chars: " <label> │ <value> " = label+data+5
|
|
465
|
+
$innerWidth = $labelWidth + $dataWidth + 5
|
|
466
|
+
|
|
467
|
+
# Convert chars to strings for multiplication (PS 5.1 compatibility)
|
|
468
|
+
$hzLine = [string]$TR200Chars.Horizontal
|
|
469
|
+
$vtLine = [string]$TR200Chars.Vertical
|
|
470
|
+
$tDown = [string]$TR200Chars.TDown
|
|
408
471
|
|
|
409
472
|
# Helper to write the top header and borders
|
|
410
473
|
function Write-TR200TopHeader {
|
|
411
474
|
param()
|
|
412
|
-
$top = $TR200Chars.TopLeft + ($
|
|
475
|
+
$top = $TR200Chars.TopLeft + ($hzLine * ($innerWidth)) + $TR200Chars.TopRight
|
|
413
476
|
Write-Host $top
|
|
414
|
-
$mid = $TR200Chars.TRight + ($
|
|
477
|
+
$mid = $TR200Chars.TRight + ($tDown * ($innerWidth)) + $TR200Chars.TLeft
|
|
415
478
|
Write-Host $mid
|
|
416
479
|
}
|
|
417
480
|
|
|
@@ -427,7 +490,7 @@ function Show-TR200Report {
|
|
|
427
490
|
if ($i -eq ($labelWidth + 2)) {
|
|
428
491
|
$line += $mid
|
|
429
492
|
} else {
|
|
430
|
-
$line += $
|
|
493
|
+
$line += $hzLine
|
|
431
494
|
}
|
|
432
495
|
}
|
|
433
496
|
$line += $right
|
|
@@ -436,7 +499,7 @@ function Show-TR200Report {
|
|
|
436
499
|
|
|
437
500
|
function Write-TR200Footer {
|
|
438
501
|
param()
|
|
439
|
-
$bottom = $TR200Chars.BottomLeft + ($
|
|
502
|
+
$bottom = $TR200Chars.BottomLeft + ($hzLine * ($innerWidth)) + $TR200Chars.BottomRight
|
|
440
503
|
Write-Host $bottom
|
|
441
504
|
}
|
|
442
505
|
|
|
@@ -450,7 +513,9 @@ function Show-TR200Report {
|
|
|
450
513
|
$padding = $totalWidth - $text.Length
|
|
451
514
|
$leftPad = [int]([math]::Floor($padding / 2.0))
|
|
452
515
|
$rightPad = $padding - $leftPad
|
|
453
|
-
|
|
516
|
+
$leftSpace = ' ' * $leftPad
|
|
517
|
+
$rightSpace = ' ' * $rightPad
|
|
518
|
+
Write-Host ($vtLine + $leftSpace + $text + $rightSpace + $vtLine)
|
|
454
519
|
}
|
|
455
520
|
|
|
456
521
|
function Write-TR200Row {
|
|
@@ -476,7 +541,7 @@ function Show-TR200Report {
|
|
|
476
541
|
$val = $val.PadRight($dataWidth)
|
|
477
542
|
}
|
|
478
543
|
|
|
479
|
-
Write-Host (
|
|
544
|
+
Write-Host ($vtLine + ' ' + $lbl + ' ' + $vtLine + ' ' + $val + ' ' + $vtLine)
|
|
480
545
|
}
|
|
481
546
|
|
|
482
547
|
# Render table
|
|
@@ -501,11 +566,17 @@ function Show-TR200Report {
|
|
|
501
566
|
|
|
502
567
|
#endregion Rendering
|
|
503
568
|
|
|
504
|
-
# If the script is executed directly (not dot-sourced), show the report
|
|
569
|
+
# If the script is executed directly (not dot-sourced), handle args or show the report
|
|
505
570
|
try {
|
|
506
571
|
if ($MyInvocation.InvocationName -ne '.') {
|
|
507
572
|
# Only auto-run when invoked as a script, not when dot-sourced from a profile
|
|
508
|
-
|
|
573
|
+
if ($Help) {
|
|
574
|
+
Show-TR200Help
|
|
575
|
+
} elseif ($Version) {
|
|
576
|
+
Write-Host $script:TR200Version
|
|
577
|
+
} else {
|
|
578
|
+
Show-TR200Report
|
|
579
|
+
}
|
|
509
580
|
}
|
|
510
581
|
} catch {
|
|
511
582
|
Write-Error $_
|
package/bin/tr200.js
CHANGED
|
@@ -13,8 +13,180 @@
|
|
|
13
13
|
const { spawn } = require('child_process');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const readline = require('readline');
|
|
16
18
|
|
|
17
19
|
const isWindows = process.platform === 'win32';
|
|
20
|
+
const isMac = process.platform === 'darwin';
|
|
21
|
+
const homeDir = os.homedir();
|
|
22
|
+
|
|
23
|
+
// Config block markers for shell profiles
|
|
24
|
+
const CONFIG_MARKER = 'TR-200 Machine Report (npm)';
|
|
25
|
+
const UNIX_CONFIG = `
|
|
26
|
+
# ${CONFIG_MARKER} - auto-run
|
|
27
|
+
if command -v tr200 &> /dev/null; then
|
|
28
|
+
tr200
|
|
29
|
+
fi
|
|
30
|
+
`;
|
|
31
|
+
const PS_CONFIG = `
|
|
32
|
+
# ${CONFIG_MARKER} - auto-run
|
|
33
|
+
if (Get-Command tr200 -ErrorAction SilentlyContinue) {
|
|
34
|
+
tr200
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
// Shell profile paths
|
|
39
|
+
function getProfilePaths() {
|
|
40
|
+
if (isWindows) {
|
|
41
|
+
return [
|
|
42
|
+
path.join(homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
|
|
43
|
+
path.join(homeDir, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1')
|
|
44
|
+
];
|
|
45
|
+
} else if (isMac) {
|
|
46
|
+
return [
|
|
47
|
+
path.join(homeDir, '.zshrc'),
|
|
48
|
+
path.join(homeDir, '.bash_profile')
|
|
49
|
+
];
|
|
50
|
+
} else {
|
|
51
|
+
// Linux/BSD
|
|
52
|
+
return [
|
|
53
|
+
path.join(homeDir, '.bashrc'),
|
|
54
|
+
path.join(homeDir, '.profile')
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Prompt user for confirmation
|
|
60
|
+
function askConfirmation(question) {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
const rl = readline.createInterface({
|
|
63
|
+
input: process.stdin,
|
|
64
|
+
output: process.stdout
|
|
65
|
+
});
|
|
66
|
+
rl.question(question, (answer) => {
|
|
67
|
+
rl.close();
|
|
68
|
+
resolve(answer.toLowerCase().startsWith('y'));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check if config already exists in file
|
|
74
|
+
function hasConfig(filePath) {
|
|
75
|
+
if (!fs.existsSync(filePath)) return false;
|
|
76
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
77
|
+
return content.includes(CONFIG_MARKER);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Install auto-run to shell profiles
|
|
81
|
+
async function installAutoRun() {
|
|
82
|
+
const profiles = getProfilePaths();
|
|
83
|
+
const configBlock = isWindows ? PS_CONFIG : UNIX_CONFIG;
|
|
84
|
+
|
|
85
|
+
console.log('\nTR-200 Machine Report - Install Auto-Run\n');
|
|
86
|
+
console.log('This will configure tr200 to run automatically when you open a terminal.');
|
|
87
|
+
console.log('Profile(s) to modify:');
|
|
88
|
+
profiles.forEach(p => console.log(` - ${p}`));
|
|
89
|
+
console.log('');
|
|
90
|
+
|
|
91
|
+
const confirmed = await askConfirmation('Proceed with installation? (y/N): ');
|
|
92
|
+
if (!confirmed) {
|
|
93
|
+
console.log('Installation cancelled.');
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let installed = 0;
|
|
98
|
+
let skipped = 0;
|
|
99
|
+
|
|
100
|
+
for (const profilePath of profiles) {
|
|
101
|
+
// Check if already configured
|
|
102
|
+
if (hasConfig(profilePath)) {
|
|
103
|
+
console.log(` [skip] ${profilePath} - already configured`);
|
|
104
|
+
skipped++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Ensure directory exists
|
|
109
|
+
const dir = path.dirname(profilePath);
|
|
110
|
+
if (!fs.existsSync(dir)) {
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Append config block
|
|
115
|
+
try {
|
|
116
|
+
fs.appendFileSync(profilePath, configBlock, 'utf8');
|
|
117
|
+
console.log(` [done] ${profilePath}`);
|
|
118
|
+
installed++;
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error(` [error] ${profilePath}: ${err.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log('');
|
|
125
|
+
if (installed > 0) {
|
|
126
|
+
console.log(`Success! Auto-run configured in ${installed} profile(s).`);
|
|
127
|
+
console.log('Open a new terminal window to see the report on startup.');
|
|
128
|
+
} else if (skipped === profiles.length) {
|
|
129
|
+
console.log('Auto-run was already configured in all profiles.');
|
|
130
|
+
}
|
|
131
|
+
process.exit(0);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Uninstall auto-run from shell profiles
|
|
135
|
+
async function uninstallAutoRun() {
|
|
136
|
+
const profiles = getProfilePaths();
|
|
137
|
+
|
|
138
|
+
console.log('\nTR-200 Machine Report - Remove Auto-Run\n');
|
|
139
|
+
console.log('This will remove the auto-run configuration from your shell profile(s).');
|
|
140
|
+
console.log('Profile(s) to check:');
|
|
141
|
+
profiles.forEach(p => console.log(` - ${p}`));
|
|
142
|
+
console.log('');
|
|
143
|
+
|
|
144
|
+
const confirmed = await askConfirmation('Proceed with removal? (y/N): ');
|
|
145
|
+
if (!confirmed) {
|
|
146
|
+
console.log('Removal cancelled.');
|
|
147
|
+
process.exit(0);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let removed = 0;
|
|
151
|
+
|
|
152
|
+
for (const profilePath of profiles) {
|
|
153
|
+
if (!fs.existsSync(profilePath)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const content = fs.readFileSync(profilePath, 'utf8');
|
|
158
|
+
if (!content.includes(CONFIG_MARKER)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Remove the config block (handles both Unix and PowerShell formats)
|
|
163
|
+
// Match from the comment line through the closing fi/}
|
|
164
|
+
const unixPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif command -v tr200 &> \/dev\/null; then\n tr200\nfi\n?/g;
|
|
165
|
+
const psPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif \(Get-Command tr200 -ErrorAction SilentlyContinue\) \{\n tr200\n\}\n?/g;
|
|
166
|
+
|
|
167
|
+
let newContent = content.replace(unixPattern, '');
|
|
168
|
+
newContent = newContent.replace(psPattern, '');
|
|
169
|
+
|
|
170
|
+
if (newContent !== content) {
|
|
171
|
+
try {
|
|
172
|
+
fs.writeFileSync(profilePath, newContent, 'utf8');
|
|
173
|
+
console.log(` [done] ${profilePath}`);
|
|
174
|
+
removed++;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.error(` [error] ${profilePath}: ${err.message}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.log('');
|
|
182
|
+
if (removed > 0) {
|
|
183
|
+
console.log(`Success! Auto-run removed from ${removed} profile(s).`);
|
|
184
|
+
} else {
|
|
185
|
+
console.log('No auto-run configuration found in any profile.');
|
|
186
|
+
}
|
|
187
|
+
console.log('\nNote: To completely remove tr200, run: npm uninstall -g tr200');
|
|
188
|
+
process.exit(0);
|
|
189
|
+
}
|
|
18
190
|
|
|
19
191
|
// Locate the script files relative to this wrapper
|
|
20
192
|
const packageRoot = path.resolve(__dirname, '..');
|
|
@@ -36,6 +208,8 @@ function runReport() {
|
|
|
36
208
|
command = 'pwsh';
|
|
37
209
|
args = ['-ExecutionPolicy', 'Bypass', '-NoProfile', '-File', scriptPath];
|
|
38
210
|
|
|
211
|
+
let pwshFailed = false;
|
|
212
|
+
|
|
39
213
|
const child = spawn(command, args, {
|
|
40
214
|
stdio: 'inherit',
|
|
41
215
|
shell: false
|
|
@@ -44,6 +218,7 @@ function runReport() {
|
|
|
44
218
|
child.on('error', (err) => {
|
|
45
219
|
// If pwsh not found, try Windows PowerShell
|
|
46
220
|
if (err.code === 'ENOENT') {
|
|
221
|
+
pwshFailed = true;
|
|
47
222
|
const fallback = spawn('powershell', args, {
|
|
48
223
|
stdio: 'inherit',
|
|
49
224
|
shell: false
|
|
@@ -64,7 +239,10 @@ function runReport() {
|
|
|
64
239
|
});
|
|
65
240
|
|
|
66
241
|
child.on('close', (code) => {
|
|
67
|
-
|
|
242
|
+
// Only handle close if pwsh didn't fail (otherwise fallback handles it)
|
|
243
|
+
if (!pwshFailed) {
|
|
244
|
+
process.exit(code || 0);
|
|
245
|
+
}
|
|
68
246
|
});
|
|
69
247
|
|
|
70
248
|
} else {
|
|
@@ -102,7 +280,7 @@ function runReport() {
|
|
|
102
280
|
// Handle help flag
|
|
103
281
|
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
104
282
|
console.log(`
|
|
105
|
-
TR-200 Machine Report v2.0.
|
|
283
|
+
TR-200 Machine Report v2.0.1
|
|
106
284
|
|
|
107
285
|
Usage: tr200 [options]
|
|
108
286
|
report [options]
|
|
@@ -112,6 +290,8 @@ Displays system information in a formatted table with Unicode box-drawing.
|
|
|
112
290
|
Options:
|
|
113
291
|
-h, --help Show this help message
|
|
114
292
|
-v, --version Show version number
|
|
293
|
+
--install Set up auto-run on terminal/shell startup
|
|
294
|
+
--uninstall Remove auto-run from shell startup
|
|
115
295
|
|
|
116
296
|
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
117
297
|
`);
|
|
@@ -120,9 +300,17 @@ More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
|
120
300
|
|
|
121
301
|
// Handle version flag
|
|
122
302
|
if (process.argv.includes('--version') || process.argv.includes('-v')) {
|
|
123
|
-
console.log('2.0.
|
|
303
|
+
console.log('2.0.2');
|
|
124
304
|
process.exit(0);
|
|
125
305
|
}
|
|
126
306
|
|
|
127
|
-
//
|
|
128
|
-
|
|
307
|
+
// Handle install flag
|
|
308
|
+
if (process.argv.includes('--install')) {
|
|
309
|
+
installAutoRun();
|
|
310
|
+
} else if (process.argv.includes('--uninstall')) {
|
|
311
|
+
// Handle uninstall flag
|
|
312
|
+
uninstallAutoRun();
|
|
313
|
+
} else {
|
|
314
|
+
// Run the report
|
|
315
|
+
runReport();
|
|
316
|
+
}
|
package/machine_report.sh
CHANGED
|
@@ -7,6 +7,49 @@
|
|
|
7
7
|
# Supports: Linux (all major distros), macOS 10.13+, partial BSD support
|
|
8
8
|
# Requires: Bash 4.0+ (macOS users: brew install bash)
|
|
9
9
|
|
|
10
|
+
TR200_VERSION="2.0.1"
|
|
11
|
+
|
|
12
|
+
# Handle command-line arguments
|
|
13
|
+
show_help() {
|
|
14
|
+
cat << 'EOF'
|
|
15
|
+
|
|
16
|
+
TR-200 Machine Report v2.0.1
|
|
17
|
+
|
|
18
|
+
Usage: machine_report.sh [options]
|
|
19
|
+
report [options]
|
|
20
|
+
|
|
21
|
+
Displays system information in a formatted table with Unicode box-drawing.
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--help, -h Show this help message
|
|
25
|
+
--version, -v Show version number
|
|
26
|
+
|
|
27
|
+
When installed via npm (tr200):
|
|
28
|
+
tr200 Run the machine report
|
|
29
|
+
tr200 --help Show help (includes install/uninstall options)
|
|
30
|
+
tr200 --install Set up auto-run on terminal startup
|
|
31
|
+
tr200 --uninstall Remove auto-run from shell startup
|
|
32
|
+
|
|
33
|
+
When installed via install.sh:
|
|
34
|
+
report Run the machine report
|
|
35
|
+
~/.machine_report.sh Run directly
|
|
36
|
+
|
|
37
|
+
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
38
|
+
|
|
39
|
+
EOF
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case "${1:-}" in
|
|
43
|
+
--help|-h)
|
|
44
|
+
show_help
|
|
45
|
+
exit 0
|
|
46
|
+
;;
|
|
47
|
+
--version|-v)
|
|
48
|
+
echo "$TR200_VERSION"
|
|
49
|
+
exit 0
|
|
50
|
+
;;
|
|
51
|
+
esac
|
|
52
|
+
|
|
10
53
|
# Global variables
|
|
11
54
|
MIN_NAME_LEN=5
|
|
12
55
|
MAX_NAME_LEN=13
|