serverscript

package
v0.202.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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.

View Source
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

View Source
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.

View Source
var Arches = []string{"amd64", "arm64"}

Arches are the Linux architectures a release ships archives for.

Functions

func Archive

func Archive(version, arch string) string

Archive is a release's Linux archive name for arch.

func IsRelease

func IsRelease(v string) bool

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

func ParseChecksums(r io.Reader) (map[string]string, error)

ParseChecksums reads a goreleaser checksums.txt: "<sha256> <file>" lines.

func Render

func Render(in Input) (string, error)

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

func SSHCommand(goos string, t SSHTarget, scriptPath string) (string, error)

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

type Release struct {
	Version string
	SHA256  map[string]string
	Signed  bool
}

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

func FetchRelease(ctx context.Context, hc *http.Client, base, version string) (Release, error)

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.

func (SSHTarget) Check

func (t SSHTarget) Check() error

Check accepts only what cannot be read as anything but an address, a user and a port by a shell or by ssh: no spaces, quotes, ;, $, `, a leading - (an ssh option), @ or : outside an IPv6 address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL