Documentation
¶
Overview ¶
Package serverscript writes the setup script for a new server (ADR-109, .ai/26-server.md P1): a POSIX shell script that cloud-init runs as a new server's user data, or a person runs once as root over SSH. It creates the user `caprock`, turns on lingering, unattended upgrades and a firewall that admits nothing inbound, sets SSH to keys only (or stops it), installs Git, Node.js, Claude Code with Anthropic's installer and Codex, installs Caprock at the laptop's version with its archive checked, and ends with `caprock join <key>` as that user.
Render is a pure function of its Input: the same input gives the same script, byte for byte, which is what the golden tests hold it to. It never reads the clock, the network or the disk; the daemon fetches the release's checksums (release.go) and makes the join key, then calls it.
Index ¶
- Constants
- Variables
- func Archive(version, arch string) string
- func IsRelease(v string) bool
- func ParseChecksums(r io.Reader) (map[string]string, error)
- func Render(in Input) (string, error)
- func SSHCommand(goos string, t SSHTarget, scriptPath string) (string, error)
- type Input
- type Release
- type SSHTarget
Constants ¶
const MinisignPublicKey = "RWTX1RX33pVjQu6PgjfJjd9yG0IAEMskOZbDzsOMugDUiz5sTShBZ1rB"
MinisignPublicKey is the key the desktop app's updater verifies its bundles with (ADR-042, app/src-tauri/tauri.conf.json's plugins.updater .pubkey, base64 of a minisign public key file). The release workflow signs each Linux archive with its secret half (release.yml, linux-sign), and the script checks that signature before the checksum. A test holds this to the app's copy, so the two cannot drift.
const ReleaseBase = "https://github.com/dspv/caprock/releases/download"
ReleaseBase is where release archives are downloaded from; the script fetches <ReleaseBase>/v<version>/caprock_<version>_linux_<arch>.tar.gz.
const RemoteScript = "caprock-setup.sh"
RemoteScript is where the two-step command (a user who is not root) puts the script on the server, in that user's home, removed after it runs.
Variables ¶
var ( ErrBadAddress = errors.New("the address is an IP address or a host name: letters, digits, dots and hyphens (an IPv6 address: hex digits and colons), nothing else") ErrBadUser = errors.New("the user is a Linux user name: lowercase letters, digits, _ and -, starting with a letter or _") ErrBadPort = errors.New("the port is a number from 1 to 65535") )
Errors the form tells apart.
var Arches = []string{"amd64", "arm64"}
Arches are the Linux architectures a release ships archives for.
Functions ¶
func IsRelease ¶
IsRelease says v names a published release rather than a development build ("dev", or a `git describe` string with a commit suffix), the same test update.Newer applies.
func ParseChecksums ¶
ParseChecksums reads a goreleaser checksums.txt: "<sha256> <file>" lines.
func Render ¶
Render writes the script. Every value it puts inside the script is checked first against a pattern that cannot break out of its single quotes.
func SSHCommand ¶
SSHCommand is the command typed into the terminal tab, for the shell that tab runs on goos: sh-like on macOS and Linux (bash, zsh, fish), PowerShell on Windows (Caprock's shell tab there, agents.windowsShell).
- root: the script on ssh's standard input, `sh -s` on the server, one login. PowerShell's pipe rewrites line endings and encoding, so on Windows the redirection is cmd's (`cmd --% /c …`, PowerShell passing the rest untouched), byte for byte.
- another user: sudo needs a terminal for its password, which standard input cannot be, so the script is copied with scp first and run with `ssh -t … sudo sh`, then removed; two logins.
Types ¶
type Input ¶
type Input struct {
// Version is the Caprock release to install, without the "v": the
// laptop's own version, or the latest release for a development build.
Version string
// SHA256 is each archive's SHA-256, hex, by architecture (Arches), as
// that release's checksums.txt lists it.
SHA256 map[string]string
// Signed says the release has a .minisig beside each Linux archive: the
// script then checks it against MinisignPublicKey before the checksum.
Signed bool
// JoinKey is the key `caprock join` uses, made for a server (60 minutes).
JoinKey string
// SSHKey says the user gave the provider an SSH key, or runs the script
// over SSH: SSH stays on, keys only. Without one sshd is stopped and
// disabled, and the provider's web console is the way in.
SSHKey bool
// Base overrides ReleaseBase, for tests that serve the archive locally.
Base string
}
Input is everything a script depends on.
type Release ¶
Release is what the laptop reads about a release before it writes a script: each Linux archive's SHA-256 from its checksums.txt, and whether a minisign signature sits beside both.
func FetchRelease ¶
FetchRelease reads version's checksums.txt from base (ReleaseBase when empty) — GitHub, which the release check already talks to, so no new destination (rule 4) — and asks whether each Linux archive has its .minisig. A request carries nothing but the path.
type SSHTarget ¶
type SSHTarget struct {
// Address is an IPv4 or IPv6 address or a host name.
Address string `json:"address"`
// User is who ssh logs in as: root, or a user with sudo.
User string `json:"user"`
// Port is sshd's port; 0 is 22.
Port int `json:"port,omitempty"`
}
SSHTarget is the server as the user names it.