#! /usr/bin/env bash set -eo pipefail if [ -z "$1" ]; then echo "Usage: $0 " echo echo "$0 creates an msb instance from a Go image with Claude installed." echo "It mounts the current directory to /home/ubuntu/workspace, $HOME/tmp to /home/ubuntu/tmp," echo "$HOME/.agents to /home/ubuntu/.agents and $HOME/.claude to /home/ubuntu/.claude" echo echo "Requirements:" echo "- msb installed and configured (curl -fsSL https://install.microsandbox.dev | sh)" exit 1 fi echo "Create Microsandbox instance" export home=/home/ubuntu export user=ubuntu # create a microsandbox instance with the name of the first argument, # pass the GitHub token as a secret,mount the current directory to /mnt/workspace, # and run scripts to install and a few other tools msb create --name "$1" \ --secret GITHUB_TOKEN="$(gopass app/ag/github-token)@api.github.com" \ -u $user \ -w $home \ -v "$(pwd)":$home/workspace \ -v "$HOME/.claude:$home/.claude" \ -c 6 \ -m 4G \ --trust-host-cas \ ubuntu echo echo "Install things as user root" msb exec "$1" -u root -- bash -c "set -eo pipefail export DEBIAN_FRONTEND=noninteractive export TZ=Europe/Berlin apt update apt install -y curl echo echo Install Go GO_VERSION=\$(curl -Ls https://go.dev/VERSION?m=text | head -n 1) export arch=\"\$(uname -m)\" case \$arch in arm64|aarch64) arch=arm64 ;; esac curl -so /tmp/go.tar.gz -L# https://go.dev/dl/\${GO_VERSION}.linux-\$arch.tar.gz tar -C /usr/local -xzf /tmp/go.tar.gz echo 'export PATH=\$PATH:/usr/local/go/bin:$home/go/bin' >> $home/.bashrc echo echo Install NeoVim # apt install neovim -y --no-install-recommends " echo echo "Install things as user ubuntu" msb exec "$1" -- bash -c "set -eo pipefail # this non-interactive script doesn't evaluate .bashrc, so: # export PATH=\$PATH:/usr/local/go/bin:\$HOME/go/bin # echo echo Install Claude Code curl -fSL# https://claude.ai/install.sh | bash echo 'export PATH=\$HOME/.local/bin:\$PATH' >> .bashrc # echo # echo Install Go tools # The following steps eventually run in a DNS issue with msb 0.5.6. # Currently, I run them later in an interactive shell. # curl -SfL# https://golangci-lint.run/install.sh | sh -s -- -b \$(go env GOPATH)/bin v2.12.2 && echo golangci-lint installed # go install golang.org/x/tools/gopls@latest && echo gopls installed # go install golang.org/x/vuln/cmd/govulncheck@latest && echo govulncheck installed # go install github.com/securego/gosec/v2/cmd/gosec@latest && echo gosec installed # go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest && echo sqlc installed # go install github.com/go-critic/go-critic/cmd/go-critic@latest && echo go-critic installed # go install honnef.co/go/tools/cmd/staticcheck@latest && echo staticcheck installed # go install github.com/fzipp/gocyclo/cmd/gocyclo@latest && echo gocyclo installed "