diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-13 16:11:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-13 16:11:16 -0500 |
| commit | e179a1022319ec77d936f1cee21c471ac34f4d53 (patch) | |
| tree | 224736a2f3b18e8823b8af50e30edc2ee747a62a /scripts | |
| parent | 1fc6925f9328ce7ce909aad0acf619d618eddcc2 (diff) | |
| download | dotemacs-e179a1022319ec77d936f1cee21c471ac34f4d53.tar.gz dotemacs-e179a1022319ec77d936f1cee21c471ac34f4d53.zip | |
feat(setup): scripts/setup-telega.sh prepares the docker environment for telega
Verifies docker is installed and the daemon is reachable, then either pulls a public image (when `TELEGA_DOCKER_IMAGE` is set) or announces the in-Emacs build path (`M-x telega-server-build`) for the user to run once. Telegram auth (phone + verification code) is interactive on first `M-x telega` and not scripted here.
Same shape as setup-email.sh: helpers are sourceable for bats, `main` runs only under direct execution. 7 bats tests stub `docker` and `command` so the suite never talks to the real daemon.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/setup-telega.sh | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/setup-telega.sh b/scripts/setup-telega.sh new file mode 100755 index 00000000..2b565e99 --- /dev/null +++ b/scripts/setup-telega.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Craig Jennings <c@cjennings.net> +# +# Prepares the docker environment telega.el uses for TDLib. +# +# Sequence: +# - Verifies docker is installed and the daemon is responsive. +# - Verifies the user can talk to docker without sudo (group membership). +# - Pulls the telega-server image if a public one is configured (env var +# `TELEGA_DOCKER_IMAGE'); otherwise prints the in-Emacs build command +# (`M-x telega-server-build') for the user to run once. +# +# Does NOT handle Telegram account auth -- phone number + verification +# code is interactive and runs inside `M-x telega' on first launch. +# +# Sourceable: only `main' runs when the script is executed directly, so +# the helpers can be tested with bats. + +set -euo pipefail + +# Public image override. When set, the script pulls this image directly +# instead of falling back to the in-Emacs build flow. Default empty so +# the script doesn't assume an image name that may or may not exist +# upstream. +: "${TELEGA_DOCKER_IMAGE:=}" + +ensure_docker_installed() { + if ! command -v docker >/dev/null 2>&1; then + echo " ✗ docker not found on PATH" + echo " install docker (https://docs.docker.com/get-docker/) and rerun" + return 1 + fi + echo " ✓ docker present: $(command -v docker)" +} + +ensure_docker_running() { + if ! docker info >/dev/null 2>&1; then + echo " ✗ cannot talk to the docker daemon" + echo " start the daemon (e.g. 'sudo systemctl start docker') or" + echo " add your user to the 'docker' group, then re-login and rerun" + return 1 + fi + echo " ✓ docker daemon reachable" +} + +pull_or_announce_image() { + if [[ -z "$TELEGA_DOCKER_IMAGE" ]]; then + cat <<EOF + → no public image configured (set TELEGA_DOCKER_IMAGE to override) + build the telega-server image once from inside Emacs: + M-x telega-server-build + telega.el handles the docker build under the hood when + \`telega-use-docker' is t (set in modules/telega-config.el). +EOF + return 0 + fi + echo " → pulling $TELEGA_DOCKER_IMAGE..." + if docker pull "$TELEGA_DOCKER_IMAGE"; then + echo " ✓ pulled $TELEGA_DOCKER_IMAGE" + else + echo " ✗ pull failed for $TELEGA_DOCKER_IMAGE" + return 1 + fi +} + +main() { + echo "→ checking docker..." + ensure_docker_installed + ensure_docker_running + echo "→ preparing telega-server image..." + pull_or_announce_image + echo "✅ Telega docker setup complete." + echo " First launch: M-x telega -- enter phone + verification code interactively." +} + +# Run main only when the script is executed directly. Sourcing this file +# (for example from a bats test) just defines the helpers above. +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi |
