Skip to content

Commit 583a1fa

Browse files
add install script for windows & incompatible with crawlee 0.5.x (#186)
Signed-off-by: bigbrother666 <[email protected]> Co-authored-by: bigbrother666 <[email protected]>
1 parent 1f79cb3 commit 583a1fa

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

install_pocketbase.ps1

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# 1. Check if pocketbase exists
2+
function Check-PocketBase {
3+
if (Test-Path ".\pb\pocketbase.exe") {
4+
Write-Host "Detected ./pb/pocketbase already exists, please delete it manually and try again" -ForegroundColor Red
5+
exit 1
6+
}
7+
8+
if (-not (Test-Path ".\pb")) {
9+
New-Item -ItemType Directory -Path ".\pb"
10+
}
11+
}
12+
13+
# 2. Get available versions
14+
function Get-PocketBaseVersions {
15+
Write-Host "Fetching available versions..." -ForegroundColor Green
16+
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/pocketbase/pocketbase/releases"
17+
$global:VERSIONS = $response | ForEach-Object { $_.tag_name }
18+
$global:LATEST_VERSION = $VERSIONS[0]
19+
}
20+
21+
# 3. Select version with arrow keys
22+
function Select-PocketBaseVersion {
23+
Clear-Host
24+
$current = 0
25+
$total = $VERSIONS.Count
26+
27+
while ($true) {
28+
Clear-Host
29+
Write-Host "Available versions (Use ↑↓ arrows to select, Enter to confirm):" -ForegroundColor Yellow
30+
Write-Host "----------------------------------------"
31+
32+
for ($i = 0; $i -lt $total; $i++) {
33+
if ($i -eq $current) {
34+
Write-Host ("-> " + $VERSIONS[$i]) -ForegroundColor Green
35+
} else {
36+
Write-Host (" " + $VERSIONS[$i])
37+
}
38+
}
39+
40+
$key = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
41+
42+
switch ($key.VirtualKeyCode) {
43+
38 { # Up arrow
44+
if ($current -gt 0) { $current-- }
45+
}
46+
40 { # Down arrow
47+
if ($current -lt ($total - 1)) { $current++ }
48+
}
49+
13 { # Enter
50+
$global:SELECTED_VERSION = $VERSIONS[$current]
51+
Write-Host "`nSelected version: $SELECTED_VERSION" -ForegroundColor Green
52+
return
53+
}
54+
}
55+
}
56+
}
57+
58+
# 4. Download PocketBase
59+
function Download-PocketBase {
60+
$versionNum = $SELECTED_VERSION -replace '^v'
61+
$fileName = "pocketbase_${versionNum}_windows_amd64.zip"
62+
$downloadUrl = "https://github.com/pocketbase/pocketbase/releases/download/$SELECTED_VERSION/$fileName"
63+
$outputPath = ".\pb\pocketbase.zip"
64+
65+
Write-Host "Downloading PocketBase $SELECTED_VERSION..." -ForegroundColor Green
66+
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath
67+
68+
Write-Host "Extracting files..." -ForegroundColor Green
69+
Expand-Archive -Path $outputPath -DestinationPath ".\pb" -Force
70+
Remove-Item $outputPath
71+
}
72+
73+
# 5. Configure admin account
74+
function Configure-AdminAccount {
75+
Write-Host "`nConfiguring admin account" -ForegroundColor Yellow
76+
77+
do {
78+
$email = Read-Host "Enter admin email"
79+
} while (-not ($email -match "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
80+
81+
do {
82+
$password = Read-Host "Enter admin password (min 8 chars)" -AsSecureString
83+
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
84+
$passwordText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
85+
} while ($passwordText.Length -lt 8)
86+
87+
$global:ADMIN_EMAIL = $email
88+
$global:ADMIN_PASSWORD = $passwordText
89+
}
90+
91+
# 6. Configure environment file
92+
function Configure-Environment {
93+
if (-not (Test-Path ".\core\.env")) {
94+
Copy-Item "env_sample" -Destination ".\core\.env"
95+
Write-Host "Created new .env file from template" -ForegroundColor Green
96+
} else {
97+
Write-Host "Found existing .env file" -ForegroundColor Yellow
98+
}
99+
100+
$envContent = Get-Content ".\core\.env"
101+
$envContent = $envContent -replace 'export PB_API_AUTH="[^"]*"', "export PB_API_AUTH=`"$ADMIN_EMAIL|$ADMIN_PASSWORD`""
102+
Set-Content ".\core\.env" $envContent
103+
104+
Write-Host "Updated PB_API_AUTH in .env with new credentials" -ForegroundColor Green
105+
}
106+
107+
# Main execution
108+
function Main {
109+
Write-Host "Starting PocketBase installation..." -ForegroundColor Cyan
110+
Check-PocketBase
111+
Get-PocketBaseVersions
112+
Select-PocketBaseVersion
113+
Download-PocketBase
114+
Configure-AdminAccount
115+
Configure-Environment
116+
Write-Host "PocketBase installation completed!" -ForegroundColor Green
117+
}
118+
119+
# Run the script
120+
Main

0 commit comments

Comments
 (0)