Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
105 lines (100 loc) · 5.66 KB
/
Copy pathinstall.ps1
File metadata and controls
105 lines (100 loc) · 5.66 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# FIOF installer for Windows PowerShell 5.1 or PowerShell 7.
# Run in a normal PowerShell window, not as Administrator.
# Installs into a NEW folder, then starts the same guided setup as Linux/macOS.
# Does not install packages, change execution policy, configure ACLs or repair servers.
[CmdletBinding()]
param(
# Change this only if you want another NEW framework folder.
[string]$Directory = (Join-Path ([Environment]::GetFolderPath('UserProfile')) 'fiof-framework'),
# main is experimental. Supply a reviewed full commit ID for a pinned install.
[string]$Ref = 'main',
# Download only; run the questions later using the command printed at the end.
[switch]$NoSetup,
[switch]$Help
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
try {
if ($Help) {
Write-Output 'Usage: .\install.ps1 [-Directory C:\absolute\new\folder] [-Ref tag-or-commit] [-NoSetup]'
Write-Output 'Default: experimental main in your home folder\fiof-framework, followed by guided setup.'
Write-Output 'Requires Git and Node.js 22 or later. Existing directories are never overwritten.'
exit 0
}
# Check dependencies before writing files. Reopen PowerShell after installing
# Git/Node.js so that the window can find their newly installed commands.
if (-not (Get-Command git -CommandType Application -ErrorAction SilentlyContinue)) {
throw 'Git is missing. Install Git for Windows, reopen PowerShell, then run this script again.'
}
if (-not (Get-Command node -CommandType Application -ErrorAction SilentlyContinue)) {
throw 'Node.js is missing. Install Node.js 22 or later, reopen PowerShell, then try again.'
}
$nodeVersion = & node --version
if ($LASTEXITCODE -ne 0 -or $nodeVersion -notmatch '^v(\d+)\.' -or [int]$Matches[1] -lt 22) {
throw 'Node.js 22 or later is required. Update Node.js and reopen PowerShell.'
}
if ([string]::IsNullOrWhiteSpace($Ref) -or $Ref.StartsWith('-') -or $Ref -match '[^a-zA-Z0-9._/-]') {
throw 'Use a branch, tag or commit ID for -Ref.'
}
if (-not $NoSetup -and ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected)) {
throw 'Guided setup needs an interactive terminal. Open PowerShell, or use -NoSetup to download only.'
}
# Feed validation code through standard input, keeping the directory a separate
# argument. User paths are never interpolated into executable JavaScript.
# Reject linked ancestors and existing paths, including dangling links. Parent
# ACLs still determine Windows access; this script does not change permissions.
$validation = @'
import fs from 'node:fs';
import path from 'node:path';
const target = process.argv[2];
try {
if (!path.isAbsolute(target) || /[\x00-\x1f\x7f]/.test(target)) throw Error('Choose an absolute directory path without control characters.');
const dest = path.resolve(target);
try { fs.lstatSync(dest); throw Error('The install path already exists. Choose another new path with -Directory; existing files will not be changed.'); }
catch (error) { if (error.code !== 'ENOENT') throw error; }
const parent = path.dirname(dest);
for (let current = parent; ; current = path.dirname(current)) {
const stat = fs.lstatSync(current);
if (stat.isSymbolicLink() || !stat.isDirectory()) throw Error('The parent must exist and its path must not contain links.');
if (current === path.dirname(current)) break;
}
if (process.platform !== 'win32') {
const stat = fs.statSync(parent);
if ((stat.mode & 0o022) || (stat.uid !== process.getuid() && stat.uid !== 0)) throw Error('Choose a protected parent owned by you or root, without group/world write access.');
}
} catch (error) { console.error('Cannot install: ' + error.message); process.exit(1); }
'@
$validation | & node --input-type=module - $Directory
if ($LASTEXITCODE -ne 0) { throw 'Destination checks failed. No download was attempted.' }
Write-Output "Installing FIOF from https://github.com/zacdreyer/FIOF.git"
Write-Output "Requested revision: $Ref"
Write-Output "New framework folder: $Directory"
# Native programs report errors through exit codes. Check each explicitly:
# PowerShell's Stop preference alone does not catch native command failures.
& git -c core.hooksPath=/dev/null clone --no-checkout -- https://github.com/zacdreyer/FIOF.git $Directory
if ($LASTEXITCODE -ne 0) {
throw 'Download failed. Check network access and inspect any partial install folder before retrying.'
}
& git -C $Directory -c core.hooksPath=/dev/null checkout --detach $Ref
if ($LASTEXITCODE -ne 0) {
throw 'Could not select the requested revision. The downloaded folder is preserved; no setup was run.'
}
$commit = & git -C $Directory rev-parse HEAD
if ($LASTEXITCODE -ne 0) { throw 'Unable to read the installed commit. Inspect the preserved folder.' }
Write-Output "Installed exact commit: $commit"
Write-Output "Framework location: $Directory"
$initializer = Join-Path $Directory 'tools/init.mjs'
if ($NoSetup) {
Write-Output 'Download complete. To configure a resource, run:'
Write-Output ('node "{0}" --interactive' -f $initializer)
} else {
Write-Output 'Next: answer the questions about ONE resource. Leave unknown answers blank.'
& node $initializer --interactive
if ($LASTEXITCODE -ne 0) { throw 'Guided setup stopped. Inspect its message above; the framework is preserved.' }
}
} catch {
# Preserve partial downloads and knowledge records. Never recursively delete
# a folder just because installation did not complete.
Write-Error -Message $_.Exception.Message -ErrorAction Continue
exit 1
}