Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/scripts/one-click-install.sh
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 18 minutes ago History
one-click-install.sh · 7.4 KB · 157 lines
1#!/usr/bin/env bash
2#
3# DBBASIC Object Server on a new public server, for a one-click installer (cloud-init.yaml runs this).
4#
5# sudo bash scripts/one-click-install.sh 2026.11v1
6#
7# scripts/install.sh assumes an operator who is there and opens things up step by step. A one-click box
8# is on the public internet from its first second with nobody signed up, so this runs install.sh and then
9# closes it up before anything outside can reach it:
10#
11# 1. a setup code. The installer (GitStable) shows the code to the person who pressed the button and
12# puts only its SHA-256 in /etc/dbbasic-setup-code.sha256 (cloud-init). It moves into the data
13# directory, and until someone uses it at /setup the server answers nothing but /health and /setup
14# (object_setup.py). No default login, and no password the box could hand out.
15# 2. password login on (setup makes one) and permission enforcement on, set before the restart below.
16# The box's policy is the rules its starting apps ship (each package writes its own); no separate
17# starter policy is saved. Enforcement is effective from that first start: password login counts as
18# the sign-in path before any user exists, and until setup the gate above answers only /health and
19# /setup (the admin token still works). A policy with no allow grants is enforced as deny-all, so
20# even a box with no policy file starts. A box with enforcement on and no usable sign-in path or
21# admin token refuses to start rather than run open.
22# 3. HTTPS on the server's IP address, from Let's Encrypt, through Caddy: the setup code and the new
23# password never cross the network in the clear. The server itself stays on 127.0.0.1:8001.
24#
25# Refuses to start without the setup code: a public box with no way to claim it but a race is worse
26# than no box. Safe to re-run (a later release, or after a failure); a box already set up stays set up.
27#
28set -euo pipefail
29
30VERSION="${1:?usage: one-click-install.sh <release, such as 2026.11v1>}"
31HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
32CODE_DIR="${DBBASIC_CODE_DIR:-/opt/dbbasic-object-server}"
33STATE_DIR="${DBBASIC_STATE_DIR:-/var/lib/dbbasic-object-server}"
34ENV_FILE="${DBBASIC_ENV_FILE:-/etc/dbbasic-object-server.env}"
35DATA_DIR="${STATE_DIR}/data"
36SETUP_HASH_IN="/etc/dbbasic-setup-code.sha256"
37SETUP_HASH="${DATA_DIR}/identity/setup_code.sha256"
38SERVICE_USER="dbbasic"
39export DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a
40
41say() { printf '\033[1;36m==>\033[0m %s\n' "$*"; }
42
43if [[ "${EUID}" -ne 0 ]]; then
44 echo "Run as root." >&2
45 exit 1
46fi
47
48already_set_up() { # an admin exists: the same test the server uses (object_setup._admin_exists)
49 [[ -f "${DATA_DIR}/identity/users.tsv" && -x "${CODE_DIR}/.venv/bin/python" ]] || return 1
50 ( cd "${CODE_DIR}" && sudo -u "${SERVICE_USER}" .venv/bin/python -c \
51 'import sys, object_setup as s; sys.exit(0 if s._admin_exists(sys.argv[1]) else 1)' "${DATA_DIR}" )
52}
53
54if [[ ! -s "${SETUP_HASH_IN}" && ! -s "${SETUP_HASH}" ]] && ! already_set_up; then
55 echo "No setup code (${SETUP_HASH_IN}). The installer puts its hash there; without it nobody could" >&2
56 echo "become this server's admin except by racing for it. Stopping before anything is installed." >&2
57 exit 1
58fi
59if ! grep -Eqx 'sha256:[0-9a-f]{64}' "${SETUP_HASH_IN}" 2>/dev/null && [[ -e "${SETUP_HASH_IN}" ]]; then
60 echo "${SETUP_HASH_IN} isn't a setup code hash (sha256:<64 hex>). Stopping." >&2
61 exit 1
62fi
63
64bash "${HERE}/install.sh" --version "${VERSION}"
65
66say "Setup code: only its hash, readable by the server alone"
67if [[ -s "${SETUP_HASH_IN}" ]]; then
68 if already_set_up; then
69 rm -f "${SETUP_HASH_IN}" # someone is admin already: there's nothing left to claim
70 else
71 install -d -o "${SERVICE_USER}" -g "${SERVICE_USER}" -m 0700 "${DATA_DIR}/identity"
72 install -o "${SERVICE_USER}" -g "${SERVICE_USER}" -m 0600 "${SETUP_HASH_IN}" "${SETUP_HASH}"
73 rm -f "${SETUP_HASH_IN}"
74 FRESH=1
75 fi
76fi
77
78if [[ "${FRESH:-0}" == 1 ]]; then
79 # A new box with no apps has no home page: the owner finished setup and landed on "Not found" (seen on the
80 # first test droplet, 2026-11-23). The apps to start with are the desk's set (nc-object-bootstrap) without
81 # the ones that need keys or more setup (shell, notify, sites). Order matters: install_package doesn't pull
82 # in dependencies, and notes without app-views was "Object not found: site_view_render" (2026.11v1).
83 # Only on a fresh box, so a re-run never replaces apps the owner may have changed.
84 say "Starting apps: home and menu, projects, notes, tasks, files"
85 ( cd "${CODE_DIR}" && sudo -u "${SERVICE_USER}" .venv/bin/python -c '
86import sys
87from pathlib import Path
88import object_packages
89for app in ("app-theme", "app-views", "app-nav", "app-projects", "app-files", "app-tasks", "app-collab",
90 "app-notes", "app-settings"):
91 object_packages.install_package(app, root=Path("packages"), base_dir=Path(sys.argv[1]),
92 object_roots=[Path(sys.argv[2])], allow_replace=True)
93 print(" " + app)
94' "${DATA_DIR}" "${STATE_DIR}/objects" )
95fi
96
97say "Login and permissions for a public server"
98set_env() { # KEY VALUE: replace the line, or add it
99 if grep -q "^$1=" "${ENV_FILE}"; then
100 sed -i "s|^$1=.*|$1=$2|" "${ENV_FILE}"
101 else
102 printf '%s=%s\n' "$1" "$2" >> "${ENV_FILE}"
103 fi
104}
105set_env DBBASIC_ENABLE_PASSWORD_LOGIN true
106set_env DBBASIC_ENABLE_PERMISSION_ENFORCEMENT true
107set_env DBBASIC_COOKIE_SECURE true
108set_env DBBASIC_RATE_LIMIT_TRUST_PROXY_HEADERS true # Caddy writes X-Forwarded-For itself
109systemctl restart dbbasic-object-server dbbasic-object-daemon
110
111say "Caddy, for HTTPS on this server's address"
112ADDRESS="${DBBASIC_PUBLIC_ADDRESS:-}"
113if [[ -z "${ADDRESS}" ]]; then
114 # DigitalOcean's metadata service; another cloud sets DBBASIC_PUBLIC_ADDRESS
115 ADDRESS="$(curl -fsS --max-time 5 http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address || true)"
116fi
117if ! [[ "${ADDRESS}" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then
118 echo "Couldn't tell this server's public IPv4 address; set DBBASIC_PUBLIC_ADDRESS and run again." >&2
119 exit 1
120fi
121if ! command -v caddy >/dev/null 2>&1; then
122 # Caddy's own packages: Ubuntu's caddy is too old to ask Let's Encrypt for an IP address certificate
123 apt-get install -y -qq debian-keyring debian-archive-keyring apt-transport-https curl gnupg
124 curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
125 | gpg --dearmor --yes -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
126 curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' > /etc/apt/sources.list.d/caddy-stable.list
127 apt-get update -qq
128 apt-get install -y -qq caddy
129fi
130cat > /etc/caddy/Caddyfile <<EOF
131# Written by scripts/one-click-install.sh. A certificate for the bare IP address (Let's Encrypt gives
132# those only as six-day "shortlived" certificates; Caddy renews them). With a domain, replace the
133# address below with the domain name and drop the two global lines.
134{
135 default_sni ${ADDRESS}
136 cert_issuer acme {
137 profile shortlived
138 }
139}
140
141${ADDRESS} {
142 reverse_proxy 127.0.0.1:8001
143}
144EOF
145systemctl enable -q caddy
146systemctl restart caddy
147
148say "Waiting for https://${ADDRESS}/health (the certificate takes a few seconds)"
149for _ in $(seq 1 60); do
150 if curl -fsS --max-time 5 "https://${ADDRESS}/health" >/dev/null 2>&1; then
151 say "Up: https://${ADDRESS}/ (setup at https://${ADDRESS}/setup with the code the installer showed you)"
152 exit 0
153 fi
154 sleep 3
155done
156echo "HTTPS didn't answer yet; see: journalctl -u caddy -e" >&2
157exit 1