Skip to content

Commit 101b4c2

Browse files
committed
convert to powershell
1 parent 536894c commit 101b4c2

File tree

3 files changed

+190
-133
lines changed

3 files changed

+190
-133
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ Configure AI controls by running the appropriate script for your platform:
2525
2626
Download and run the appropriate script for your platform:
2727

28-
- [Windows Script](https://download.phcode.dev/ai-control/setup_phoenix_ai_control_win.bat)
28+
- [Windows PowerShell Script](https://download.phcode.dev/ai-control/setup_phoenix_ai_control_win.ps1)
2929
- [macOS Script](https://download.phcode.dev/ai-control/setup_phoenix_ai_control_mac.sh)
3030
- [Linux Script](https://download.phcode.dev/ai-control/setup_phoenix_ai_control_linux.sh)
3131

3232
#### Windows Installation
3333

34-
1. Download the Windows script
35-
2. Open Command Prompt as Administrator:
36-
- Press Win+X and select "Command Prompt (Admin)" or "Windows PowerShell (Admin)"
34+
1. Download the Windows PowerShell script:
35+
- `setup_phoenix_ai_control_win.ps1`
36+
2. Open PowerShell as Administrator:
37+
- Press Win+X and select "Windows PowerShell (Admin)"
3738
- Navigate to the download location using `cd` command
3839
3. Execute with parameters, for example:
3940
```
40-
setup_phoenix_ai_control_win.bat --managedByEmail [email protected] --disableAI
41+
.\setup_phoenix_ai_control_win.ps1 --managedByEmail [email protected] --disableAI
4142
```
4243
Note: The `--managedByEmail` parameter is optional but recommended
4344

install_scripts/setup_phoenix_ai_control_win.bat

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# PowerShell script for Phoenix AI Control Setup
2+
# This should be saved as setup_phoenix_ai_control_win.ps1
3+
4+
# Function to display help
5+
function Show-Help {
6+
Write-Host
7+
Write-Host "Phoenix AI Control Setup Script"
8+
Write-Host "-------------------------------"
9+
Write-Host "Usage:"
10+
Write-Host " .\setup_phoenix_ai_control_win.ps1 [--managedByEmail <email>] [--allowedUsers <user1,user2,...>]"
11+
Write-Host
12+
Write-Host "Options:"
13+
Write-Host " --managedByEmail Optional but recommended. Admin email who manages AI policy. Can be used in your"
14+
Write-Host " Phoenix managed AI dashboard to selectively enable features and"
15+
Write-Host " manage usage quotas."
16+
Write-Host " --allowedUsers Optional. Comma-separated list of Windows usernames allowed to use AI."
17+
Write-Host " --disableAI Optional. If present, AI will be disabled by default."
18+
Write-Host " If not present, AI will be enabled."
19+
Write-Host
20+
Write-Host "Examples:"
21+
Write-Host " .\setup_phoenix_ai_control_win.ps1 --managedByEmail [email protected]"
22+
Write-Host " .\setup_phoenix_ai_control_win.ps1 --allowedUsers Alice,Bob"
23+
Write-Host " .\setup_phoenix_ai_control_win.ps1 --managedByEmail [email protected] --allowedUsers Alice,Bob --disableAI"
24+
Write-Host
25+
Write-Host "Help:"
26+
Write-Host " .\setup_phoenix_ai_control_win.ps1 --help"
27+
Write-Host
28+
Write-Host "Important:"
29+
Write-Host " Running this script will overwrite any previous configuration."
30+
Write-Host " Only the latest settings will be preserved."
31+
Write-Host
32+
33+
exit 1
34+
}
35+
36+
# Check if user has admin rights
37+
function Test-Admin {
38+
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
39+
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
40+
}
41+
42+
# Process command-line arguments
43+
function Process-Arguments {
44+
param (
45+
[string[]]$Arguments
46+
)
47+
48+
$params = @{
49+
managedByEmail = $null
50+
allowedUsers = $null
51+
disableAI = $false
52+
}
53+
54+
for ($i = 0; $i -lt $Arguments.Count; $i++) {
55+
switch ($Arguments[$i]) {
56+
"--help" {
57+
Show-Help
58+
break
59+
}
60+
"--managedByEmail" {
61+
$i++
62+
if ($i -ge $Arguments.Count) {
63+
Write-Host "Error: Email address cannot be empty."
64+
Write-Host "Example: --managedByEmail [email protected]"
65+
exit 1
66+
}
67+
68+
$email = $Arguments[$i]
69+
if ($email -eq "[email protected]") {
70+
Write-Host "Error: Please enter a valid admin email address."
71+
Write-Host "[email protected] is only meant as an example!"
72+
exit 1
73+
}
74+
75+
$params.managedByEmail = $email
76+
break
77+
}
78+
"--allowedUsers" {
79+
$i++
80+
if ($i -ge $Arguments.Count) {
81+
Write-Host "Error: Allowed users list cannot be empty."
82+
Write-Host "Example: --allowedUsers Alice,Bob"
83+
exit 1
84+
}
85+
86+
$params.allowedUsers = $Arguments[$i]
87+
break
88+
}
89+
"--disableAI" {
90+
$params.disableAI = $true
91+
break
92+
}
93+
default {
94+
Write-Host "Unknown option: $($Arguments[$i])"
95+
Show-Help
96+
break
97+
}
98+
}
99+
}
100+
101+
return $params
102+
}
103+
104+
# Check for help first, before admin check
105+
if ($args -contains "--help") {
106+
Show-Help
107+
}
108+
109+
# Check for admin privileges
110+
if (-not (Test-Admin)) {
111+
Write-Host "This script must be run as Administrator."
112+
Write-Host "Please restart PowerShell as an administrator and try again."
113+
Write-Host "Run with --help for usage information."
114+
exit 1
115+
}
116+
117+
# Process arguments
118+
$params = Process-Arguments -Arguments $args
119+
120+
# Target directory and file
121+
$targetDir = "C:\Program Files\Phoenix AI Control"
122+
$configFile = Join-Path -Path $targetDir -ChildPath "config.json"
123+
124+
# Create directory if it doesn't exist
125+
if (-not (Test-Path -Path $targetDir)) {
126+
New-Item -Path $targetDir -ItemType Directory | Out-Null
127+
}
128+
129+
# Show config values
130+
Write-Host
131+
Write-Host "Configuration values:"
132+
Write-Host "- Email: $($params.managedByEmail)"
133+
Write-Host "- Allowed Users: $($params.allowedUsers)"
134+
Write-Host "- Disable AI: $($params.disableAI)"
135+
Write-Host
136+
137+
# Create the JSON content
138+
$jsonContent = @{
139+
disableAI = $params.disableAI
140+
}
141+
142+
if ($params.managedByEmail) {
143+
$jsonContent.managedByEmail = $params.managedByEmail
144+
}
145+
146+
if ($params.allowedUsers) {
147+
$userList = $params.allowedUsers -split ","
148+
$jsonContent.allowedUsers = $userList
149+
}
150+
151+
# Convert to JSON and write to file
152+
$jsonString = $jsonContent | ConvertTo-Json
153+
Set-Content -Path $configFile -Value $jsonString
154+
155+
# Set appropriate permissions - only Administrators can modify
156+
$acl = Get-Acl -Path $configFile
157+
$acl.SetAccessRuleProtection($true, $false) # Disable inheritance
158+
$administratorsRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
159+
"Administrators", "FullControl", "Allow"
160+
)
161+
$systemRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
162+
"SYSTEM", "FullControl", "Allow"
163+
)
164+
$everyoneRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
165+
"Everyone", "ReadAndExecute", "Allow"
166+
)
167+
$acl.AddAccessRule($administratorsRule)
168+
$acl.AddAccessRule($systemRule)
169+
$acl.AddAccessRule($everyoneRule)
170+
Set-Acl -Path $configFile -AclObject $acl
171+
172+
# Display results
173+
Write-Host "Phoenix AI control config written to:"
174+
Write-Host $configFile
175+
Write-Host
176+
Write-Host "Configuration contents:"
177+
Write-Host "----------------------"
178+
Get-Content -Path $configFile
179+
Write-Host "----------------------"
180+
Write-Host
181+
Write-Host "NOTE: Running this script again will overwrite any previous configuration."
182+
Write-Host " Only the latest settings will be preserved."
183+
184+
# No need to create a batch wrapper

0 commit comments

Comments
 (0)