offgit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. offgit-0.1.0/.gitignore +11 -0
  2. offgit-0.1.0/LICENSE +21 -0
  3. offgit-0.1.0/PKG-INFO +171 -0
  4. offgit-0.1.0/README.md +146 -0
  5. offgit-0.1.0/deploy/install-server.sh +207 -0
  6. offgit-0.1.0/deploy/offgit-backup-retention.service +24 -0
  7. offgit-0.1.0/deploy/offgit-backup-retention.timer +10 -0
  8. offgit-0.1.0/deploy/offgit-backup.service +31 -0
  9. offgit-0.1.0/deploy/offgit-backup.timer +11 -0
  10. offgit-0.1.0/deploy/server.toml.example +24 -0
  11. offgit-0.1.0/deploy/ssh-authorized-keys.example +7 -0
  12. offgit-0.1.0/docs/architecture.md +208 -0
  13. offgit-0.1.0/docs/backup-and-recovery.md +203 -0
  14. offgit-0.1.0/docs/decisions.md +61 -0
  15. offgit-0.1.0/docs/protocol.md +114 -0
  16. offgit-0.1.0/docs/security.md +67 -0
  17. offgit-0.1.0/docs/server-setup.md +188 -0
  18. offgit-0.1.0/docs/testing.md +65 -0
  19. offgit-0.1.0/pyproject.toml +90 -0
  20. offgit-0.1.0/src/offgit/__init__.py +4 -0
  21. offgit-0.1.0/src/offgit/cli.py +498 -0
  22. offgit-0.1.0/src/offgit/client.py +1636 -0
  23. offgit-0.1.0/src/offgit/config.py +281 -0
  24. offgit-0.1.0/src/offgit/errors.py +115 -0
  25. offgit-0.1.0/src/offgit/gitrepo.py +186 -0
  26. offgit-0.1.0/src/offgit/hashing.py +22 -0
  27. offgit-0.1.0/src/offgit/identity.py +243 -0
  28. offgit-0.1.0/src/offgit/local_state.py +255 -0
  29. offgit-0.1.0/src/offgit/output.py +160 -0
  30. offgit-0.1.0/src/offgit/paths.py +367 -0
  31. offgit-0.1.0/src/offgit/protocol.py +466 -0
  32. offgit-0.1.0/src/offgit/reconcile.py +169 -0
  33. offgit-0.1.0/src/offgit/server/__init__.py +1 -0
  34. offgit-0.1.0/src/offgit/server/backup.py +401 -0
  35. offgit-0.1.0/src/offgit/server/cli.py +391 -0
  36. offgit-0.1.0/src/offgit/server/export.py +75 -0
  37. offgit-0.1.0/src/offgit/server/health.py +59 -0
  38. offgit-0.1.0/src/offgit/server/locks.py +48 -0
  39. offgit-0.1.0/src/offgit/server/migrate.py +59 -0
  40. offgit-0.1.0/src/offgit/server/migrations/__init__.py +12 -0
  41. offgit-0.1.0/src/offgit/server/migrations/v001_initial.py +57 -0
  42. offgit-0.1.0/src/offgit/server/restore.py +207 -0
  43. offgit-0.1.0/src/offgit/server/rpc.py +187 -0
  44. offgit-0.1.0/src/offgit/server/schema.py +228 -0
  45. offgit-0.1.0/src/offgit/server/settings.py +140 -0
  46. offgit-0.1.0/src/offgit/server/store.py +658 -0
  47. offgit-0.1.0/src/offgit/transport.py +304 -0
  48. offgit-0.1.0/tests/conftest.py +182 -0
  49. offgit-0.1.0/tests/e2e/test_acceptance.py +128 -0
  50. offgit-0.1.0/tests/e2e/test_real_sshd.py +160 -0
  51. offgit-0.1.0/tests/integration/test_backup_restore.py +354 -0
  52. offgit-0.1.0/tests/integration/test_cli_ssh.py +195 -0
  53. offgit-0.1.0/tests/integration/test_failures.py +485 -0
  54. offgit-0.1.0/tests/integration/test_git_root.py +114 -0
  55. offgit-0.1.0/tests/integration/test_sync_flows.py +473 -0
  56. offgit-0.1.0/tests/unit/test_config_reconcile.py +113 -0
  57. offgit-0.1.0/tests/unit/test_identity.py +138 -0
  58. offgit-0.1.0/tests/unit/test_paths.py +140 -0
  59. offgit-0.1.0/tests/unit/test_protocol.py +167 -0
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ .coverage
11
+ htmlcov/
offgit-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 offgit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
offgit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.5
2
+ Name: offgit
3
+ Version: 0.1.0
4
+ Summary: Versioned synchronization for files Git ignores.
5
+ Project-URL: Documentation, https://github.com/sjcsoftware/offgit/tree/main/docs
6
+ Project-URL: Repository, https://github.com/sjcsoftware/offgit
7
+ Author: offgit contributors
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: backup,git,gitignore,ssh,sync
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Version Control :: Git
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: rich>=13.7
23
+ Requires-Dist: typer>=0.12
24
+ Description-Content-Type: text/markdown
25
+
26
+ <div align="center">
27
+
28
+ # offgit
29
+
30
+ [![CI](https://github.com/sjcsoftware/offgit/actions/workflows/ci.yml/badge.svg)](https://github.com/sjcsoftware/offgit/actions/workflows/ci.yml)
31
+ [![Release](https://img.shields.io/github/v/release/sjcsoftware/offgit?include_prereleases)](https://github.com/sjcsoftware/offgit/releases)
32
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
33
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-3776AB?logo=python&logoColor=white)](pyproject.toml)
34
+
35
+ [![Server](https://img.shields.io/badge/Server-Linux-FCC624?logo=linux&logoColor=black)](docs/server-setup.md)
36
+ [![Client](https://img.shields.io/badge/Client-macOS%20%7C%20Linux-000000)](#install)
37
+
38
+ ### Versioned sync for files Git ignores.
39
+
40
+ `.env`, `PLAN.md`, `TODO.md` kept in sync across your machines.
41
+
42
+ [Install](#install) · [Quick Start](#quick-start) · [How it works](#how-it-works) · [Docs](#docs)
43
+
44
+ </div>
45
+
46
+ ---
47
+
48
+ ```sh
49
+ offgit init -f .env PLAN.md # once, at the project root
50
+ offgit push # to your Pi, NAS, etc.
51
+
52
+ # --Another machine--
53
+ offgit pull # Detects `git remote -v` and auto-pulls relevant files
54
+ ```
55
+
56
+ > [!IMPORTANT]
57
+ > **Your own server is the source of truth.** offgit talks only to a machine you own (e.g. a
58
+ > Raspberry Pi on Tailscale) over SSH. There's no cloud fallback and no silent overwrite: if both
59
+ > sides changed a file, nothing is touched until you choose.
60
+
61
+ ## Install
62
+
63
+ | Side | Install | Platform | Requires |
64
+ |---|---|---|---|
65
+ | **Client** | `offgit` | macOS or Linux | Python ≥ 3.11, Git, OpenSSH |
66
+ | **Server** | `offgit-server` | Linux (Ubuntu 24.04, arm64 / x86-64) | Python ≥ 3.11, OpenSSH server |
67
+
68
+ **Client**
69
+
70
+ ```sh
71
+ uv tool install offgit # or: pipx install offgit
72
+ ```
73
+
74
+ **Server**
75
+
76
+ ```sh
77
+ curl -fsSL https://raw.githubusercontent.com/sjcsoftware/offgit/main/deploy/install-server.sh | sudo bash
78
+ # add -s -- --with-backup-tools for restic + rclone, -s -- --dry-run to preview
79
+ ```
80
+
81
+ This creates a no-sudo `offgit` user, `/opt/offgit/venv`, and `/var/lib/offgit`. It never
82
+ touches your firewall, Tailscale, or `sshd_config`. [Server setup](docs/server-setup.md)
83
+
84
+ ## Quick Start
85
+
86
+ > Server (once per client device)
87
+ ```sh
88
+ # authorize the device's dedicated key, locked to the RPC command
89
+ echo 'restrict,command="/opt/offgit/venv/bin/offgit-server rpc" ssh-ed25519 AAAA... laptop' \
90
+ | sudo tee -a /var/lib/offgit/.ssh/authorized_keys
91
+ ```
92
+
93
+ > Client
94
+ ```sh
95
+ # 1) Connect Once (the host key must already be in known_hosts)
96
+ offgit configure --host pi5 --user offgit --identity ~/.ssh/offgit_ed25519
97
+ offgit doctor
98
+
99
+ # 2) First machine: register ignored files
100
+ cd ~/projects/myapp
101
+ offgit init -f .env PLAN.md TASKS.md
102
+
103
+ # 3) Other machines: automatically identifies repo with git remote address
104
+ cd ~/Developer/myapp
105
+ git pull
106
+ offgit pull
107
+
108
+ # 4) Day to day
109
+ offgit status
110
+ offgit push
111
+ ```
112
+
113
+ ## Commands
114
+
115
+ | Command | Does |
116
+ |---|---|
117
+ | `push` / `pull` / `sync` | Upload local changes / download server changes / both. `--dry-run` changes nothing. |
118
+ | `status` / `diff` / `list` | Per-file state, unified diff server → local, and registered files. Read-only. |
119
+ | `add` / `remove` | Register more files, or unregister for all devices (local files kept). |
120
+ | `history` / `restore FILE -r N` | Revision log, and republish an old version as a new revision. |
121
+ | `push --prefer-local F` / `pull --prefer-remote F` | Resolve a conflict explicitly; the other side's copy is kept. |
122
+ | `rebaseline` | Re-verify after the server was restored from backup. |
123
+
124
+ Every command takes `--json`. Exit codes: `0` ok · `2` usage · `3` server unreachable · `4` conflict · `5` partial or recovery needed.
125
+
126
+ ## How it works
127
+
128
+ | Piece | What happens |
129
+ |---|---|
130
+ | **Identity** | `https://github.com/o/r`, `git@github.com:o/r.git` and `ssh://…` all map to `github.com/o/r`. Credentials are stripped. |
131
+ | **Selection** | Exact paths only, each one untracked *and* ignored according to Git itself. Checked again before every read and write. |
132
+ | **Sync** | Three-way compare per file (last common base, local, server) by SHA-256. No mtimes, no newline changes, binary-safe. |
133
+ | **Server** | One SQLite file. Every change is one transaction with compare-and-swap, and full history is kept. |
134
+ | **Transport** | One JSON request per `ssh` call to a forced command. No daemon, no open port. |
135
+ | **Local state** | Lives in `.git/offgit/`, so `git status` stays clean. |
136
+
137
+ ## Backups
138
+
139
+ The server makes hourly, encrypted, versioned backups to Google Drive with restic + rclone.
140
+ Clients never talk to the cloud. [Backup & restore →](docs/backup-and-recovery.md)
141
+
142
+ > [!WARNING]
143
+ > **Limitations**
144
+ > - One owner, several devices. Every authorized key can access every project.
145
+ > - Small files: 8 MiB per file, 32 MiB and 256 paths per project by default.
146
+ > - All branches and worktrees of a remote share one set of files.
147
+ > - Repository renames aren't followed automatically.
148
+ >
149
+ > [Security & residual risks](docs/security.md)
150
+
151
+ ## Docs
152
+
153
+ - [Server setup](docs/server-setup.md): install, keys, Tailscale, upgrades
154
+ - [Backup & recovery](docs/backup-and-recovery.md): rclone, restic, retention, restore drill
155
+ - [Architecture](docs/architecture.md) · [Protocol](docs/protocol.md) · [Security](docs/security.md) · [Decisions](docs/decisions.md) · [Test report](docs/testing.md)
156
+
157
+ ## Development
158
+
159
+ ```sh
160
+ uv sync --all-groups
161
+ uv run ruff check . && uv run mypy && uv run pytest
162
+ ```
163
+
164
+ ## Uninstall
165
+
166
+ ```sh
167
+ uv tool uninstall offgit # client: your files stay where they are
168
+ sudo rm -rf /opt/offgit # server app: data in /var/lib/offgit is kept
169
+ ```
170
+
171
+ MIT License
offgit-0.1.0/README.md ADDED
@@ -0,0 +1,146 @@
1
+ <div align="center">
2
+
3
+ # offgit
4
+
5
+ [![CI](https://github.com/sjcsoftware/offgit/actions/workflows/ci.yml/badge.svg)](https://github.com/sjcsoftware/offgit/actions/workflows/ci.yml)
6
+ [![Release](https://img.shields.io/github/v/release/sjcsoftware/offgit?include_prereleases)](https://github.com/sjcsoftware/offgit/releases)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
8
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-3776AB?logo=python&logoColor=white)](pyproject.toml)
9
+
10
+ [![Server](https://img.shields.io/badge/Server-Linux-FCC624?logo=linux&logoColor=black)](docs/server-setup.md)
11
+ [![Client](https://img.shields.io/badge/Client-macOS%20%7C%20Linux-000000)](#install)
12
+
13
+ ### Versioned sync for files Git ignores.
14
+
15
+ `.env`, `PLAN.md`, `TODO.md` kept in sync across your machines.
16
+
17
+ [Install](#install) · [Quick Start](#quick-start) · [How it works](#how-it-works) · [Docs](#docs)
18
+
19
+ </div>
20
+
21
+ ---
22
+
23
+ ```sh
24
+ offgit init -f .env PLAN.md # once, at the project root
25
+ offgit push # to your Pi, NAS, etc.
26
+
27
+ # --Another machine--
28
+ offgit pull # Detects `git remote -v` and auto-pulls relevant files
29
+ ```
30
+
31
+ > [!IMPORTANT]
32
+ > **Your own server is the source of truth.** offgit talks only to a machine you own (e.g. a
33
+ > Raspberry Pi on Tailscale) over SSH. There's no cloud fallback and no silent overwrite: if both
34
+ > sides changed a file, nothing is touched until you choose.
35
+
36
+ ## Install
37
+
38
+ | Side | Install | Platform | Requires |
39
+ |---|---|---|---|
40
+ | **Client** | `offgit` | macOS or Linux | Python ≥ 3.11, Git, OpenSSH |
41
+ | **Server** | `offgit-server` | Linux (Ubuntu 24.04, arm64 / x86-64) | Python ≥ 3.11, OpenSSH server |
42
+
43
+ **Client**
44
+
45
+ ```sh
46
+ uv tool install offgit # or: pipx install offgit
47
+ ```
48
+
49
+ **Server**
50
+
51
+ ```sh
52
+ curl -fsSL https://raw.githubusercontent.com/sjcsoftware/offgit/main/deploy/install-server.sh | sudo bash
53
+ # add -s -- --with-backup-tools for restic + rclone, -s -- --dry-run to preview
54
+ ```
55
+
56
+ This creates a no-sudo `offgit` user, `/opt/offgit/venv`, and `/var/lib/offgit`. It never
57
+ touches your firewall, Tailscale, or `sshd_config`. [Server setup](docs/server-setup.md)
58
+
59
+ ## Quick Start
60
+
61
+ > Server (once per client device)
62
+ ```sh
63
+ # authorize the device's dedicated key, locked to the RPC command
64
+ echo 'restrict,command="/opt/offgit/venv/bin/offgit-server rpc" ssh-ed25519 AAAA... laptop' \
65
+ | sudo tee -a /var/lib/offgit/.ssh/authorized_keys
66
+ ```
67
+
68
+ > Client
69
+ ```sh
70
+ # 1) Connect Once (the host key must already be in known_hosts)
71
+ offgit configure --host pi5 --user offgit --identity ~/.ssh/offgit_ed25519
72
+ offgit doctor
73
+
74
+ # 2) First machine: register ignored files
75
+ cd ~/projects/myapp
76
+ offgit init -f .env PLAN.md TASKS.md
77
+
78
+ # 3) Other machines: automatically identifies repo with git remote address
79
+ cd ~/Developer/myapp
80
+ git pull
81
+ offgit pull
82
+
83
+ # 4) Day to day
84
+ offgit status
85
+ offgit push
86
+ ```
87
+
88
+ ## Commands
89
+
90
+ | Command | Does |
91
+ |---|---|
92
+ | `push` / `pull` / `sync` | Upload local changes / download server changes / both. `--dry-run` changes nothing. |
93
+ | `status` / `diff` / `list` | Per-file state, unified diff server → local, and registered files. Read-only. |
94
+ | `add` / `remove` | Register more files, or unregister for all devices (local files kept). |
95
+ | `history` / `restore FILE -r N` | Revision log, and republish an old version as a new revision. |
96
+ | `push --prefer-local F` / `pull --prefer-remote F` | Resolve a conflict explicitly; the other side's copy is kept. |
97
+ | `rebaseline` | Re-verify after the server was restored from backup. |
98
+
99
+ Every command takes `--json`. Exit codes: `0` ok · `2` usage · `3` server unreachable · `4` conflict · `5` partial or recovery needed.
100
+
101
+ ## How it works
102
+
103
+ | Piece | What happens |
104
+ |---|---|
105
+ | **Identity** | `https://github.com/o/r`, `git@github.com:o/r.git` and `ssh://…` all map to `github.com/o/r`. Credentials are stripped. |
106
+ | **Selection** | Exact paths only, each one untracked *and* ignored according to Git itself. Checked again before every read and write. |
107
+ | **Sync** | Three-way compare per file (last common base, local, server) by SHA-256. No mtimes, no newline changes, binary-safe. |
108
+ | **Server** | One SQLite file. Every change is one transaction with compare-and-swap, and full history is kept. |
109
+ | **Transport** | One JSON request per `ssh` call to a forced command. No daemon, no open port. |
110
+ | **Local state** | Lives in `.git/offgit/`, so `git status` stays clean. |
111
+
112
+ ## Backups
113
+
114
+ The server makes hourly, encrypted, versioned backups to Google Drive with restic + rclone.
115
+ Clients never talk to the cloud. [Backup & restore →](docs/backup-and-recovery.md)
116
+
117
+ > [!WARNING]
118
+ > **Limitations**
119
+ > - One owner, several devices. Every authorized key can access every project.
120
+ > - Small files: 8 MiB per file, 32 MiB and 256 paths per project by default.
121
+ > - All branches and worktrees of a remote share one set of files.
122
+ > - Repository renames aren't followed automatically.
123
+ >
124
+ > [Security & residual risks](docs/security.md)
125
+
126
+ ## Docs
127
+
128
+ - [Server setup](docs/server-setup.md): install, keys, Tailscale, upgrades
129
+ - [Backup & recovery](docs/backup-and-recovery.md): rclone, restic, retention, restore drill
130
+ - [Architecture](docs/architecture.md) · [Protocol](docs/protocol.md) · [Security](docs/security.md) · [Decisions](docs/decisions.md) · [Test report](docs/testing.md)
131
+
132
+ ## Development
133
+
134
+ ```sh
135
+ uv sync --all-groups
136
+ uv run ruff check . && uv run mypy && uv run pytest
137
+ ```
138
+
139
+ ## Uninstall
140
+
141
+ ```sh
142
+ uv tool uninstall offgit # client: your files stay where they are
143
+ sudo rm -rf /opt/offgit # server app: data in /var/lib/offgit is kept
144
+ ```
145
+
146
+ MIT License
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env bash
2
+ # offgit server installer for Ubuntu 24.04 (arm64 / x86-64), e.g. a Raspberry Pi 5.
3
+ #
4
+ # curl -fsSL https://raw.githubusercontent.com/sjcsoftware/offgit/main/deploy/install-server.sh | sudo bash
5
+ # curl -fsSL ... | sudo bash -s -- --with-backup-tools --version v0.1.0
6
+ #
7
+ # Piped from curl, it downloads the offgit source from github.com/sjcsoftware/offgit (the
8
+ # latest release, or main if there is none yet; override with --version REF). Run from a
9
+ # checkout (sudo deploy/install-server.sh), it installs that checkout.
10
+ #
11
+ # Idempotent: safe to re-run for upgrades. It never edits firewalls, Tailscale,
12
+ # sshd_config, or existing authorized_keys entries, never deletes data, and never
13
+ # enables cloud backups on its own.
14
+ if [ -z "${BASH_VERSION:-}" ]; then
15
+ echo "error: run this installer with bash (curl ... | sudo bash)" >&2
16
+ exit 1
17
+ fi
18
+ set -euo pipefail
19
+
20
+ REPO="sjcsoftware/offgit"
21
+ SERVICE_USER="offgit"
22
+ APP_DIR="/opt/offgit"
23
+ VENV="${APP_DIR}/venv"
24
+ DATA_DIR="/var/lib/offgit"
25
+ CONF_DIR="/etc/offgit"
26
+ UNIT_DIR="/etc/systemd/system"
27
+
28
+ usage() {
29
+ cat <<'USAGE'
30
+ usage: install-server.sh [--version REF] [--source PATH] [--with-backup-tools]
31
+ [--enable-backup-timer] [--dry-run]
32
+
33
+ --version REF git tag or branch to download (default: latest release, else main)
34
+ --source PATH install from a local checkout/sdist directory or .whl instead
35
+ --with-backup-tools also apt-install restic and rclone
36
+ --enable-backup-timer enable the hourly backup timer (configure backups first)
37
+ --dry-run print what would be done; change nothing
38
+ USAGE
39
+ exit "${1:-0}"
40
+ }
41
+
42
+ fetch_source() {
43
+ # Download and unpack the repository at a ref into a private temp dir.
44
+ local ref="$1" tmp
45
+ if [[ -z "${ref}" ]]; then
46
+ ref="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null \
47
+ | sed -n 's/^ *"tag_name": *"\([^"]*\)".*/\1/p' | head -n 1 || true)"
48
+ ref="${ref:-main}"
49
+ fi
50
+ if [[ ! "${ref}" =~ ^[A-Za-z0-9._/-]+$ ]]; then
51
+ echo "error: invalid --version ${ref}" >&2
52
+ exit 2
53
+ fi
54
+ tmp="$(mktemp -d)"
55
+ TMP_DIR="${tmp}"
56
+ trap 'rm -rf -- "${TMP_DIR}"' EXIT
57
+ echo "downloading ${REPO}@${ref}"
58
+ curl -fsSL "https://codeload.github.com/${REPO}/tar.gz/${ref}" | tar -xz -C "${tmp}"
59
+ SOURCE="$(find "${tmp}" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
60
+ SCRIPT_DIR="${SOURCE}/deploy"
61
+ }
62
+
63
+ main() {
64
+ WITH_BACKUP_TOOLS=0
65
+ ENABLE_TIMER=0
66
+ DRY_RUN=0
67
+ VERSION=""
68
+ SOURCE=""
69
+ SCRIPT_DIR=""
70
+
71
+ while [[ $# -gt 0 ]]; do
72
+ case "$1" in
73
+ --version) VERSION="$2"; shift 2 ;;
74
+ --source) SOURCE="$2"; shift 2 ;;
75
+ --with-backup-tools) WITH_BACKUP_TOOLS=1; shift ;;
76
+ --enable-backup-timer) ENABLE_TIMER=1; shift ;;
77
+ --dry-run) DRY_RUN=1; shift ;;
78
+ -h|--help) usage 0 ;;
79
+ *) echo "unknown option: $1" >&2; usage 2 ;;
80
+ esac
81
+ done
82
+
83
+ run() {
84
+ echo "+ $*"
85
+ if [[ "${DRY_RUN}" -eq 0 ]]; then "$@"; fi
86
+ }
87
+
88
+ if [[ "${DRY_RUN}" -eq 0 && "$(id -u)" -ne 0 ]]; then
89
+ echo "error: run with sudo (root is needed to create the service user and /opt, /etc, /var/lib paths)" >&2
90
+ exit 1
91
+ fi
92
+
93
+ # Local checkout (script run from deploy/) or piped from curl (download the repo).
94
+ local_dir=""
95
+ if [[ -n "${BASH_SOURCE[0]:-}" && -f "${BASH_SOURCE[0]}" ]]; then
96
+ local_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
97
+ fi
98
+ if [[ -z "${SOURCE}" && -z "${VERSION}" && -n "${local_dir}" && -f "${local_dir}/server.toml.example" ]]; then
99
+ SCRIPT_DIR="${local_dir}"
100
+ SOURCE="$(cd "${SCRIPT_DIR}/.." && pwd)"
101
+ elif [[ -n "${SOURCE}" ]]; then
102
+ if [[ -n "${local_dir}" && -f "${local_dir}/server.toml.example" ]]; then
103
+ SCRIPT_DIR="${local_dir}"
104
+ else
105
+ user_source="${SOURCE}"
106
+ fetch_source "${VERSION}" # only for the deploy/ files (units, config template)
107
+ SOURCE="${user_source}"
108
+ fi
109
+ else
110
+ command -v curl >/dev/null || { echo "error: curl is required" >&2; exit 1; }
111
+ fetch_source "${VERSION}"
112
+ fi
113
+
114
+ if [[ ! -f "${SOURCE}/pyproject.toml" && ! "${SOURCE}" =~ \.whl$ ]]; then
115
+ echo "error: --source must be an offgit checkout/sdist directory or a .whl file" >&2
116
+ exit 2
117
+ fi
118
+
119
+ echo "== offgit server install =="
120
+ echo "source: ${SOURCE}"
121
+
122
+ # 1. Packages (only what is missing; distro packages only).
123
+ pkgs=(python3 python3-venv git openssh-server)
124
+ if [[ "${WITH_BACKUP_TOOLS}" -eq 1 ]]; then pkgs+=(restic rclone); fi
125
+ missing=()
126
+ for p in "${pkgs[@]}"; do
127
+ dpkg -s "$p" >/dev/null 2>&1 || missing+=("$p")
128
+ done
129
+ if [[ ${#missing[@]} -gt 0 ]]; then
130
+ run apt-get update
131
+ run apt-get install -y --no-install-recommends "${missing[@]}"
132
+ fi
133
+
134
+ # 2. Dedicated service user: no sudo, real shell (required for the forced command),
135
+ # no usable password (key-only), home = data directory.
136
+ if ! id "${SERVICE_USER}" >/dev/null 2>&1; then
137
+ run useradd --system --user-group --home-dir "${DATA_DIR}" --no-create-home \
138
+ --shell /bin/sh --comment "offgit server" "${SERVICE_USER}"
139
+ run usermod -p '*' "${SERVICE_USER}"
140
+ fi
141
+ if id -nG "${SERVICE_USER}" 2>/dev/null | tr ' ' '\n' | grep -qxE 'sudo|admin|wheel'; then
142
+ echo "error: ${SERVICE_USER} must not be in an admin group" >&2
143
+ exit 1
144
+ fi
145
+
146
+ # 3. Data directory (owner-writable, private).
147
+ run install -d -m 0700 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${DATA_DIR}"
148
+ run install -d -m 0700 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${DATA_DIR}/.ssh"
149
+ run install -d -m 0700 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${DATA_DIR}/locks"
150
+ run install -d -m 0700 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${DATA_DIR}/secrets"
151
+ if [[ ! -e "${DATA_DIR}/.ssh/authorized_keys" ]]; then
152
+ run install -m 0600 -o "${SERVICE_USER}" -g "${SERVICE_USER}" /dev/null "${DATA_DIR}/.ssh/authorized_keys"
153
+ fi
154
+
155
+ # 4. Immutable, root-owned application virtualenv.
156
+ run install -d -m 0755 -o root -g root "${APP_DIR}"
157
+ if [[ ! -x "${VENV}/bin/python" ]]; then
158
+ run python3 -m venv "${VENV}"
159
+ fi
160
+ run "${VENV}/bin/python" -m pip install --upgrade --no-input --disable-pip-version-check "${SOURCE}"
161
+ run chown -R root:root "${APP_DIR}"
162
+ run chmod -R go-w "${APP_DIR}"
163
+
164
+ # 5. Server configuration (never overwritten).
165
+ run install -d -m 0750 -o root -g "${SERVICE_USER}" "${CONF_DIR}"
166
+ if [[ ! -e "${CONF_DIR}/server.toml" ]]; then
167
+ run install -m 0640 -o root -g "${SERVICE_USER}" "${SCRIPT_DIR}/server.toml.example" "${CONF_DIR}/server.toml"
168
+ fi
169
+
170
+ # 6. Store (created once; existing stores are kept; back up before upgrades that migrate).
171
+ if [[ ! -e "${DATA_DIR}/store.sqlite3" ]]; then
172
+ run sudo -u "${SERVICE_USER}" env OFFGIT_SERVER_CONFIG="${CONF_DIR}/server.toml" \
173
+ "${VENV}/bin/offgit-server" init-store
174
+ else
175
+ echo "store exists: ${DATA_DIR}/store.sqlite3 (kept)"
176
+ if [[ "${DRY_RUN}" -eq 0 ]]; then
177
+ sudo -u "${SERVICE_USER}" env OFFGIT_SERVER_CONFIG="${CONF_DIR}/server.toml" \
178
+ "${VENV}/bin/offgit-server" verify || {
179
+ echo "warning: store verification failed or migration required; see docs/server-setup.md#upgrades" >&2; }
180
+ fi
181
+ fi
182
+
183
+ # 7. systemd units (backup only; RPC needs no daemon).
184
+ for unit in offgit-backup.service offgit-backup.timer offgit-backup-retention.service offgit-backup-retention.timer; do
185
+ run install -m 0644 -o root -g root "${SCRIPT_DIR}/${unit}" "${UNIT_DIR}/${unit}"
186
+ done
187
+ run systemctl daemon-reload
188
+ if [[ "${ENABLE_TIMER}" -eq 1 ]]; then
189
+ run systemctl enable --now offgit-backup.timer
190
+ fi
191
+
192
+ cat <<EOF
193
+
194
+ offgit-server installed: $( [[ "${DRY_RUN}" -eq 0 ]] && "${VENV}/bin/offgit-server" --version || echo "(dry run)")
195
+
196
+ Next steps (see docs/server-setup.md):
197
+ 1. For each client device, append ONE line to ${DATA_DIR}/.ssh/authorized_keys:
198
+ restrict,command="${VENV}/bin/offgit-server rpc" ssh-ed25519 AAAA... device-offgit
199
+ 2. Verify the SSH host key fingerprint on this machine's console:
200
+ ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
201
+ 3. On each client: offgit configure --host <tailscale-name> --user ${SERVICE_USER} --identity ~/.ssh/offgit_ed25519
202
+ 4. Optional cloud backups: docs/backup-and-recovery.md (rclone config, backup-init, then
203
+ sudo systemctl enable --now offgit-backup.timer)
204
+ EOF
205
+ }
206
+
207
+ main "$@"
@@ -0,0 +1,24 @@
1
+ [Unit]
2
+ Description=offgit cloud retention (restic forget; optional, opt-in)
3
+ Documentation=https://github.com/sjcsoftware/offgit/blob/main/docs/backup-and-recovery.md#retention
4
+ Wants=network-online.target
5
+ After=network-online.target offgit-backup.service
6
+
7
+ [Service]
8
+ Type=oneshot
9
+ User=offgit
10
+ Group=offgit
11
+ UMask=0077
12
+ Environment=HOME=/var/lib/offgit
13
+ Environment=OFFGIT_SERVER_CONFIG=/etc/offgit/server.toml
14
+ # Forget daily per policy; prune (slow, rewrites packs) only on Sundays; then check.
15
+ ExecStart=/opt/offgit/venv/bin/offgit-server backup-forget
16
+ ExecStart=/bin/sh -c 'if [ "$$(date +%%u)" = 7 ]; then exec /opt/offgit/venv/bin/offgit-server backup-forget --prune; fi'
17
+ ExecStart=/bin/sh -c 'if [ "$$(date +%%u)" = 7 ]; then exec /opt/offgit/venv/bin/offgit-server backup-check; fi'
18
+ TimeoutStartSec=4h
19
+ Nice=10
20
+ NoNewPrivileges=yes
21
+ PrivateTmp=yes
22
+ ProtectSystem=strict
23
+ ProtectHome=yes
24
+ ReadWritePaths=/var/lib/offgit
@@ -0,0 +1,10 @@
1
+ [Unit]
2
+ Description=Daily offgit cloud retention (opt-in; review 'backup-forget --dry-run' first)
3
+
4
+ [Timer]
5
+ OnCalendar=*-*-* 04:30:00
6
+ Persistent=true
7
+ RandomizedDelaySec=10min
8
+
9
+ [Install]
10
+ WantedBy=timers.target
@@ -0,0 +1,31 @@
1
+ [Unit]
2
+ Description=offgit encrypted off-site backup (restic snapshot of the authoritative store)
3
+ Documentation=https://github.com/sjcsoftware/offgit/blob/main/docs/backup-and-recovery.md
4
+ Wants=network-online.target
5
+ After=network-online.target
6
+ ConditionPathExists=/var/lib/offgit/store.sqlite3
7
+
8
+ [Service]
9
+ Type=oneshot
10
+ User=offgit
11
+ Group=offgit
12
+ UMask=0077
13
+ Environment=HOME=/var/lib/offgit
14
+ Environment=OFFGIT_SERVER_CONFIG=/etc/offgit/server.toml
15
+ ExecStart=/opt/offgit/venv/bin/offgit-server backup
16
+ TimeoutStartSec=2h
17
+ Nice=10
18
+ IOSchedulingClass=idle
19
+ # Sandboxing (verified with restic + rclone Google Drive; relax only if your setup needs it)
20
+ NoNewPrivileges=yes
21
+ PrivateTmp=yes
22
+ PrivateDevices=yes
23
+ ProtectSystem=strict
24
+ ProtectHome=yes
25
+ ReadWritePaths=/var/lib/offgit
26
+ ProtectKernelTunables=yes
27
+ ProtectKernelModules=yes
28
+ ProtectControlGroups=yes
29
+ RestrictSUIDSGID=yes
30
+ LockPersonality=yes
31
+ RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=Hourly offgit off-site backup
3
+ Documentation=https://github.com/sjcsoftware/offgit/blob/main/docs/backup-and-recovery.md
4
+
5
+ [Timer]
6
+ OnCalendar=hourly
7
+ Persistent=true
8
+ RandomizedDelaySec=3min
9
+
10
+ [Install]
11
+ WantedBy=timers.target
@@ -0,0 +1,24 @@
1
+ # /etc/offgit/server.toml (owner root:offgit, mode 0640)
2
+ # Every path here is chosen by the administrator; clients can never supply paths.
3
+
4
+ data_dir = "/var/lib/offgit" # must be a local filesystem (not NFS)
5
+ busy_timeout_ms = 5000
6
+ lock_timeout_seconds = 15
7
+
8
+ [limits] # defaults shown; hard ceilings apply (16 MiB / 40 MiB / 1024)
9
+ max_file_bytes = 8388608
10
+ max_project_bytes = 33554432
11
+ max_paths = 256
12
+
13
+ [backup]
14
+ restic_bin = "/usr/bin/restic"
15
+ repository = "rclone:gdrive:offgit/restic"
16
+ password_file = "/var/lib/offgit/secrets/restic-password"
17
+ rclone_config = "/var/lib/offgit/.config/rclone/rclone.conf"
18
+ host_tag = "offgit"
19
+ tag = "offgit"
20
+ timeout_seconds = 3600
21
+ keep_hourly = 24
22
+ keep_daily = 14
23
+ keep_weekly = 8
24
+ keep_monthly = 6
@@ -0,0 +1,7 @@
1
+ # /var/lib/offgit/.ssh/authorized_keys (owner offgit, mode 0600; directory 0700)
2
+ #
3
+ # One line per client device, each with its own dedicated key. 'restrict' disables
4
+ # PTY allocation, agent/port/X11 forwarding and ~/.ssh/rc; 'command=' forces the RPC
5
+ # server regardless of what the client asks to run.
6
+ restrict,command="/opt/offgit/venv/bin/offgit-server rpc" ssh-ed25519 AAAA...replace-me... workstation-offgit
7
+ restrict,command="/opt/offgit/venv/bin/offgit-server rpc" ssh-ed25519 AAAA...replace-me... macbook-offgit