demo / network-computer
Public
Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.
GitStable demo
README: say this is a copy and where the original is
cde82c2
13 hours, 36 minutes ago
History
create-droplet.sh · 3.2 KB · 57 lines
| 1 | #!/bin/sh |
| 2 | # Create a computer, attach its desk, and provision it. |
| 3 | # Usage: infra/create-droplet.sh [name] [region] [size] |
| 4 | # Defaults come from the profile in NC_DESK_ENV (default infra/desk.env; see |
| 5 | # desk.env.example and people.sh), then built-ins. |
| 6 | # |
| 7 | # The desk is a small DigitalOcean volume (desk-$NC_DESK, $NC_DESK_GB GB) that |
| 8 | # outlives the computer: settings, documents, secrets, and the desk's identity |
| 9 | # (login, PIN, pairing, certificate). It is created once, attached at boot, and |
| 10 | # never deleted by any script. With NC_DOMAIN set (DNS on DigitalOcean) the |
| 11 | # hostname is pointed at the new computer before provisioning, for https. |
| 12 | set -e |
| 13 | DIR=$(cd "$(dirname "$0")" && pwd) |
| 14 | ENVF=${NC_DESK_ENV:-$DIR/desk.env} |
| 15 | [ -f "$ENVF" ] && . "$ENVF" |
| 16 | NAME=${1:-${NC_HOST_NAME:-nc}}; REGION=${2:-${NC_REGION:-nyc3}}; SIZE=${3:-${NC_SIZE:-s-2vcpu-4gb}} |
| 17 | DESK=${NC_DESK:-$NAME}; DESK_GB=${NC_DESK_GB:-1}; VOL=desk-$DESK |
| 18 | IMAGE=ubuntu-24-04-x64 |
| 19 | |
| 20 | KEY_ID=$(doctl compute ssh-key list --format ID --no-header | paste -sd, -) |
| 21 | [ -n "$KEY_ID" ] || { echo "no SSH key on DigitalOcean; add one with: doctl compute ssh-key import mykey --public-key-file ~/.ssh/id_ed25519.pub"; exit 1; } |
| 22 | |
| 23 | # the desk: find it, or create it once |
| 24 | VOL_ID=$(doctl compute volume list --format ID,Name,Region --no-header | awk -v n="$VOL" '$2==n{print $1; exit}') |
| 25 | if [ -n "$VOL_ID" ]; then |
| 26 | VOL_REGION=$(doctl compute volume list --format ID,Region --no-header | awk -v i="$VOL_ID" '$1==i{print $2}') |
| 27 | [ "$VOL_REGION" = "$REGION" ] || { echo "desk $VOL is in $VOL_REGION; a computer in $REGION cannot attach it"; exit 1; } |
| 28 | ATTACHED=$(doctl compute volume get "$VOL_ID" --format DropletIDs --no-header | tr -d '[] ') |
| 29 | [ -z "$ATTACHED" ] || { echo "desk $VOL is attached to droplet $ATTACHED; run 'infra/droplet.sh down' first"; exit 1; } |
| 30 | echo "desk $VOL found ($VOL_REGION)" |
| 31 | else |
| 32 | echo "creating desk $VOL (${DESK_GB} GB, $REGION)..." |
| 33 | VOL_ID=$(doctl compute volume create "$VOL" --region "$REGION" --size "${DESK_GB}GiB" \ |
| 34 | --fs-type ext4 --fs-label desk --tag nc-desk --desc "network-computer desk for $DESK" \ |
| 35 | --format ID --no-header) |
| 36 | fi |
| 37 | |
| 38 | echo "creating $NAME ($SIZE, $REGION) with desk attached..." |
| 39 | doctl compute droplet create "$NAME" --region "$REGION" --size "$SIZE" --image "$IMAGE" \ |
| 40 | --ssh-keys "$KEY_ID" --tag-names "nc,nc-$NAME" --volumes "$VOL_ID" --wait --format ID,Name,PublicIPv4 --no-header |
| 41 | |
| 42 | IP="" |
| 43 | for i in $(seq 1 30); do |
| 44 | IP=$(doctl compute droplet list --format Name,PublicIPv4 --no-header | awk -v n="$NAME" '$1==n{print $2}') |
| 45 | [ -n "$IP" ] && break; sleep 3 |
| 46 | done |
| 47 | [ -n "$IP" ] || { echo "no public IP yet; run: infra/droplet.sh status"; exit 1; } |
| 48 | echo "droplet $NAME at $IP" |
| 49 | if [ -n "$NC_DOMAIN" ]; then |
| 50 | # point DNS now: it propagates while the box provisions |
| 51 | sh "$DIR/dns-point.sh" "$NC_DOMAIN" "$IP" |
| 52 | fi |
| 53 | echo "waiting for ssh..." |
| 54 | for i in $(seq 1 30); do ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@"$IP" true 2>/dev/null && break; sleep 5; done |
| 55 | |
| 56 | PRICE=$(doctl compute size list --format Slug,PriceHourly --no-header | awk -v s="$SIZE" '$1==s{print $2}') |
| 57 | NC_DESK_ENV=$ENVF NC_DOMAIN=$NC_DOMAIN NC_KEYBOARD=$NC_KEYBOARD NC_DESK_USER=${NC_DESK_USER:-user} NC_SIZE=$SIZE NC_PRICE_HOURLY=$PRICE sh "$DIR/provision-host.sh" "$IP" "$NAME" |