Skip to content

Instantly share code, notes, and snippets.

@evaisse
Created September 26, 2025 13:13
Show Gist options
  • Select an option

  • Save evaisse/2201f3f534020dfd7d516a8ba23f902d to your computer and use it in GitHub Desktop.

Select an option

Save evaisse/2201f3f534020dfd7d516a8ba23f902d to your computer and use it in GitHub Desktop.
pocketbase management tools (for CI)
#!/usr/bin/env python3
import argparse
import json
import os
import platform
import sys
import urllib.request
import zipfile
from pathlib import Path
def get_system_info():
system = platform.system().lower()
machine = platform.machine().lower()
if system == 'darwin':
os_name = 'darwin'
elif system == 'linux':
os_name = 'linux'
elif system == 'windows':
os_name = 'windows'
else:
raise ValueError(f"Unsupported operating system: {system}")
if machine in ['x86_64', 'amd64']:
arch = 'amd64'
elif machine in ['aarch64', 'arm64']:
arch = 'arm64'
else:
raise ValueError(f"Unsupported architecture: {machine}")
return os_name, arch
def get_latest_release(version=None):
if version:
url = f"https://api.github.com/repos/pocketbase/pocketbase/releases/tags/{version}"
else:
url = "https://api.github.com/repos/pocketbase/pocketbase/releases/latest"
req = urllib.request.Request(url)
req.add_header('Accept', 'application/vnd.github.v3+json')
with urllib.request.urlopen(req) as response:
return json.loads(response.read().decode())
def install_pocketbase(version=None):
os_name, arch = get_system_info()
print(f"Detected system: {os_name} {arch}")
release = get_latest_release(version)
version_tag = release['tag_name']
print(f"Fetching PocketBase {version_tag}...")
asset_name = f"pocketbase_{version_tag.lstrip('v')}_{os_name}_{arch}.zip"
download_url = None
for asset in release['assets']:
if asset['name'] == asset_name:
download_url = asset['browser_download_url']
break
if not download_url:
raise ValueError(f"Could not find asset {asset_name} in release {version_tag}")
print(f"Downloading from {download_url}...")
zip_path = Path('pocketbase.zip')
urllib.request.urlretrieve(download_url, zip_path)
print(f"Extracting binary...")
binary_name = 'pocketbase.exe' if os_name == 'windows' else 'pocketbase'
binary_path = Path(binary_name)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
with zip_ref.open(binary_name) as source, open(binary_path, 'wb') as target:
target.write(source.read())
zip_path.unlink()
if binary_path.exists() and os_name != 'windows':
binary_path.chmod(0o755)
print(f"✓ PocketBase {version_tag} installed successfully at {binary_path}")
def main():
parser = argparse.ArgumentParser(
description='PocketBase management tools',
prog='tools.py'
)
subparsers = parser.add_subparsers(dest='command', help='Available commands')
install_parser = subparsers.add_parser('install', help='Install PocketBase')
install_parser.add_argument(
'--version',
type=str,
help='Specific version to install (e.g., v0.20.0). Defaults to latest.'
)
args = parser.parse_args()
if args.command == 'install':
try:
install_pocketbase(args.version)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
else:
parser.print_help()
sys.exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment