-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstart_macproxy.ps1
119 lines (103 loc) · 2.96 KB
/
start_macproxy.ps1
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Windows-compatible script to set up and launch Macproxy Plus
.DESCRIPTION
This script does the following:
1. Checks that Python and the venv module are installed.
2. Creates and/or validates a virtual environment.
3. Installs required Python packages (from requirements.txt and any enabled extensions).
4. Launches the proxy server, optionally using a specified port.
.PARAMETER Port
Specifies the port number for the proxy server.
.EXAMPLE
.\start_macproxy.ps1 -Port 8080
#>
param (
[string]$Port
)
function FailAndExit($message) {
Write-Host "`nERROR: $message"
Write-Host "Aborting."
exit 1
}
# Verify Python and venv are installed
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
FailAndExit "python could not be found.`nInstall Python from https://www.python.org/downloads/"
}
try {
python -m venv --help | Out-Null
}
catch {
FailAndExit "venv could not be found. Make sure the Python installation includes the 'venv' module."
}
# Set working directory to script location
Set-Location $PSScriptRoot
$venvPath = Join-Path $PSScriptRoot "venv"
$venvOk = $true
# Test for known broken venv states
if (Test-Path $venvPath) {
$activateScript = Join-Path $venvPath "Scripts\Activate.ps1"
if (-not (Test-Path $activateScript)) {
$venvOk = $false
}
else {
. $activateScript
try {
pip list | Out-Null
}
catch {
$venvOk = $false
}
}
if (-not $venvOk) {
Write-Host "Deleting bad python venv..."
Remove-Item -Recurse -Force $venvPath
}
}
# Create the venv if it doesn't exist
if (-not (Test-Path $venvPath)) {
Write-Host "Creating python venv for Macproxy Plus..."
python -m venv venv
Write-Host "Activating venv..."
. (Join-Path $venvPath "Scripts\Activate.ps1")
Write-Host "Installing base requirements.txt..."
pip install wheel | Out-Null
pip install -r requirements.txt | Out-Null
try {
$head = (git rev-parse HEAD)
Set-Content -Path (Join-Path $PSScriptRoot "current") -Value $head
}
catch {
Write-Host "Warning: Git not found, skipping writing HEAD commit info."
}
}
. (Join-Path $venvPath "Scripts\Activate.ps1")
# Gather all requirements from enabled extensions
$allRequirements = @()
$enabledExtensions = python -c "import config; print(' '.join(config.ENABLED_EXTENSIONS))"
foreach ($ext in $enabledExtensions.Split()) {
$reqFile = Join-Path -Path $PSScriptRoot -ChildPath "extensions" |
Join-Path -ChildPath $ext |
Join-Path -ChildPath "requirements.txt"
if (Test-Path $reqFile) {
$allRequirements += "-r `"$reqFile`""
}
}
# Install all requirements at once if there are any
if ($allRequirements.Count -gt 0) {
Write-Host "Installing requirements for enabled extensions..."
$pipCommand = "pip install $($allRequirements -join ' ') -q --upgrade"
Invoke-Expression $pipCommand
}
else {
Write-Host "No additional requirements for enabled extensions."
}
# Start Macproxy Plus
Write-Host "Starting Macproxy Plus..."
if ($Port) {
python proxy.py --port $Port
}
else {
python proxy.py
}