On the hospital's laptop
Windows (PowerShell):
-{`$env:MEDCHAIN_HUB = "${hub}"; irm ${base}/install.ps1 | iex`}
+ {windows}
+ macOS or Linux (Terminal):
-{`curl -fsSL ${base}/install.sh | MEDCHAIN_HUB=${hub} bash`}
+ {unix}
+ It asks for the hospital's name and the join code, checks Docker, Tailscale, this hub and disk space, and starts the hospital.
Give this code to one hospital. It is shown only now.
{created.code}
+Expires {when(created.expires_at)}. Works once.
> ) : ( diff --git a/deploy/install/install.ps1 b/deploy/install/install.ps1 index 8b4a5e7..bea4624 100644 --- a/deploy/install/install.ps1 +++ b/deploy/install/install.ps1 @@ -16,8 +16,12 @@ # MEDCHAIN_IMAGE (ghcr.io/denimworld12/medchain-node), MEDCHAIN_IMAGE_VERSION (this installer's). # MEDCHAIN_DISPLAY_NAME and MEDCHAIN_JOIN_CODE, if set, are used instead of asking (unattended runs). # Works in Windows PowerShell 5.1 and PowerShell 7. +# +# A failure exits 1 when run as a file (powershell -File install.ps1) or as a one-off +# `powershell -Command`; pasted into an open window (irm ... | iex) it sets $LASTEXITCODE to 1 +# instead, so that window stays open. -function Install-MedChain { +function Install-MedChain($Outcome) { $InstallerVersion = "1.1.0" $Image = if ($env:MEDCHAIN_IMAGE) { $env:MEDCHAIN_IMAGE } else { "ghcr.io/denimworld12/medchain-node" } $Version = if ($env:MEDCHAIN_IMAGE_VERSION) { $env:MEDCHAIN_IMAGE_VERSION } else { "v$InstallerVersion" } @@ -28,14 +32,27 @@ function Install-MedChain { function Say($text) { Write-Host $text } function Ok($text) { Write-Host " [ok] $text" -ForegroundColor Green } - function Problem($what, $fix) { + function Problem($what, $fix, $after = "Fix that, then run the same command again. Nothing has been changed on this laptop.") { + $Outcome.Failed = $true # a folder this run created and left empty goes again, so "nothing has been changed" stays true if ($createdDir -and (Test-Path $Dir) -and -not (Get-ChildItem -Force $Dir)) { Remove-Item $Dir } Write-Host "" Write-Host " [!] $what" -ForegroundColor Red Write-Host " What to do: $fix" -ForegroundColor Yellow Write-Host "" - Write-Host " Fix that, then run the same command again. Nothing has been changed on this laptop." -ForegroundColor Yellow + Write-Host " $after" -ForegroundColor Yellow + } + # the name and the join code are asked for (and checked) before the 2 GB download, not after it + function Read-Name { + $typed = Read-Host "Your hospital's name, as the dashboard should show it (2 to 60 characters)" + if ($null -eq $typed) { return $null } # no one to ask (no input at all) + return [string]$typed + } + function Test-Name($text) { return ($text.Trim() -match '^[^\x00-\x1f\x7f]{2,60}$') } + # node/enroll.py's normalize_code: 20 letters and digits from its alphabet, any dashes or spaces dropped + function Test-JoinCode($text) { + $raw = ($text -replace '[^A-Za-z0-9]', '').ToUpperInvariant() + return ($raw.Length -eq 20 -and $raw -cmatch '^[ABCDEFGHJKMNPQRSTVWXYZ23456789]+$') } Say "" @@ -99,7 +116,7 @@ function Install-MedChain { if ($wait.AsyncWaitHandle.WaitOne(5000) -and $tcp.Connected) { $reachable = $true } } catch { } finally { $tcp.Close() } if (-not $reachable) { - Problem "The organiser's hub at ${hubHost}:${hubPort} does not answer." "Check the address with the organiser, check that their hub is running ('make hub'), and that their laptop shows as connected in your Tailscale menu. A work VPN can block Tailscale: disconnect it." + Problem "The organiser's hub at ${hubHost}:${hubPort} does not answer." "Check the address with the organiser, check that their hub is running, and that their laptop shows as connected in your Tailscale menu. A work VPN can block Tailscale: disconnect it." return } Ok "The hub at ${hubHost}:${hubPort} answers" @@ -114,7 +131,57 @@ function Install-MedChain { } Ok "$freeGB GB free on $root" - # ---- 5. The MedChain image -------------------------------------------------------------------- + # ---- 5. Enrolled already? If not: the hospital's name and the join code, checked before the download ---- + $envFile = Join-Path $Dir ".env" + $id = $null + if (Test-Path $envFile) { + $idLine = Select-String -Path $envFile -Pattern '^NODE_ID=(.+)$' | Select-Object -First 1 + if ($idLine -and (Test-Path ([IO.Path]::Combine($Dir, "pki", $idLine.Matches[0].Groups[1].Value, "tls.crt")))) { + $id = $idLine.Matches[0].Groups[1].Value + } + } + $rerun = [bool]$id + if ($rerun) { + Ok "This laptop is already enrolled ($id); keeping its keys" + } else { + Say "" + Say "Enrolling this laptop. The organiser gives you a join code (it works once, for 30 minutes)." + # unattended (the name given in MEDCHAIN_DISPLAY_NAME): never fall back to asking, as install.sh + $unattended = [bool]$env:MEDCHAIN_DISPLAY_NAME + $name = if ($env:MEDCHAIN_DISPLAY_NAME) { [string]$env:MEDCHAIN_DISPLAY_NAME } else { "" } + $joinCode = if ($env:MEDCHAIN_JOIN_CODE) { [string]$env:MEDCHAIN_JOIN_CODE } else { "" } + if ($unattended -and -not (Test-Name $name)) { + Problem "The hospital name in `$env:MEDCHAIN_DISPLAY_NAME must be 2 to 60 characters." "Set `$env:MEDCHAIN_DISPLAY_NAME to the hospital's name, then run the same command again." + return + } + while (-not (Test-Name $name)) { + $name = Read-Name + if ($null -eq $name) { + Problem "No hospital name given." "Run it in a PowerShell window and type the name, or set `$env:MEDCHAIN_DISPLAY_NAME." + return + } + } + if (-not $joinCode -and $unattended) { # unattended: never prompt (on 5.1 -AsSecureString would wait forever) + Problem "No join code given." "Set `$env:MEDCHAIN_JOIN_CODE to the code the organiser gave you, then run the same command again." + return + } + if (-not $joinCode) { + $secure = Read-Host "The join code (like ABCD-EFGH-JKMN-PQRS-TVWX; hidden as you type)" -AsSecureString + if ($null -eq $secure -or $secure.Length -eq 0) { + Problem "No join code given." "Ask the organiser for a join code and type it when asked, or set `$env:MEDCHAIN_JOIN_CODE." + return + } + $ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) + try { $joinCode = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr) } + finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) } + } + if (-not (Test-JoinCode $joinCode)) { + Problem "That is not a join code: a join code is 20 letters and digits in groups of four, like ABCD-EFGH-JKMN-PQRS-TVWX." "Check it with the organiser (or ask for a new one), then run the same command again." + return + } + } + + # ---- 6. The MedChain image -------------------------------------------------------------------- Say "" Say "Downloading the MedChain program ($Image`:$Version, about 2 GB the first time)..." docker pull "${Image}:${Version}" @@ -127,27 +194,18 @@ function Install-MedChain { Say " (could not check for a newer copy; using the one already on this laptop)" } - # ---- 6. This computer's facts, for the dashboard's proof of origin -------------------------- - $os = Get-CimInstance Win32_OperatingSystem + # ---- 7. This computer's facts, for the dashboard's proof of origin -------------------------- + # (no CIM, as in PowerShell 7 off Windows: the version string, and no boot time) + $os = if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue } $env:MEDCHAIN_HOST_NAME = if ($env:COMPUTERNAME) { $env:COMPUTERNAME } else { [Environment]::MachineName } - $env:MEDCHAIN_HOST_OS = "$($os.Caption) $($os.Version)" - $env:MEDCHAIN_HOST_BOOTED_AT = [string][int64](([DateTimeOffset]$os.LastBootUpTime).ToUnixTimeSeconds()) + $env:MEDCHAIN_HOST_OS = if ($os) { "$($os.Caption) $($os.Version)" } else { [Environment]::OSVersion.VersionString } + $env:MEDCHAIN_HOST_BOOTED_AT = if ($os) { [string][int64](([DateTimeOffset]$os.LastBootUpTime).ToUnixTimeSeconds()) } else { "" } $env:MEDCHAIN_TAILSCALE_DEVICE = $device - # ---- 7. Enroll (once) --------------------------------------------------------------------------- + # ---- 8. Enroll (once), or refresh an enrolled laptop's settings ----------------------------------- $createdDir = -not (Test-Path $Dir) New-Item -ItemType Directory -Force -Path $Dir | Out-Null - $envFile = Join-Path $Dir ".env" - $enrolled = $false - if (Test-Path $envFile) { - $idLine = Select-String -Path $envFile -Pattern '^NODE_ID=(.+)$' | Select-Object -First 1 - if ($idLine -and (Test-Path ([IO.Path]::Combine($Dir, "pki", $idLine.Matches[0].Groups[1].Value, "tls.crt")))) { - $enrolled = $true - } - } - $rerun = $enrolled - if ($enrolled) { - Ok "This laptop is already enrolled ($($idLine.Matches[0].Groups[1].Value)); keeping its keys" + if ($rerun) { # refresh what can change: this laptop's Tailscale address, its facts, and its port when MEDCHAIN_PORT asks # for another one (peers pin the key, not the address: no new join code is needed) $keep = Get-Content $envFile | Where-Object { $_ -notmatch '^(NODE_PORT|ADVERTISE_ADDR|MEDCHAIN_HOST_NAME|MEDCHAIN_HOST_OS|MEDCHAIN_HOST_BOOTED_AT|MEDCHAIN_TAILSCALE_DEVICE)=' } @@ -159,34 +217,14 @@ function Install-MedChain { "MEDCHAIN_TAILSCALE_DEVICE=$env:MEDCHAIN_TAILSCALE_DEVICE") [System.IO.File]::WriteAllLines($envFile, $lines) # no BOM: Docker Compose reads it } else { - Say "" - Say "Enrolling this laptop. The organiser gives you a join code (it works once, for 30 minutes)." - # unattended (the name given in MEDCHAIN_DISPLAY_NAME): never fall back to asking, as install.sh - $unattended = [bool]$env:MEDCHAIN_DISPLAY_NAME - $name = if ($env:MEDCHAIN_DISPLAY_NAME) { [string]$env:MEDCHAIN_DISPLAY_NAME } else { "" } - $joinCode = if ($env:MEDCHAIN_JOIN_CODE) { $env:MEDCHAIN_JOIN_CODE } else { "" } + $enrolled = $false for ($try = 1; $try -le 3; $try++) { - while ($name.Trim().Length -lt 2 -or $name.Trim().Length -gt 60) { - $typed = Read-Host "Your hospital's name, as the dashboard should show it (2 to 60 characters)" - if ($null -eq $typed) { # no one to ask (no input at all) + while (-not (Test-Name $name)) { + $name = Read-Name + if ($null -eq $name) { Problem "No hospital name given." "Run it in a PowerShell window and type the name, or set `$env:MEDCHAIN_DISPLAY_NAME." return } - $name = [string]$typed - } - if (-not $joinCode -and $unattended) { # unattended: never prompt (on 5.1 -AsSecureString would wait forever) - Problem "No join code given." "Set `$env:MEDCHAIN_JOIN_CODE to the code the organiser gave you, then run the same command again." - return - } - if (-not $joinCode) { - $secure = Read-Host "The join code (like ABCD-EFGH-JKMN-PQRS-TVWX; hidden as you type)" -AsSecureString - if ($null -eq $secure -or $secure.Length -eq 0) { - Problem "No join code given." "Ask the organiser for a join code and type it when asked, or set `$env:MEDCHAIN_JOIN_CODE." - return - } - $ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) - try { $joinCode = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr) } - finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) } } $env:MEDCHAIN_JOIN_CODE = $joinCode $env:MEDCHAIN_DISPLAY_NAME = $name.Trim() @@ -214,21 +252,23 @@ function Install-MedChain { Problem "No free name after three tries." "Pick a name no other hospital uses, then run the same command again." return } + $id = (Select-String -Path $envFile -Pattern '^NODE_ID=(.+)$' | Select-Object -First 1).Matches[0].Groups[1].Value } - # ---- 8. Start (or restart) the hospital -------------------------------------------------------- + # ---- 9. Start (or restart) the hospital -------------------------------------------------------- Say "" $compose = [IO.Path]::Combine($Dir, "deploy", "node.yml") # the node checks in with the hub only when it starts: on a re-run recreate it, so step 9 sees the hub's answer of now - $recreate = if ($rerun) { @("--force-recreate") } else { @() } + # @(if ...) keeps it an array: `if` alone unwraps a one-element array into a string, and splatting a + # string passes it one character at a time ("no such service: -") + $recreate = @(if ($rerun) { "--force-recreate" }) docker compose --project-directory $Dir -f $compose up -d @recreate if ($LASTEXITCODE -ne 0) { Problem "Docker could not start the hospital." "If it says 'port is already allocated', another program uses port ${Port}: close it, or set `$env:MEDCHAIN_PORT to another port and run the same command again (no new join code needed). Otherwise restart Docker Desktop and run this again." return } - $id = (Select-String -Path $envFile -Pattern '^NODE_ID=(.+)$' | Select-Object -First 1).Matches[0].Groups[1].Value - # ---- 9. Did the hub let it in? ------------------------------------------------------------------- + # ---- 10. Did the hub let it in? ------------------------------------------------------------------- $tries = if ($env:MEDCHAIN_REGISTER_TRIES) { [int]$env:MEDCHAIN_REGISTER_TRIES } else { 20 } Say "" Say "Waiting for the hub to place this hospital (up to $($tries * 3)s)..." @@ -239,7 +279,7 @@ function Install-MedChain { if ($code -eq 0) { $registered = $true; break } if ($code -eq 3) { docker compose --project-directory $Dir -f $compose down *> $null # it would only retry, refused, forever - Problem "The organiser removed this laptop from the network: the hub refuses its keys." "Delete the folder $Dir, ask the organiser for a new join code, then run the same command again." + Problem "The organiser removed this laptop from the network: the hub refuses its keys." "Delete the folder $Dir, ask the organiser for a new join code, then run the same command again." "This laptop's hospital has been stopped; nothing else was changed." return } Start-Sleep -Seconds 3 @@ -258,4 +298,13 @@ function Install-MedChain { Say " Stop: $up down" } -Install-MedChain +$medchainOutcome = @{ Failed = $false } +Install-MedChain $medchainOutcome +if ($medchainOutcome.Failed) { + # exit (so a caller sees the failure) unless this runs in a window someone keeps using: `exit` would close it + $cli = @([Environment]::GetCommandLineArgs() | Select-Object -Skip 1) + $oneShot = @($cli | Where-Object { $_ -match '^[-/]{1,2}(c|com\w*|e|ec|enc\w*|f|fi\w*|noni\w*)$' }).Count -gt 0 + $keepOpen = @($cli | Where-Object { $_ -match '^[-/]{1,2}noe\w*$' }).Count -gt 0 + if ($PSCommandPath -or ($oneShot -and -not $keepOpen)) { exit 1 } + $global:LASTEXITCODE = 1 +} diff --git a/deploy/install/install.sh b/deploy/install/install.sh index 062381c..d609775 100755 --- a/deploy/install/install.sh +++ b/deploy/install/install.sh @@ -33,9 +33,16 @@ CREATED_DIR="" problem() { # a folder this run created and left empty goes again, so "nothing has been changed" stays true [ -n "$CREATED_DIR" ] && rmdir "$DIR" 2>/dev/null - printf '\n [!] %s\n What to do: %s\n\n Fix that, then run the same command again. Nothing has been changed on this computer.\n' "$1" "$2" >&2 + printf '\n [!] %s\n What to do: %s\n\n %s\n' "$1" "$2" \ + "${3:-Fix that, then run the same command again. Nothing has been changed on this computer.}" >&2 exit 1 } +# node/enroll.py's normalize_code: 20 letters and digits from its alphabet, any dashes or spaces dropped +valid_code() { + local raw + raw=$(printf '%s' "$1" | tr -cd 'A-Za-z0-9' | tr 'a-z' 'A-Z') + [ "${#raw}" -eq 20 ] && [ -z "$(printf '%s' "$raw" | tr -d 'ABCDEFGHJKMNPQRSTVWXYZ23456789')" ] +} # read from the terminal even when this script itself arrives on stdin (curl ... | bash) ask() { local reply; IFS= read -r -p "$1" reply /dev/tty; printf '%s' "$reply"; } @@ -74,7 +81,7 @@ HUB=$(printf '%s' "$HUB" | tr -d '[:space:]') case "$HUB" in *:*) HUB_HOST=${HUB%:*}; HUB_PORT=${HUB##*:} ;; *) HUB_HOST=$HUB; HUB_PORT=$DIRECTORY_PORT ;; esac curl -sk --max-time 6 "https://$HUB_HOST:$HUB_PORT/health" 2>/dev/null | grep -q '"directory"' || problem "The organiser's hub at $HUB_HOST:$HUB_PORT does not answer." \ - "Check the address with the organiser, that their hub is running ('make hub'), and that their computer shows as connected in your Tailscale menu. A work VPN can block Tailscale: disconnect it." + "Check the address with the organiser, that their hub is running, and that their computer shows as connected in your Tailscale menu. A work VPN can block Tailscale: disconnect it." ok "The hub at $HUB_HOST:$HUB_PORT answers" # ---- 4. Disk space ----------------------------------------------------------------------------- @@ -86,7 +93,33 @@ FREE_KB=$(df -Pk "$DIR" | awk 'NR==2 {print $4}') "Free some space, or set MEDCHAIN_DIR to a folder on another disk." ok "$((FREE_KB / 1024 / 1024)) GB free" -# ---- 5. The MedChain image --------------------------------------------------------------------- +# ---- 5. Enrolled already? If not: the hospital's name and the join code, checked before the download ---- +ENV_FILE="$DIR/.env" +NODE_ID=$(sed -n 's/^NODE_ID=//p' "$ENV_FILE" 2>/dev/null | head -n 1) +RERUN="" +if [ -n "$NODE_ID" ] && [ -f "$DIR/pki/$NODE_ID/tls.crt" ]; then + RERUN=1 + ok "This computer is already enrolled ($NODE_ID); keeping its keys" +else + printf '\nEnrolling this computer. The organiser gives you a join code (it works once, for 30 minutes).\n' + NAME=${MEDCHAIN_DISPLAY_NAME:-} + CODE=${MEDCHAIN_JOIN_CODE:-} + if [ -n "$NAME" ] && { [ "${#NAME}" -lt 2 ] || [ "${#NAME}" -gt 60 ]; }; then + problem "The hospital name in MEDCHAIN_DISPLAY_NAME must be 2 to 60 characters." \ + "Set MEDCHAIN_DISPLAY_NAME to the hospital's name, then run the same command again." + fi + while [ "${#NAME}" -lt 2 ] || [ "${#NAME}" -gt 60 ]; do + ( : /dev/null || problem "No hospital name given." "Set MEDCHAIN_DISPLAY_NAME, or run it in a terminal and type the name." + NAME=$(ask "Your hospital's name, as the dashboard should show it (2 to 60 characters): ") + done + [ -n "$CODE" ] || CODE=$(ask_hidden "The join code (like ABCD-EFGH-JKMN-PQRS-TVWX; hidden as you type): ") + [ -n "$CODE" ] || problem "No join code given." "Set MEDCHAIN_JOIN_CODE to the code the organiser gave you (or type it when asked), then run the same command again." + valid_code "$CODE" || + problem "That is not a join code: a join code is 20 letters and digits in groups of four, like ABCD-EFGH-JKMN-PQRS-TVWX." \ + "Check it with the organiser (or ask for a new one), then run the same command again." +fi + +# ---- 6. The MedChain image --------------------------------------------------------------------- printf '\nDownloading the MedChain program (%s:%s, about 2 GB the first time)...\n' "$IMAGE" "$VERSION" if ! docker pull "$IMAGE:$VERSION"; then docker image inspect "$IMAGE:$VERSION" >/dev/null 2>&1 || @@ -95,7 +128,7 @@ if ! docker pull "$IMAGE:$VERSION"; then printf ' (could not check for a newer copy; using the one already on this computer)\n' fi -# ---- 6. This computer's facts, for the dashboard's proof of origin ----------------------------- +# ---- 7. This computer's facts, for the dashboard's proof of origin ----------------------------- if [ "$(uname)" = Darwin ]; then OS="$(sw_vers -productName) $(sw_vers -productVersion)" BOOTED=$(sysctl -n kern.boottime | sed -n 's/^{ sec = \([0-9]*\),.*/\1/p') # "{ sec = 1712345678, usec = ... }" @@ -110,14 +143,11 @@ MEDCHAIN_HOST_OS=$OS MEDCHAIN_HOST_BOOTED_AT=$BOOTED MEDCHAIN_TAILSCALE_DEVICE=$DEVICE -# ---- 7. Enroll (once) -------------------------------------------------------------------------- -ENV_FILE="$DIR/.env" -NODE_ID=$(sed -n 's/^NODE_ID=//p' "$ENV_FILE" 2>/dev/null | head -n 1) +# ---- 8. Enroll (once), or refresh an enrolled computer's settings ------------------------------- USER_FLAG=() RECREATE=() [ "$(uname)" = Linux ] && USER_FLAG=(--user "$(id -u):$(id -g)") # the kit's files belong to you, not root -if [ -n "$NODE_ID" ] && [ -f "$DIR/pki/$NODE_ID/tls.crt" ]; then - ok "This computer is already enrolled ($NODE_ID); keeping its keys" +if [ -n "$RERUN" ]; then # the node checks in with the hub only when it starts: recreate it, so step 9 sees the hub's answer of now RECREATE=(--force-recreate) # refresh what can change: this computer's Tailscale address, its facts, and its port when MEDCHAIN_PORT asks @@ -129,10 +159,7 @@ if [ -n "$NODE_ID" ] && [ -f "$DIR/pki/$NODE_ID/tls.crt" ]; then "$NODE_PORT" "$TS_IP" "$NODE_PORT" "$MEDCHAIN_HOST_NAME" "$MEDCHAIN_HOST_OS" "$MEDCHAIN_HOST_BOOTED_AT" "$MEDCHAIN_TAILSCALE_DEVICE" } >"$ENV_FILE.new" && mv "$ENV_FILE.new" "$ENV_FILE" else - printf '\nEnrolling this computer. The organiser gives you a join code (it works once, for 30 minutes).\n' enrolled="" - NAME=${MEDCHAIN_DISPLAY_NAME:-} - CODE=${MEDCHAIN_JOIN_CODE:-} for _ in 1 2 3; do while [ "${#NAME}" -lt 2 ] || [ "${#NAME}" -gt 60 ]; do NAME=$(ask "Your hospital's name, as the dashboard should show it (2 to 60 characters): ") @@ -164,14 +191,14 @@ else NODE_ID=$(sed -n 's/^NODE_ID=//p' "$ENV_FILE" | head -n 1) fi -# ---- 8. Start (or restart) the hospital -------------------------------------------------------- +# ---- 9. Start (or restart) the hospital -------------------------------------------------------- printf '\n' docker compose --project-directory "$DIR" -f "$DIR/deploy/node.yml" up -d ${RECREATE[@]+"${RECREATE[@]}"} || problem "Docker could not start the hospital." \ "If it says 'port is already allocated', another program uses port $PORT: stop it, or set MEDCHAIN_PORT to another port and run the same command again (no new join code needed). Otherwise restart Docker and run this again." UP="docker compose --project-directory \"$DIR\" -f \"$DIR/deploy/node.yml\"" -# ---- 9. Did the hub let it in? ------------------------------------------------------------------- +# ---- 10. Did the hub let it in? ------------------------------------------------------------------- printf '\nWaiting for the hub to place this hospital (up to %ss)...\n' "$((REGISTER_TRIES * 3))" registered="" for _ in $(seq 1 "$REGISTER_TRIES"); do @@ -181,7 +208,8 @@ for _ in $(seq 1 "$REGISTER_TRIES"); do [ $code -eq 3 ] && { docker compose --project-directory "$DIR" -f "$DIR/deploy/node.yml" down >/dev/null 2>&1 problem "The organiser removed this computer from the network: the hub refuses its keys (${line#the hub refuses this hospital: })." \ - "Delete the folder $DIR, ask the organiser for a new join code, then run the same command again." + "Delete the folder $DIR, ask the organiser for a new join code, then run the same command again." \ + "This computer's hospital has been stopped; nothing else was changed." } sleep 3 done diff --git a/docs/MULTI_LAPTOP.md b/docs/MULTI_LAPTOP.md index 19270fc..9b00ae9 100644 --- a/docs/MULTI_LAPTOP.md +++ b/docs/MULTI_LAPTOP.md @@ -278,8 +278,9 @@ to hit. "Preflight says" is the text after `unreachable`; "logs say" is from the ## For the organiser -**Join codes (the quick way).** Start the hub (`make hub`, step 2 below; the hub kit -from `provision.py` is still how the hub gets its keys), open the dashboard and log in +**Join codes (the quick way).** Make your kits with only your own hospital in +`--peers` (step 1 below: the hub kit from `provision.py` is still how the hub gets +its keys; everyone else joins with a code), start the hub (step 2), open the dashboard and log in as `admin` (set `MEDCHAIN_ADMIN_PASSWORD`, at least 10 characters, in `hub.env` first: without it nobody can log in). On **JOIN CODES**, press **Create a join code**: it is shown once. Give it to one friend with the install command the page shows (it has your hub's @@ -316,7 +317,8 @@ code needed. **Postgres already running on the hub laptop?** Set `POSTGRES_PORT` `hub.env`. You run the **hub** (the directory, the observer, Postgres and the dashboard) from -a checkout of this repository. Run it with Docker on your own laptop. +a checkout of this repository, or the release's source zip, unpacked. Run it with +Docker on your own laptop. Docker is all you need: no Python, no `make`. 1. **Make the kits.** List every hospital with the address the others will reach it at (including any you run yourself, like `hospital-d` here), and your @@ -328,16 +330,33 @@ a checkout of this repository. Run it with Docker on your own laptop. --directory sam-laptop.tail1234.ts.net:8100 ``` + If everyone else will join with a join code, list only your own hospital: + `--peers hospital-d=sam-laptop.tail1234.ts.net:8004`. + + **No Python?** Run the same command inside the published image, from the + repository folder (it works in PowerShell and in a Mac or Linux terminal; on + Linux add `--user "$(id -u):$(id -g)"` after `--rm` so the kits belong to you): + + ```sh + docker run --rm -v "${PWD}:/src" -w /src ghcr.io/denimworld12/medchain-node:v1.1.0 python scripts/provision.py --zip --peers hospital-d=sam-laptop.tail1234.ts.net:8004 --directory sam-laptop.tail1234.ts.net:8100 + ``` + This writes `kits/hospital-a.zip` and so on, plus `kits/directory/`, your hub kit with a filled `hub.env`. It also prints the network's shared secret; keep it. Send each hospital its own zip privately. A kit holds that hospital's keys. -2. **Start the hub:** `make hub`. This is - `docker compose --project-directory . --env-file kits/directory/hub.env -f deploy/hub.yml up -d --wait`. +2. **Start the hub:** `make hub`. Without `make` (a stock Windows laptop has none), + run what it runs, from the repository folder: + + ```sh + docker compose --project-directory . --env-file kits/directory/hub.env -f deploy/hub.yml up -d --wait + ``` + The dashboard is at