Docs / Publish with curl / One-command script
One-command script
Pack and publish your folder in a single command. Set SITE_DIR at the
top, run it: the first run stages your site and prints a URL to activate; once your API key is
saved, later runs update it in place.
Prerequisites
curl and tar (built into macOS, Linux, and Windows 10/11). For the
one-command updates, save your API key to ~/.publishmy first — see
Publish with curl, step 4.
macOS / Linux — publish.sh
Save it next to your site, chmod +x publish.sh, then run ./publish.sh.
#!/usr/bin/env bash
# publish.sh — publish a static folder to publish.my (no agent).
set -euo pipefail
# ===== configure =====
SITE_DIR="./site" # folder containing index.html at its top level
API="https://api.publish.my"
KEY_FILE="$HOME/.publishmy" # your API key (saved after you activate; see step 4)
# =====================
[ -f "$SITE_DIR/index.html" ] || { echo "No index.html at the top of $SITE_DIR"; exit 1; }
tarball="$(mktemp -t pmsite).tar.gz"
trap 'rm -f "$tarball"' EXIT
tar -czf "$tarball" -C "$SITE_DIR" .
state="$SITE_DIR/.publishmy-id" # remembers the project id between runs
if [ -f "$state" ] && [ -f "$KEY_FILE" ]; then
id="$(cat "$state")"
echo "Updating $id ..."
curl -fsS -X POST "$API/v1/deploy" \
-H "Authorization: Bearer $(cat "$KEY_FILE")" \
-F "project_id=$id" -F "site=@$tarball"
else
echo "Publishing for the first time ..."
resp="$(curl -fsS -X POST "$API/v1/deploy" -F "site=@$tarball")"
echo "$resp"
echo "$resp" | sed -n 's/.*"project_id":"\([^"]*\)".*/\1/p' > "$state"
url="$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')"
echo
echo "Open $url , enter your email, and click the link to go live."
echo "Then save your API key to $KEY_FILE (see step 4) for one-command updates."
fi
Windows 10/11 — publish.ps1 (PowerShell)
Windows 10/11 ship curl.exe and tar.exe. Run with
powershell -ExecutionPolicy Bypass -File publish.ps1.
$ErrorActionPreference = "Stop"
# ===== configure =====
$SiteDir = ".\site" # folder containing index.html at its top level
$Api = "https://api.publish.my"
$KeyFile = "$HOME\.publishmy" # your API key (saved after you activate)
# =====================
if (-not (Test-Path "$SiteDir\index.html")) { throw "No index.html at the top of $SiteDir" }
$tarball = "$env:TEMP\pmsite.tar.gz"
tar -czf $tarball -C $SiteDir .
$state = "$SiteDir\.publishmy-id"
if ((Test-Path $state) -and (Test-Path $KeyFile)) {
$id = (Get-Content $state).Trim()
Write-Host "Updating $id ..."
curl.exe -fsS -X POST "$Api/v1/deploy" -H "Authorization: Bearer $(Get-Content $KeyFile)" -F "project_id=$id" -F "site=@$tarball"
} else {
Write-Host "Publishing for the first time ..."
$resp = curl.exe -fsS -X POST "$Api/v1/deploy" -F "site=@$tarball" | ConvertFrom-Json
$resp | ConvertTo-Json
$resp.project_id | Out-File -Encoding ascii $state
Write-Host "Open $($resp.url) , enter your email, and click the link to go live."
}
Remove-Item $tarball -ErrorAction SilentlyContinue
How it remembers your site
On the first publish the script writes the new project id to
.publishmy-id next to
your site. With that file plus your key in ~/.publishmy, every later run updates the
same URL. Delete .publishmy-id to start a fresh site.