diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19fe3a9..0f97ae5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - run: shellcheck -s sh install.sh selfhostit scripts/pin-apps.sh scripts/release-apps.sh - - run: sh -n install.sh && sh -n selfhostit && sh -n scripts/pin-apps.sh && sh -n scripts/release-apps.sh + - run: shellcheck -s sh install.sh selfhostit scripts/pin-apps.sh scripts/release-apps.sh scripts/test-selfhostit.sh + - run: sh -n install.sh && sh -n selfhostit && sh -n scripts/pin-apps.sh && sh -n scripts/release-apps.sh && sh -n scripts/test-selfhostit.sh + # selfhostit info, list and remove against a made-up apps folder and a stub docker + - run: scripts/test-selfhostit.sh # Every file install.sh downloads must still have the SHA-256 it pins. pins: diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..e55e59a --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +docs.selfhostit.org diff --git a/README.md b/README.md index d3dcf33..86cdf55 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,39 @@ # Install selfhostit apps -selfhostit apps are small apps you run on your own hardware: a Raspberry Pi, a NAS or a +selfhostit apps are small apps you run on your own hardware: a [Raspberry Pi](words.md#raspberry-pi), a [NAS](words.md#nas) or a cheap server. Each one is a single container with its data in one folder, and they all -install the same way, with Docker. - -| App | What it does | Port | -|---|---|---| -| [Splitwiz](https://github.com/selfhostit/splitwiz) | Split shared costs with your partner or roommate | 8090 | -| [should-we](https://github.com/selfhostit/should-we) | Pick one option together, as a group | 8091 | -| [Flowy](https://github.com/selfhostit/flowy) | A private period and cycle tracker | 8092 | -| [Troye](https://github.com/selfhostit/troye) | A private calorie and weight tracker | 8093 | -| [Shoppa](https://github.com/selfhostit/shoppa) | A shared shopping list for your household | 8094 | -| [Calio](https://github.com/selfhostit/calio) | One calendar for your household: plans, pet sitting and trips | 8095 | - -The port is where the installer puts each app, so they can all run on one machine. If -another program already has it, the app gets the next free port, and keeps that one. +install the same way, with [Docker](words.md#docker). + +| App | What it does | +|---|---| +| [Splitwiz](https://github.com/selfhostit/splitwiz) | Split shared costs with your partner or roommate | +| [should-we](https://github.com/selfhostit/should-we) | Pick one option together, as a group | +| [Flowy](https://github.com/selfhostit/flowy) | A private period and cycle tracker | +| [Troye](https://github.com/selfhostit/troye) | A private calorie and weight tracker | +| [Shoppa](https://github.com/selfhostit/shoppa) | A shared shopping list for your household | +| [Calio](https://github.com/selfhostit/calio) | One calendar for your household: plans, pet sitting and trips | + +## Before you start + +- **About 30 minutes.** +- **A machine that stays on,** such as a Raspberry Pi, a mini PC, an old laptop or a NAS. + Not sure which? See [which machine?](machine.md) +- **A computer with a [terminal](words.md#terminal)** to type the install line, on that machine or connected to + it: [open a terminal and connect](terminal.md). +- **An account to sign in to [Tailscale](words.md#tailscale) with** (Google, Microsoft, Apple or GitHub), if you + want the apps on your phones. +- **The phones of everyone who will use the apps.** Each one gets the free Tailscale app: + [what that means for a phone](phones.md#tailscale-is-a-vpn-but-not-that-kind). + +You can stop at any step and nothing breaks: the apps keep working on the machine, and +running the installer again picks up where you left off. You can also +[remove everything](updates-and-backups.md#remove-an-app) later. ## Quick start -**1. Install the apps you want.** You need a little computer that runs Linux, such as an old +**1. Install the apps you want.** You need a little computer that runs [Linux](words.md#linux), such as an old laptop, a mini PC, a Raspberry Pi or a NAS (see [what you need](#what-you-need)), and a -terminal on it, or SSH. Then: +terminal on it, or [SSH](words.md#ssh) ([how to open one and connect](terminal.md)). Then: ```sh curl -fsSL https://github.com/selfhostit/docs/releases/latest/download/install.sh | sh @@ -42,22 +55,24 @@ settings and data are kept. Step by step: [a Pi or Linux](linux.md), a [Synology](synology.md) or [another NAS](other-nas.md). **2. Open an app and make your account.** At the end the installer lists each app's address -and a one-time setup code. Open the address, type the code and create your account: you -become the app's owner. [After you install](first-steps.md) says how to add the rest of your +and a one-time [setup code](words.md#setup-code). Open the address, type the code and create your account: you +become the app's [owner](words.md#owner-and-member). [After you install](first-steps.md) says how to add the rest of your household, and what to do when something doesn't open. **3. Open them from your phones and other computers.** The apps only answer on the machine they run on, so nothing else on your network or the internet can reach them by accident. To -use them from your phone or laptop, at home and away, they need an `https://` address, which -phones also need to install a web app and show its notifications. The installer can give all +use them from your phone or laptop, at home and away, they need an [`https://`](words.md#https) address, which +phones also need to install a [web app](words.md#web-app) and show its notifications. The installer can give all your apps one with [Tailscale](phones.md#tailscale-recommended), a free private network that only your own devices can reach: say yes when it asks. There is nothing to install on the server, because the installer runs Tailscale for you; you sign in once, and each phone gets the Tailscale app. Then [put the apps on your phones](phones.md#install-the-app-on-the-phone). +Tailscale is a [VPN](words.md#vpn), but not the kind that changes how your phone browses: +[here is what it does on a phone](phones.md#tailscale-is-a-vpn-but-not-that-kind). Three panels: say yes to Tailscale in the installer and open its sign-in link, install the Tailscale app on each phone with the same account, then open each app's https address and add it to the home screen. -Already have a domain? Use [a reverse proxy](phones.md#your-own-domain-with-a-reverse-proxy) +Already have a [domain](words.md#domain)? Use [a reverse proxy](phones.md#your-own-domain-with-a-reverse-proxy) instead of Tailscale. Prefer to read and check a script before you run it? Download it, verify it, read it, then @@ -80,7 +95,7 @@ and what you are trusting. The apps keep their data on your machine, in one folder each, with no selfhostit cloud and no analytics. They listen on `127.0.0.1` only and are reached through Tailscale or your own -reverse proxy, never a forwarded port. Containers run as a normal user with no Linux +reverse proxy, never a [forwarded port](words.md#port-forwarding). Containers run as a normal user with no Linux capabilities and a read-only filesystem, a new install asks for a one-time setup code, passwords are stored as bcrypt hashes, sign-ins are rate limited and the web apps send a Content Security Policy. Every change, and every week, is scanned with CodeQL, govulncheck, @@ -93,10 +108,14 @@ privately through the app's Security tab on GitHub or to kalfasyan@pm.me ## Guides -- [Raspberry Pi and Linux](linux.md): a Pi, a mini PC, an old laptop or a VPS. +- [Which machine?](machine.md): a NAS, a spare computer, a Raspberry Pi or mini PC, or a + rented server. +- [Open a terminal and connect](terminal.md): on Windows, Mac, Linux or a Chromebook. +- [Words you'll meet](words.md): SSH, Docker, Tailscale and the other words in these guides. +- [Raspberry Pi and Linux](linux.md): a Pi, a mini PC, an old laptop or a [VPS](words.md#vps). - [Synology NAS](synology.md): with Container Manager, from the DSM web interface. - [Other NAS and home servers](other-nas.md): QNAP, Unraid, TrueNAS SCALE, Portainer, - CasaOS and anything else that takes a Compose file. + CasaOS and anything else that takes a [Compose file](words.md#compose-file). - [Use them on your phones](phones.md): Tailscale, or a reverse proxy with your own domain. - [After you install](first-steps.md): your first account, adding your household, and what to do when an app doesn't open. @@ -105,6 +124,8 @@ privately through the app's Security tab on GitHub or to kalfasyan@pm.me ## What you need +Not sure what to run them on? [Which machine?](machine.md) compares the choices. + Anything that runs Docker containers for `linux/amd64`, `linux/arm64` or `linux/arm/v7`: x86 and ARM servers, a Raspberry Pi 3 or newer (64-bit Raspberry Pi OS is best), and NAS models with a Docker app. Each app needs about 128 to 512 MB of memory. NAS models without diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..1798a89 --- /dev/null +++ b/_config.yml @@ -0,0 +1,52 @@ +# Site settings for https://docs.selfhostit.org, built by GitHub Pages' own Jekyll. +# The .md files stay plain GitHub markdown: the plugins below give them titles, turn +# README.md into the home page and `x.md` links into pages, so no front matter is needed. +title: selfhostit docs +description: Install selfhostit apps on your own Raspberry Pi, NAS or server, step by step. +url: https://docs.selfhostit.org +lang: en + +markdown: kramdown +kramdown: + input: GFM + auto_ids: true + +plugins: + - jekyll-optional-front-matter + - jekyll-readme-index + - jekyll-titles-from-headings + - jekyll-relative-links + +relative_links: + enabled: true + collections: false + +readme_index: + enabled: true + +titles_from_headings: + enabled: true + strip_title: false + +defaults: + - scope: + path: "" + values: + layout: default + +exclude: + - install.sh + - selfhostit + - scripts/ + - security/ + - "*.sh" + - .github/ + - Makefile + - LICENSE + - Gemfile + - Gemfile.lock + - vendor/ + +# Don't also publish the raw .md files next to the pages. +optional_front_matter: + remove_originals: true diff --git a/_layouts/default.html b/_layouts/default.html new file mode 100644 index 0000000..f2e3618 --- /dev/null +++ b/_layouts/default.html @@ -0,0 +1,198 @@ + + + + + +{%- if page.url == "/" %} +{{ site.title }}: install apps on your own machine +{%- else %} +{{ page.title | default: site.title }} · {{ site.title }} +{%- endif %} + + + + + + + + + + + +
+
+ + Install guide + +
+
+ +{%- assign pages_nav = "/|Start,/machine.html|Which machine,/terminal.html|Terminal,/phones.html|Phones,/first-steps.html|After you install,/updates-and-backups.html|Updates and backups,/words.html|Words" | split: "," %} +
+ + +
+{{ content }} +
+
+ + + + + + diff --git a/assets/docs.css b/assets/docs.css new file mode 100644 index 0000000..ae5e18e --- /dev/null +++ b/assets/docs.css @@ -0,0 +1,166 @@ +/* The docs site's look, adapted from selfhostit.org's style.css: same tokens, light and dark. */ +:root { + --bg: #fafaf9; + --surface: #ffffff; + --band: #f1f0ee; + --text: #1c1917; + --muted: #57534e; + --line: #e7e5e4; + --brand: #4f46e5; + --brand-hover: #4338ca; + --on-brand: #ffffff; + --code-bg: #1c1917; + --code-text: #f5f5f4; + --inline-code-bg: #efedeb; + --note-bg: #eef0fd; + --radius: 14px; + color-scheme: light dark; +} + +@media (prefers-color-scheme: dark) { + :root { + --bg: #121110; + --surface: #1c1a19; + --band: #181716; + --text: #f5f5f4; + --muted: #a8a29e; + --line: #2e2b29; + --brand: #818cf8; + --brand-hover: #a5b4fc; + --on-brand: #121110; + --code-bg: #0a0a09; + --inline-code-bg: #262321; + --note-bg: #1d1d33; + } +} + +* { box-sizing: border-box; } + +html { -webkit-text-size-adjust: 100%; } + +body { + margin: 0; + background: var(--bg); + color: var(--text); + font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; + overflow-wrap: break-word; +} + +a { color: var(--brand); } +a:hover { color: var(--brand-hover); } + +.wrap { max-width: 1080px; margin: 0 auto; padding-inline: 16px; } + +.skip { position: absolute; left: -9999px; } +.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 6px 12px; border-radius: 8px; } + +/* header */ +.top { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 2; } +.top-row { display: flex; align-items: center; height: 60px; gap: 16px; } +.logo { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; } +.docs-home { color: var(--muted); text-decoration: none; font-size: .95rem; } +.docs-home:hover { color: var(--text); } +.menu-btn { + margin-left: auto; cursor: pointer; + background: var(--surface); color: var(--text); + border: 1px solid var(--line); border-radius: 10px; + padding: 7px 14px; font: inherit; font-size: .9rem; font-weight: 600; +} +.menu-btn:hover { border-color: var(--muted); } + +/* page list: folded on small screens, a sidebar on wide ones */ +.layout { display: block; } +.pages ul { list-style: none; margin: 0; padding: 8px 0 16px; display: grid; gap: 2px; } +.pages a { + display: block; padding: 8px 12px; border-radius: 8px; + color: var(--muted); text-decoration: none; font-size: .95rem; +} +.pages a:hover { color: var(--text); background: var(--band); } +.pages a[aria-current="page"] { color: var(--text); background: var(--band); font-weight: 600; } +.js .pages { display: none; border-bottom: 1px solid var(--line); } +.js .pages.open { display: block; } + +@media (min-width: 900px) { + .menu-btn { display: none; } + .layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 48px; } + .js .pages, .pages { display: block; border: 0; } + .pages ul { position: sticky; top: 76px; padding-top: 32px; } +} + +/* content */ +.content { min-width: 0; max-width: 760px; padding-block: 24px 48px; } +.content h1, .content h2, .content h3 { line-height: 1.2; margin: 1.6em 0 .5em; scroll-margin-top: 76px; } +.content h1 { font-size: clamp(2rem, 6vw, 2.8rem); letter-spacing: -.02em; margin-top: .4em; } +.content h2 { font-size: clamp(1.4rem, 4vw, 1.8rem); letter-spacing: -.01em; padding-top: .4em; border-top: 1px solid var(--line); } +.content h3 { font-size: 1.15rem; } +.content p, .content ul, .content ol { margin: 0 0 1em; } +.content li { margin: .25em 0; } +.content img { max-width: 100%; height: auto; } +.content hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; } + +/* code */ +code, pre { font: 14px/1.5 ui-monospace, Menlo, Consolas, monospace; } +:not(pre) > code { + background: var(--inline-code-bg); border-radius: 5px; padding: .1em .35em; + font-size: .88em; overflow-wrap: anywhere; +} +.content pre { + margin: 0; padding: 14px 20px; + background: var(--code-bg); color: var(--code-text); + border-radius: var(--radius); + overflow-x: auto; max-width: 100%; +} +.content pre code { background: none; padding: 0; white-space: pre; font-size: 14px; color: inherit; } +.content div.highlighter-rouge, .content > pre { margin: 0 0 1.2em; } +/* With the Copy button the box is a row, like the install line on selfhostit.org, so the + button never covers the command and only the code scrolls sideways. */ +.has-copy { display: flex; align-items: flex-start; background: var(--code-bg); border-radius: var(--radius); } +.has-copy pre, .has-copy .highlight { flex: 1; min-width: 0; margin: 0; background: none; } +.copy { + flex: none; margin: 10px 10px 10px 0; cursor: pointer; + background: transparent; color: var(--code-text); + border: 1px solid #57534e; border-radius: 8px; + padding: 4px 10px; font: inherit; font-size: .8rem; +} +.copy:hover, .copy:focus-visible { border-color: var(--code-text); } +/* Rouge adds colour classes; keep code plain and readable on the dark block. */ +.highlight .c, .highlight .c1, .highlight .cm { color: #a8a29e; } +.highlight .s, .highlight .s1, .highlight .s2 { color: #c7d2fe; } + +/* tables */ +.content table { + display: block; max-width: 100%; overflow-x: auto; + border-collapse: collapse; margin: 0 0 1.2em; font-size: .95rem; +} +.content th, .content td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; } +.content th { background: var(--band); } +.content td { background: var(--surface); } + +/* boxed notes, like "Tailscale is a VPN, but not that kind" */ +.content blockquote { + margin: 0 0 1.2em; padding: 14px 18px; + background: var(--note-bg); border-left: 4px solid var(--brand); + border-radius: 0 var(--radius) var(--radius) 0; +} +.content blockquote > :first-child { margin-top: 0; } +.content blockquote > :last-child { margin-bottom: 0; } + +/* glossary hint */ +a.word { text-decoration-style: dotted; text-underline-offset: 3px; } +.hint { + position: absolute; z-index: 5; + background: var(--surface); color: var(--text); + border: 1px solid var(--line); border-radius: 12px; + box-shadow: 0 8px 24px rgb(0 0 0 / .14); + padding: 12px 14px; font-size: .92rem; line-height: 1.5; +} +.hint strong { display: block; margin-bottom: 4px; } +.hint p { margin: 0 0 8px; color: var(--muted); } +.hint a { font-size: .88rem; } + +/* footer */ +.foot { + display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; + padding-block: 32px; color: var(--muted); font-size: .9rem; + border-top: 1px solid var(--line); +} diff --git a/first-steps.md b/first-steps.md index b3e5671..16fed5c 100644 --- a/first-steps.md +++ b/first-steps.md @@ -12,12 +12,19 @@ Here is what to do next, and what to try when something doesn't open. ## 1. Make your account -Open the app's address and type its setup code. The code is there so nobody else who finds a +Open the app's address and type its [setup code](words.md#setup-code). The code is there so nobody else who finds a fresh install can claim it, and it is only needed once. Then create your account: you become -the app's **owner**, who can add people and open the admin page (`/_/`) with the same email +the app's **[owner](words.md#owner-and-member)**, who can add people and open the [admin page](words.md#admin-page) (`/_/`) with the same email and password. -Lost the code? It is in the app's folder until the first account exists: +Lost the code? If you have the [selfhostit command](updates-and-backups.md#one-command-selfhostit-update), +it shows the code until the first account exists, with the app's addresses: + +```sh +selfhostit info flowy +``` + +Without it, the code is in the app's folder: ```sh sudo cat ~/selfhostit/flowy/pb_data/setup_code # your folder and app @@ -38,8 +45,8 @@ shares one list and one calendar. ## 3. Put it on your phones -On each phone, install the Tailscale app and sign in with your Tailscale account (for someone -else's phone, [share the machine](phones.md#tailscale-recommended) with their account). Then open the app's `https://` address, sign in and add it +On each phone, install the [Tailscale](words.md#tailscale) app and sign in with your Tailscale account (for someone +else's phone, [share the machine](phones.md#tailscale-recommended) with their account). Then open the app's [`https://`](words.md#https) address, sign in and add it to the home screen: [how, on Android and iPhone](phones.md#install-the-app-on-the-phone). Turn on notifications in the app's settings if it has them. @@ -47,7 +54,7 @@ Turn on notifications in the app's settings if it has them. - **Update:** run the installer again, or `selfhostit update all` with the [selfhostit command](updates-and-backups.md#one-command-selfhostit-update). -- **Backups:** each app keeps a backup of its database every night. Copy them somewhere +- **Backups:** each app keeps a [backup](words.md#backup) of its database every night. Copy them somewhere else too: [updates and backups](updates-and-backups.md). - **Check:** `selfhostit check` looks for common mistakes, such as an app open to your network. @@ -57,10 +64,10 @@ The apps you already have keep their settings and data. ## When something doesn't open -**`http://localhost:8092` doesn't open from my laptop or phone.** That address only works on +**`http://localhost:8092` doesn't open from my laptop or phone.** That [address](words.md#localhost) only works on the machine the apps run on: the apps answer nowhere else, on purpose. Run the installer -again and say yes to Tailscale, or follow [phones](phones.md) for a reverse proxy. To look -once from your laptop without either, forward the port over SSH: +again and say yes to Tailscale, or follow [phones](phones.md) for a [reverse proxy](words.md#reverse-proxy). To look +once from your laptop without either, forward the [port](words.md#port) over [SSH](words.md#ssh): `ssh -L 8092:127.0.0.1:8092 you@homeserver.local`, then open `http://localhost:8092` on the laptop. **The Tailscale address says "connection refused" or doesn't load.** Check that: @@ -76,7 +83,7 @@ an app to the next free port and lists the new address. To pick a port yourself, the app's `.env` and run the installer again. **"permission denied" talking to Docker.** Run the installer with `sudo` in front of `sh` -(`... | sudo sh`), or sign out and in again after Docker was installed, so your account is in +(`... | sudo sh`), or sign out and in again after [Docker](words.md#docker) was installed, so your account is in the `docker` group. **An app stopped or keeps restarting.** See what it says: `cd ~/selfhostit/flowy && docker compose logs --tail 50` diff --git a/linux.md b/linux.md index f62b61d..11652c5 100644 --- a/linux.md +++ b/linux.md @@ -1,21 +1,23 @@ # Raspberry Pi and Linux -This works on a Raspberry Pi 3 or newer, a mini PC, an old laptop that stays plugged in, -or a VPS: anything that runs Linux and stays on. +This works on a [Raspberry Pi](words.md#raspberry-pi) 3 or newer, a mini PC, an old laptop that stays plugged in, +or a [VPS](words.md#vps): anything that runs [Linux](words.md#linux) and stays on. Not sure which to use? See +[which machine?](machine.md) ## 1. Prepare the machine **Raspberry Pi:** flash **Raspberry Pi OS Lite (64-bit)** to a microSD card or, better, a USB SSD with [Raspberry Pi Imager](https://www.raspberrypi.com/software/). In its settings (the gear icon), set a hostname such as `homeserver`, a username and password, -your Wi-Fi if you don't use a cable, and turn on SSH. Start the Pi and, from another -computer, sign in: +your Wi-Fi if you don't use a cable, and turn on [SSH](words.md#ssh). Start the Pi and, from another +computer, sign in ([how to open a terminal and connect](terminal.md)): ```sh ssh you@homeserver.local ``` -**Any other Linux machine:** open a terminal on it, or sign in over SSH. +**Any other Linux machine:** open a [terminal](words.md#terminal) on it, or sign in over SSH +([how](terminal.md)). ## 2. Install the apps @@ -25,13 +27,13 @@ curl -fsSL https://github.com/selfhostit/docs/releases/latest/download/install.s The installer: -1. Installs Docker with the official script from get.docker.com if it is missing (it +1. Installs [Docker](words.md#docker) with the official script from get.docker.com if it is missing (it asks first, and may ask for your password). 2. Shows the apps and asks which ones you want. Type numbers or names, such as `1 3`. Each app runs on its own, so pick only the ones you want and add more later. 3. Asks for a folder, `~/selfhostit` by default, and puts each app in its own folder there with its database. -4. Asks whether to set up Tailscale, which gives every app an `https://` address that only +4. Asks whether to set up [Tailscale](words.md#tailscale), which gives every app an [`https://`](words.md#https) address that only your own devices can reach. Phones need that to install the apps and get notifications. 5. Runs each app's own installer, which may ask a few questions of its own. Pressing Enter keeps the suggested answer. @@ -40,7 +42,7 @@ The installer: When it is done it lists every app with its address: `https://selfhostit..ts.net:8090` with Tailscale, or `http://localhost:8090` on the machine itself without it. A new app also -gets a one-time setup code, listed under its address: its setup screen asks for it when you +gets a one-time [setup code](words.md#setup-code), listed under its address: its setup screen asks for it when you create the first account, so nobody else can set it up. Each app only listens on the machine and on your Tailscale network, so nothing is open to the rest of your network or the internet. Then [make your account and add your household](first-steps.md), @@ -57,7 +59,7 @@ curl -fsSL https://github.com/selfhostit/docs/releases/latest/download/install.s ## Good to know -- **Ports:** Splitwiz 8090, should-we 8091, Flowy 8092, Troye 8093, Shoppa 8094, +- **[Ports](words.md#port):** Splitwiz 8090, should-we 8091, Flowy 8092, Troye 8093, Shoppa 8094, Calio 8095. If another program already has one of these when an app is first installed, that app gets the next free port instead, and the list at the end shows it. An app keeps its port from then on. To change one, edit the port in that app's `.env` and run the installer again. diff --git a/machine.md b/machine.md new file mode 100644 index 0000000..60c2152 --- /dev/null +++ b/machine.md @@ -0,0 +1,70 @@ +# Which machine? + +The apps need one machine that stays on, day and night, so your phones can reach them +whenever you open an app: a [home server](words.md#home-server). It doesn't need to be +fast: each app uses about 128 to 512 MB of memory. Here are four good choices. + +## A NAS you already have + +**What it is:** a [NAS](words.md#nas), a box of disks for your home network, from Synology, +QNAP, UGREEN or others. + +**Cost:** nothing extra. + +**Good for:** households that already have one. It is on all the time anyway, and your +backups probably already cover it. + +**Watch out for:** it needs a Docker app, such as Container Manager on a Synology. Many +budget and older models don't have one, and then the apps won't run on it. Follow +[Synology NAS](synology.md) or [other NAS and home servers](other-nas.md). + +## A spare laptop or desktop + +**What it is:** an old computer you no longer use, with [Linux](words.md#linux) installed +on it. + +**Cost:** free. + +**Good for:** trying the apps without buying anything. + +**Watch out for:** it must stay on and plugged in. Set it never to sleep or hibernate, and +for a laptop, not to sleep when you close the lid. It uses more power than a Pi. Follow +[Raspberry Pi and Linux](linux.md). + +## Buy a Raspberry Pi or a mini PC + +**What it is:** a [Raspberry Pi](words.md#raspberry-pi) is a small, quiet computer the size +of a deck of cards. A mini PC is a small desktop computer, about the size of a sandwich. +Both use little power and can sit next to your router. + +**Cost:** prices vary by country and have gone up with memory prices, so take these as +rough guides. A Raspberry Pi 5 kit with a case, power supply and a small SSD costs from +about 150 to 200 euros. A used mini PC costs from about 100 euros, and a new one from about +200. + +**Good for:** most households without a NAS. It is a home server you set up once and then +forget. + +**Watch out for:** on a Pi, use a USB SSD rather than a microSD card. Cards wear out with a +database writing to them all day. Follow [Raspberry Pi and Linux](linux.md). + +## A rented server (a VPS) + +**What it is:** a [VPS](words.md#vps), a server you rent in a data centre and reach over the +internet. There is no hardware at home. + +**Cost:** from a few euros a month. + +**Good for:** people with no space or machine at home, and apps with nothing very private +in them, such as should-we. + +**Watch out for:** your data then lives in someone else's data centre, not in your home. +Keeping it at home is the main reason these apps exist. For health data, such as Flowy's +cycles or Troye's weight, think twice. [Tailscale](words.md#tailscale) works the same on a +VPS, so the apps still don't need to be on the internet. Follow +[Raspberry Pi and Linux](linux.md). + +## Our suggestion + +Use what you already have: a NAS with Docker or a spare computer. If you have neither, a +Raspberry Pi or a mini PC is the best fit for most households. diff --git a/other-nas.md b/other-nas.md index 251571e..3070e3c 100644 --- a/other-nas.md +++ b/other-nas.md @@ -1,17 +1,18 @@ # Other NAS and home servers -Every app is one Docker container with a Compose file, so anything that can run a Compose +Every app is one [Docker](words.md#docker) container with a [Compose file](words.md#compose-file), so anything that can run a Compose file can run them. -**With SSH** (QNAP, Unraid, TrueNAS SCALE, OpenMediaVault, Asustor, UGREEN, Proxmox in a -Debian VM or LXC): sign in and run the installer, with `sudo` if your user can't use Docker. +**With [SSH](words.md#ssh)** (QNAP, Unraid, TrueNAS SCALE, OpenMediaVault, Asustor, UGREEN, Proxmox in a +Debian VM or LXC): sign in ([how to open a terminal and connect](terminal.md)) and run the +installer, with `sudo` if your user can't use Docker. ```sh curl -fsSL https://github.com/selfhostit/docs/releases/latest/download/install.sh | sudo sh ``` On Unraid it suggests `/mnt/user/appdata`; anywhere else, pick a folder on your data pool -so the apps' databases are part of your NAS backups. +so the apps' databases are part of your [NAS](words.md#nas) backups. **Without SSH**, paste the app's Compose file into the NAS's Docker app: @@ -30,7 +31,7 @@ The Compose files are in each app's repository: [Troye](https://github.com/selfhostit/troye/blob/main/deploy/docker-compose.yml), [Shoppa](https://github.com/selfhostit/shoppa/blob/main/deploy/docker-compose.yml), [Calio](https://github.com/selfhostit/calio/blob/main/deploy/docker-compose.yml). -Replace `./pb_data` with a full path on your pool, give each app its own port (Splitwiz +Replace `./pb_data` with a full path on your pool, give each app its own [port](words.md#port) (Splitwiz 8090, should-we 8091, Flowy 8092, Troye 8093, Shoppa 8094, Calio 8095), and set your time zone in `TZ`. -Then follow [phones](phones.md) to reach them over HTTPS. +Then follow [phones](phones.md) to reach them over [HTTPS](words.md#https). diff --git a/phones.md b/phones.md index 7b8dcac..35c040b 100644 --- a/phones.md +++ b/phones.md @@ -1,13 +1,31 @@ # Use them on your phones -The apps install on a phone from the browser, like an app from a store, and send -notifications. Phones only allow that over **HTTPS**, so each app needs an `https://` +The apps [install on a phone](words.md#web-app) from the browser, like an app from a store, and send +notifications. Phones only allow that over **[HTTPS](words.md#https)**, so each app needs an `https://` address. Plain `http://192.168.x.x:8090` works in a browser at home, but not for those two. Pick one of these. ## Tailscale (recommended) +> ### Tailscale is a VPN, but not that kind +> +> [Tailscale](words.md#tailscale) is a [VPN](words.md#vpn), but here that only means a private link between your +> own devices. It doesn't hide or reroute your web browsing like the VPN apps sold for +> privacy or streaming: your phone uses the internet exactly as before. (Tailscale has an +> option called "exit node" that would send your browsing through home, but you don't need +> it.) +> +> - **It is free for personal use.** The free plan has room for a household: at the time of +> writing, up to six people with as many devices as they like. +> - **A phone runs one VPN at a time.** If you use a paid VPN app, the two take turns: turn +> the paid one off when you want to open the apps, and back on afterwards. +> - **Everyone who uses the apps needs the Tailscale app** on their phone, signed in to your +> account or to their own free one that you share the `selfhostit` machine with (see +> *Keep your tailnet private* below). +> - **Battery and data use are small.** It waits quietly in the background and uses data +> mostly when you open the apps. + [Tailscale](https://tailscale.com) is a free private network between your own devices. The apps get an `https://` address with a real certificate that only your devices can reach, at home and away, and you don't open anything in your router. @@ -20,7 +38,7 @@ Tailscale (run it again if you skipped it). It then: 2. The first time, shows a second link that turns on HTTPS for your Tailscale network: open it and allow it. 3. Lists every app's address, such as `https://selfhostit.your-tailnet.ts.net:8090` for - Splitwiz. The port is the same as the app's port on the machine. + Splitwiz. The [port](words.md#port) is the same as the app's port on the machine. Then, on each phone, install the Tailscale app, sign in with the same account, and [install the apps](#install-the-app-on-the-phone). The sign-in and the addresses stay after a @@ -71,10 +89,10 @@ so: For public addresses such as `https://splitwiz.example.com`: -- **A NAS:** its built-in reverse proxy with a free certificate. On a Synology, see the +- **A [NAS](words.md#nas):** its built-in [reverse proxy](words.md#reverse-proxy) with a free certificate. On a Synology, see the [Splitwiz Synology guide](https://github.com/selfhostit/splitwiz/blob/main/docs/synology.md). -- **A Linux machine:** [Caddy](https://caddyserver.com) gets certificates by itself. Point a - DNS record for each name at your home or server address, forward port 443 to the machine, +- **A [Linux](words.md#linux) machine:** [Caddy](https://caddyserver.com) gets certificates by itself. Point a + DNS record for each name at your home or server address, [forward port 443](words.md#port-forwarding) to the machine, and use a `Caddyfile` like this: ``` @@ -104,8 +122,8 @@ to 8095) in your router: that serves the app over plain `http://`, so passwords internet unencrypted, and it skips the proxy. Turn off **UPnP** in the router too, so no device on your network can open a port by itself. -**Keep the admin UI private.** Each app's admin UI (`/_/`) can see and change all of its -data, and its only protection is the owner's password and a limit of 10 tries a minute. On a +**Keep the admin UI private.** Each app's [admin UI](words.md#admin-page) (`/_/`) can see and change all of its +data, and its only protection is the [owner](words.md#owner-and-member)'s password and a limit of 10 tries a minute. On a public address, block it at the proxy as in the `Caddyfile` above, and open it through Tailscale or on the machine itself when you need it (for example `ssh -L 8092:127.0.0.1:8092 yourserver`, then `http://localhost:8092/_/`). A proxy that can't diff --git a/scripts/test-selfhostit.sh b/scripts/test-selfhostit.sh new file mode 100755 index 0000000..4d37b6a --- /dev/null +++ b/scripts/test-selfhostit.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# Runs selfhostit info, list and remove against a made-up apps folder, with a stub +# docker that logs its arguments and answers like a machine where flowy and troye +# run and the shared Tailscale node serves flowy's port. +set -eu + +here=$(cd "$(dirname "$0")/.." && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +root=$work/apps +log=$work/docker.log +mkdir -p "$work/bin" "$root" + +cat >"$work/bin/docker" <<'STUB' +#!/bin/sh +echo "${PWD##*/}: $*" >>"$DOCKER_LOG" +case "${PWD##*/} $*" in + *" info") exit 0 ;; + "flowy compose ps -q") echo cid-flowy ;; + "troye compose ps -q") printf 'cid-troye\ncid-troye-ts\n' ;; + "troye compose ps -q tailscale") echo cid-troye-ts ;; + *" compose ps -q"*) ;; + *" compose down"*) ;; + *"inspect -f {{.State.Running}} selfhostit-tailscale") echo true ;; + *" inspect -f "*" cid-troye") echo "8093 " ;; + *" inspect -f "*) echo ;; + *"exec selfhostit-tailscale "*"status --json --peers=false") + printf '{\n "Self": {\n "DNSName": "selfhostit.tail1234.ts.net.",\n' ;; + *"exec cid-troye-ts "*"status --json --peers=false") + printf '{\n "Self": {\n "DNSName": "troye.tail1234.ts.net.",\n' ;; + *"serve status --json") echo '{"TCP":{"8092":{"HTTPS":true}}}' ;; + *"serve --https="*" off") ;; + *) echo "stub docker: unexpected: $*" >&2; exit 1 ;; +esac +STUB +chmod +x "$work/bin/docker" + +for app in flowy troye should-we tailscale; do + mkdir -p "$root/$app" + echo 'services: {}' >"$root/$app/docker-compose.yml" +done +echo 'PORT=8092' >"$root/flowy/.env" +mkdir -p "$root/flowy/pb_data" +echo 'K7QM-4XRP' >"$root/flowy/pb_data/setup_code" +printf 'SHOULD_WE_PORT=8091\nTZ=UTC\n' >"$root/should-we/.env" + +export DOCKER_LOG="$log" SELFHOSTIT_DIR="$root" PATH="$work/bin:$PATH" +s() { sh "$here/selfhostit" "$@"; } +fail() { echo "FAIL: $*" >&2; exit 1; } +has() { printf '%s\n' "$1" | grep -qF -- "$2" || fail "expected '$2' in: +$1"; } +hasnt() { if printf '%s\n' "$1" | grep -qF -- "$2"; then fail "did not expect '$2' in: +$1"; fi; } + +# list and info skip the shared Tailscale folder +out=$(s list) +hasnt "$out" tailscale +has "$out" flowy + +out=$(s info) +has "$out" " folder: $root/flowy" +has "$out" " on this machine: http://localhost:8092" +has "$out" " from your devices: https://selfhostit.tail1234.ts.net:8092" +has "$out" " setup code: K7QM-4XRP" +has "$out" " on this machine: http://localhost:8093" +has "$out" " from your devices: https://troye.tail1234.ts.net" +hasnt "$out" "https://selfhostit.tail1234.ts.net:8093" +has "$out" " on this machine: not running" +hasnt "$out" "https://selfhostit.tail1234.ts.net:8091" +printf '%s\n' "$out" | grep -qx tailscale && fail "info shows the tailscale folder" + +out=$(s info flowy) +hasnt "$out" troye + +if out=$(s info nope 2>&1); then fail "info of an unknown app should fail"; fi +has "$out" "Apps found: flowy should-we troye" + +# remove refuses what is not one app +for args in tailscale ../flowy "flowy troye" nope; do + # shellcheck disable=SC2086 # several arguments on purpose + if s remove $args --yes >/dev/null 2>&1; then fail "remove $args should fail"; fi +done +if ! (: /dev/null; then + if s remove flowy >/dev/null 2>&1; then fail "remove without a terminal needs --yes"; fi +fi +[ -d "$root/flowy" ] || fail "a refused remove deleted flowy" +grep -q 'compose down' "$log" && fail "a refused remove ran compose down" + +# remove keeps the data, and takes the port off Tailscale +out=$(s remove flowy --yes) +has "$out" "Its data is still in $root/flowy" +grep -q '^flowy: compose down' "$log" || fail "remove flowy did not run compose down" +grep -q 'serve --https=8092 off' "$log" || fail "remove flowy did not turn off port 8092" +[ -f "$root/flowy/pb_data/setup_code" ] || fail "remove flowy deleted its data" + +# --delete-data deletes the folder, and only that +: >"$log" +s remove should-we --yes --delete-data >/dev/null +[ ! -e "$root/should-we" ] || fail "should-we is still there" +[ -d "$root/flowy" ] && [ -d "$root/tailscale" ] || fail "remove deleted another folder" +grep -q 'serve --https=.* off' "$log" && fail "should-we was not served, so nothing to turn off" + +echo "selfhostit tests passed" diff --git a/selfhostit b/selfhostit index b55a2d4..37a39bb 100755 --- a/selfhostit +++ b/selfhostit @@ -1,11 +1,14 @@ #!/bin/sh -# Updates self-hosted Docker Compose apps on a NAS with one command. +# Updates and looks after self-hosted Docker Compose apps on a NAS, one command each. # # selfhostit update splitwiz pull the newest image and recreate if needed # selfhostit update splitwiz flowy several apps in one go # selfhostit update all every app folder that has a compose file # selfhostit list apps found and the image each one runs # selfhostit check [app...] a security check of every app, or the ones named +# selfhostit info [app...] each app's folder, addresses and setup code +# selfhostit remove stop an app and take it off Tailscale; keeps its data +# selfhostit remove --delete-data the same, then delete its folder and data # # Each app is a folder holding a docker-compose.yml, in the same parent folder # the installer uses: /volume1/docker on a Synology, ~/selfhostit elsewhere. @@ -23,7 +26,7 @@ DOCKER=$(command -v docker 2>/dev/null || true) if [ "$(id -u)" -eq 0 ] || "$DOCKER" info >/dev/null 2>&1; then SUDO=; else SUDO=sudo; fi usage() { - sed -n '3,8s/^# \{0,1\}//p' "$0" + sed -n '3,11s/^# \{0,1\}//p' "$0" exit "${1:-0}" } @@ -34,13 +37,27 @@ compose_file() { return 1 } +# The app folders. The shared Tailscale node's folder is not an app. apps() { for d in "$ROOT"/*/; do d=${d%/} + [ "${d##*/}" != tailscale ] || continue compose_file "$d" >/dev/null && basename "$d" done } +# is_app NAME: true when NAME is one of the app folders +is_app() { + case $1 in ''|*/*|.|..|tailscale) return 1 ;; esac + apps | grep -qxF -- "$1" +} + +no_such_app() { + echo "selfhostit: there is no app named '$1' in $ROOT" >&2 + echo "Apps found: $(apps | tr '\n' ' ')" >&2 + exit 1 +} + dc() { $SUDO "$DOCKER" compose "$@"; } # one line per container: " " @@ -190,6 +207,131 @@ check_one() { echo } +# --- selfhostit info and remove ----------------------------------------------- + +# env_port DIR: the port in the app's .env (PORT, SPLITWIZ_PORT or SHOULD_WE_PORT, +# the names install.sh uses), or nothing +env_port() { + [ -f "$1/.env" ] || return 0 + { cat "$1/.env" 2>/dev/null || $SUDO cat "$1/.env"; } | + grep -E '^(PORT|SPLITWIZ_PORT|SHOULD_WE_PORT)=' | head -n 1 | + cut -d= -f2- | tr -d "\"' \r" +} + +# published_port: the first host port the app's running containers publish +# (run in the app's folder) +published_port() { + for id in $(dc ps -q 2>/dev/null); do + # shellcheck disable=SC2016 # a Go template, not shell + $SUDO "$DOCKER" inspect -f '{{range $p, $b := .NetworkSettings.Ports}}{{range $b}}{{.HostPort}} {{end}}{{end}}' "$id" 2>/dev/null + done | tr ' ' '\n' | grep -E '^[0-9]+$' | head -n 1 +} + +# The shared Tailscale node install.sh sets up, in $ROOT/tailscale +ts() { $SUDO "$DOCKER" exec selfhostit-tailscale tailscale --socket=/tmp/tailscaled.sock "$@"; } +ts_running() { + [ "$($SUDO "$DOCKER" inspect -f '{{.State.Running}}' selfhostit-tailscale 2>/dev/null)" = true ] +} +# dns_name: the node's name from `tailscale status --json` on stdin, without the last dot +dns_name() { + sed -n 's/^ *"DNSName": *"\([^"]*\)".*/\1/p' | head -n 1 | sed 's/\.$//' +} +# ts_serves PORT: true when the shared node serves PORT +ts_serves() { ts serve status --json 2>/dev/null | grep -q "\"$1\""; } + +info_one() { + app=$1 + dir=$ROOT/$app + cd "$dir" || return 1 + port=$(env_port "$dir") + running=$(dc ps -q 2>/dev/null || true) + [ -n "$port" ] || [ -z "$running" ] || port=$(published_port) + + echo "$app" + printf ' %-19s %s\n' "folder:" "$dir" + if [ -z "$running" ]; then + printf ' %-19s %s\n' "on this machine:" "not running (start it with: selfhostit update $app)" + elif [ -n "$port" ]; then + printf ' %-19s %s\n' "on this machine:" "http://localhost:$port" + else + printf ' %-19s %s\n' "on this machine:" "running, but its port is not known" + fi + if [ -n "$ts_name" ] && [ -n "$port" ] && ts_serves "$port"; then + printf ' %-19s %s\n' "from your devices:" "https://$ts_name:$port" + fi + # an app installed with its own Tailscale sidecar has its own name + side=$(dc ps -q tailscale 2>/dev/null | head -n 1) + if [ -n "$side" ]; then + name=$($SUDO "$DOCKER" exec "$side" tailscale --socket=/tmp/tailscaled.sock status --json --peers=false 2>/dev/null | dns_name) + [ -z "$name" ] || printf ' %-19s %s\n' "from your devices:" "https://$name" + fi + # there until the first account is made + code=$($SUDO cat "$dir/pb_data/setup_code" 2>/dev/null || true) + [ -z "$code" ] || printf ' %-19s %s\n' "setup code:" "$code" + echo +} + +# true when there is a terminal to ask questions on +interactive() { (: /dev/null; } + +remove_app() { + app='' delete='' yes='' + for a in "$@"; do + case $a in + --delete-data) delete=1 ;; + -y|--yes) yes=1 ;; + -*) echo "selfhostit: unknown option '$a'" >&2; exit 2 ;; + *) [ -z "$app" ] || { echo "selfhostit: remove takes one app at a time" >&2; exit 2; } + app=$a ;; + esac + done + [ -n "$app" ] || { echo "usage: selfhostit remove [--delete-data] [--yes]" >&2; exit 2; } + case $app in + tailscale) echo "selfhostit: tailscale is the shared Tailscale node, not an app" >&2; exit 1 ;; + */*|.|..) echo "selfhostit: '$app' is not an app name" >&2; exit 1 ;; + esac + is_app "$app" || no_such_app "$app" + dir=$ROOT/$app + case $dir in "$ROOT"/?*) ;; *) echo "selfhostit: refusing to touch $dir" >&2; exit 1 ;; esac + + if [ -z "$yes" ]; then + interactive || { echo "selfhostit: no terminal to ask on; add --yes to remove $app anyway" >&2; exit 1; } + if [ -n "$delete" ]; then + printf 'Remove %s and delete all its data in %s? This cannot be undone.\nType the app name to confirm: ' "$app" "$dir" >/dev/tty + read -r answer /dev/tty + read -r answer &2; exit 1; } + + # the inverse of install.sh's `tailscale serve --bg --https=PORT http://127.0.0.1:PORT` + if [ -n "$port" ] && ts_running && ts_serves "$port"; then + echo "Taking port $port off Tailscale" + ts serve --https="$port" off >/dev/null || echo "selfhostit: could not turn off port $port on Tailscale" >&2 + fi + cd "$ROOT" + + if [ -n "$delete" ]; then + echo "Deleting $dir" + $SUDO rm -rf -- "$dir" + echo "$app is removed, with its data." + else + echo "$app is stopped and removed. Its data is still in $dir." + echo "To start it again: selfhostit update $app" + echo "To delete its data too: selfhostit remove $app --delete-data" + fi +} + cmd=${1:-} [ $# -gt 0 ] && shift case $cmd in @@ -223,6 +365,17 @@ case $cmd in if [ "$warned" = 1 ]; then echo "Some checks need a look: see WARN above."; exit 1; fi echo "All checks passed." ;; + info) + for app in "$@"; do is_app "$app" || no_such_app "$app"; done + # shellcheck disable=SC2046 # app folder names have no spaces + [ $# -gt 0 ] || set -- $(apps) + [ $# -gt 0 ] || { echo "No apps in $ROOT yet."; exit 0; } + [ -z "$SUDO" ] || sudo true + ts_name= + if ts_running; then ts_name=$(ts status --json --peers=false 2>/dev/null | dns_name); fi + for app in "$@"; do ( info_one "$app" ); done + ;; + remove|rm) remove_app "$@" ;; ''|-h|--help|help) usage ;; *) echo "selfhostit: unknown command '$cmd'" >&2; usage 2 >&2 ;; esac diff --git a/synology.md b/synology.md index 9a4b96b..d7982d5 100644 --- a/synology.md +++ b/synology.md @@ -9,7 +9,8 @@ shared folder. 1. Install **Container Manager** from Package Center. It creates the `docker` shared folder. 2. Control Panel > Terminal & SNMP: tick **Enable SSH service**. 3. From your computer, sign in with your DSM account: `ssh you@your-nas.local` - (on Windows, in PowerShell). + (on Windows, in PowerShell). New to this? See + [open a terminal and connect](terminal.md). ## 2. Install the apps @@ -21,8 +22,8 @@ It asks for your DSM password, which apps you want, and a folder (`/volume1/dock default, one folder per app). The apps show up in Container Manager under **Project**, where you can see their logs, stop and start them. -Turn SSH off again afterwards (Control Panel > Terminal & SNMP); you only need it to -update, and an SSH login with your DSM password is the easiest way into the NAS. +Turn [SSH](words.md#ssh) off again afterwards (Control Panel > Terminal & SNMP); you only need it to +update, and an SSH login with your DSM password is the easiest way into the [NAS](words.md#nas). **Keep the `docker` folder private.** It holds every app's database, backups and setup code, and anyone who can open it over the network can copy them. In Control Panel > @@ -36,7 +37,7 @@ Container Manager > Project > Create, once per app: - Name: the app's name, such as `splitwiz` - Path: create `/volume1/docker/` and a `pb_data` folder inside it in File Station first -- Source: **Create docker-compose.yml**, and paste the app's compose file: +- Source: **Create docker-compose.yml**, and paste the app's [compose file](words.md#compose-file): [Splitwiz](https://github.com/selfhostit/splitwiz/blob/main/docker-compose.yml), [should-we](https://github.com/selfhostit/should-we/blob/main/docker-compose.yml), [Flowy](https://github.com/selfhostit/flowy/blob/main/deploy/docker-compose.yml), @@ -44,7 +45,7 @@ Container Manager > Project > Create, once per app: [Shoppa](https://github.com/selfhostit/shoppa/blob/main/deploy/docker-compose.yml), [Calio](https://github.com/selfhostit/calio/blob/main/deploy/docker-compose.yml) -In the pasted file, set the port so two apps don't share one (the number after `:-` in the +In the pasted file, set the [port](words.md#port) so two apps don't share one (the number after `:-` in the `ports:` line: Splitwiz 8090, should-we 8091, Flowy 8092, Troye 8093, Shoppa 8094, Calio 8095), and your time zone in the `TZ` line. For Flowy, Troye, Shoppa and Calio, also set `PUID` and `PGID` to your DSM user's ids (run `id` over SSH, or leave them at 1000 and give that user the folder). @@ -53,7 +54,7 @@ In the pasted file, set the port so two apps don't share one (the number after ` Two ways, both described in [phones](phones.md): -- **At home and away, without opening your router:** Tailscale. Don't use the Tailscale +- **At home and away, without opening your router:** [Tailscale](words.md#tailscale). Don't use the Tailscale package in Package Center: Tailscale no longer supports it and it lags behind their releases. Follow [Tailscale's Synology guide](https://tailscale.com/kb/1131/synology) instead: download the package for your NAS's architecture from @@ -64,12 +65,12 @@ Two ways, both described in [phones](phones.md): should reach your other Tailscale devices (for example to back up to them), also follow [Enable outbound connections](https://tailscale.com/kb/1131/synology#enable-outbound-connections) and run it again after each update. -- **On a public address:** DSM's own reverse proxy with a free `*.synology.me` address and +- **On a public address:** DSM's own [reverse proxy](words.md#reverse-proxy) with a free `*.synology.me` address and Let's Encrypt certificate. The [Splitwiz Synology guide](https://github.com/selfhostit/splitwiz/blob/main/docs/synology.md) walks through it step by step; repeat the reverse proxy step for each app with its own name, such as `flowy..synology.me` to port 8092. -Either way, don't forward the apps' ports (8090 to 8095) or DSM's own ports (5000, 5001) in +Either way, don't [forward the apps' ports](words.md#port-forwarding) (8090 to 8095) or DSM's own ports (5000, 5001) in your router, and leave DSM's **QuickConnect** off unless you use it: they put the apps or DSM's sign-in page on the internet, where bots try passwords all day. With a public address, forward only 443 to DSM's reverse proxy. diff --git a/terminal.md b/terminal.md new file mode 100644 index 0000000..f00aee9 --- /dev/null +++ b/terminal.md @@ -0,0 +1,71 @@ +# Open a terminal and connect + +The installer runs in a [terminal](words.md#terminal): a window where you type a command +and press Enter. If the apps go on another machine, such as a Raspberry Pi or a NAS, you +use [SSH](words.md#ssh) from your own computer to type in that machine's terminal. This page +shows how, step by step. + +## Open a terminal + +**Windows 10 or 11:** open the Start menu, type `Terminal` (or `PowerShell` on older +Windows 10) and open it. + +**Mac:** open **Terminal** from Applications > Utilities, or press Cmd+Space and type +`Terminal`. + +**Linux:** open **Terminal** from your apps menu. On many desktops, Ctrl+Alt+T opens it too. + +**Chromebook:** open Settings, search for `Linux` and turn on the **Linux development +environment**. Then open the **Terminal** app. + +**Working on the machine itself,** with a keyboard and screen plugged into it: open its +own terminal and skip the next step. Everything you type runs right there. + +## Connect to the machine + +In the terminal, type `ssh`, your username on that machine, `@`, and the machine's name, +then press Enter. For a Raspberry Pi set up as in [the Pi guide](linux.md), that is: + +```sh +ssh you@homeserver.local +``` + +Replace `you` with the username you chose, and `homeserver` with the machine's name. + +- **The first time,** it asks "Are you sure you want to continue connecting + (yes/no/[fingerprint])?". Type `yes` and press Enter. This only happens once per machine. +- **Then it asks for the password.** Nothing shows while you type it, not even dots. That's + normal: type it and press Enter. +- **You are in** when the line changes to something like `you@homeserver:~ $`. What you type + now runs on that machine. + +## Paste a command + +Copying the install line is easier than typing it. To paste it into the terminal: + +- **Windows, Linux and Chromebook:** Ctrl+Shift+V, or right-click in the window. +- **Mac:** Cmd+V. + +Then press Enter to run it. + +## When the machine's name doesn't answer + +If `ssh` says "Could not resolve hostname" or nothing happens, your network may not know +the name. Use the machine's [IP address](words.md#ip-address) instead: + +1. Open your router's page in a browser. It is often at `http://192.168.1.1` or + `http://192.168.0.1`, and the address and password are usually on a sticker on the + router. Many routers also have a phone app. +2. Find its list of connected devices, and look for your machine's name. +3. Connect with the number it shows, for example: + + ```sh + ssh you@192.168.1.20 + ``` + +On a Synology, the **Synology Assistant** app (from Synology's download page) or +`find.synology.com` also shows the NAS's address. + +## Leave + +Type `exit` and press Enter. The apps keep running on the machine after you leave. diff --git a/updates-and-backups.md b/updates-and-backups.md index e756d4d..8d97172 100644 --- a/updates-and-backups.md +++ b/updates-and-backups.md @@ -19,7 +19,7 @@ docker compose pull && docker compose up -d ### One command: `selfhostit update` -To update apps over SSH without the installer, install the `selfhostit` command once: +To update apps over [SSH](words.md#ssh) without the installer, install the `selfhostit` command once: ```sh mkdir -p ~/bin @@ -39,16 +39,24 @@ selfhostit update splitwiz # one app selfhostit update splitwiz flowy # several selfhostit update all # every app selfhostit list # the apps it finds and the image each one runs +selfhostit info # every app's folder, addresses and setup code +selfhostit info flowy # the same for one app +selfhostit remove flowy # stop and remove an app, keeping its data ``` -For each app it shows the image its compose file points at, pulls it, and says whether the +For each app it shows the image its [compose file](words.md#compose-file) points at, pulls it, and says whether the container was already up to date, recreated with a new image, or recreated because its settings changed. It finds apps in the folder the installer uses (`/volume1/docker` on a Synology, `~/selfhostit` elsewhere), and works for any folder there with a `docker-compose.yml`. Keep them somewhere else? Add `export SELFHOSTIT_DIR=/path/to/apps` to -`~/.profile`. It uses `sudo` when your user can't reach Docker directly, and asks for the +`~/.profile`. It uses `sudo` when your user can't reach [Docker](words.md#docker) directly, and asks for the password once. Run the `curl` line again to get a newer version of the command. +`selfhostit info` shows, for each app, its folder, its address on the machine +([`http://localhost:8092`](words.md#localhost) for Flowy), its [Tailscale](words.md#tailscale) address if the installer set one up, and +its [setup code](words.md#setup-code) while nobody has made the first account yet. `selfhostit remove` is in +[remove an app](#remove-an-app) below. + ### Check your install: `selfhostit check` ```sh @@ -60,7 +68,7 @@ For each running container it says whether it is reachable only from this machin to your network, runs as a normal user or as root, drops Linux capabilities, can gain new privileges, has a read-only filesystem, has the Docker socket, and runs the newest image of its tag (it asks ghcr.io, without pulling anything). For each app it also says whether there -is a nightly backup from the last two days. It changes nothing. Anything to look at is +is a nightly [backup](words.md#backup) from the last two days. It changes nothing. Anything to look at is marked `WARN`, and then it exits with status 1, so you can run it from a scheduled task. On a Synology without SSH: Container Manager > Image, select the app's image and choose @@ -76,9 +84,9 @@ Tailscale key, which lets whoever has it join your tailnet as that machine. - **Synology:** add the apps' `pb_data` folders to a **Hyper Backup** task with **client-side encryption** turned on. -- **Other NAS:** include the apps' `pb_data` folders in its backup or snapshot schedule, +- **Other [NAS](words.md#nas):** include the apps' `pb_data` folders in its backup or snapshot schedule, encrypted if it goes off the NAS. -- **Linux or a Pi:** copy the `pb_data` folders to another disk or computer from time to +- **[Linux](words.md#linux) or a Pi:** copy the `pb_data` folders to another disk or computer from time to time, for example with `rsync -a --exclude tailscale ~/selfhostit/ otherhost:backups/selfhostit/`, to an encrypted disk. Or make one encrypted file with [age](https://age-encryption.org), which asks for a passphrase: @@ -97,8 +105,8 @@ apps' folders and wipe the disk first. Try this once now, while nothing is wrong, so you know your backups work. -**From a nightly backup, in the admin UI:** open the app's `/_/` (through Tailscale or on -the machine itself), sign in with the owner's email and password, and go to **Settings > +**From a nightly backup, in the admin UI:** open the app's [admin page](words.md#admin-page), `/_/` (through Tailscale or on +the machine itself), sign in with the [owner](words.md#owner-and-member)'s email and password, and go to **Settings > Backups**. Pick a backup and choose **Restore**. The app restarts with that data. **By hand,** from a nightly backup or a copy of your own. For example, for Flowy: @@ -123,6 +131,65 @@ Backup. Then open the app and check that your newest entries are there. Once they are, delete `pb_data.old`. -## Removing an app +## Remove an app + +**With the `selfhostit` command** ([install it](#one-command-selfhostit-update)): + +```sh +selfhostit remove flowy +``` + +It asks you to confirm, stops and removes the app's containers, turns off its Tailscale +address, and keeps its data folder, telling you where it is. To delete the data too, add +`--delete-data`: it then asks you to type the app's name before it deletes the folder. + +**By hand,** for example for Flowy: + +1. Stop and remove its containers: + + ```sh + cd ~/selfhostit/flowy && docker compose down + ``` + +2. Turn off its Tailscale address, if the installer set one up. The installer serves each + app on its own [port](words.md#port) through the `selfhostit-tailscale` container; give the app's port + (8092 for Flowy, or the one in its `.env`): + + ```sh + docker exec selfhostit-tailscale tailscale --socket=/tmp/tailscaled.sock serve --https=8092 off + ``` + +3. The data stays in the app's folder until you delete it. Want to keep a copy? Make a + [backup](#backups) first. Then: + + ```sh + sudo rm -rf ~/selfhostit/flowy + ``` + +Put `sudo` in front of `docker` if your user can't use Docker. To install the app again +later, run the installer and pick it: an app whose folder you kept comes back with its data. + +**On a Synology without SSH:** Container Manager > **Project**, select the app, then +Action > **Stop** and Action > **Delete**. Then delete its folder in `docker` with File +Station if you don't want the data. + +### Remove everything + +1. Remove every app as above, with `selfhostit remove` or by hand. +2. Stop the Tailscale container and delete the apps' folder, which also holds the + machine's Tailscale key: + + ```sh + cd ~/selfhostit/tailscale && docker compose down + sudo rm -rf ~/selfhostit + ``` + + On a Synology, the folder is the `docker` shared folder: delete only the apps' folders + and `tailscale` in it, in File Station, since other containers may keep data there too. + +3. On Tailscale's [machines page](https://login.tailscale.com/admin/machines), find + `selfhostit` and choose **Remove**. +4. If you installed the `selfhostit` command, delete it: `rm ~/bin/selfhostit`. -In its folder, `docker compose down`, then delete the folder. That deletes its data too. +Docker stays on the machine. Other programs may use it, so remove it only if you know +nothing else does. diff --git a/words.md b/words.md new file mode 100644 index 0000000..602e0df --- /dev/null +++ b/words.md @@ -0,0 +1,185 @@ +# Words you'll meet + +You don't need to learn any of this first; each page links here when a word comes up. + +## Terminal + +A window where you type commands instead of clicking. You type a line, press Enter, and +the computer answers in text. It is like texting the computer instead of tapping around +in its menus. + +Where you meet it: [open a terminal and connect](terminal.md). + +## SSH + +SSH lets you use the terminal of another machine from your own computer, over your +network. It is like a phone line straight into the machine's terminal: what you type runs +there, not on your computer. + +Where you meet it: [open a terminal and connect](terminal.md). + +## Linux + +A free operating system, like Windows or macOS. Most servers, NAS boxes and every +Raspberry Pi run it. You don't need to know it well: the installer does the Linux parts. + +Where you meet it: [Raspberry Pi and Linux](linux.md). + +## Docker + +Docker runs each app in a container: a sealed box with the app and everything it needs, +kept apart from the rest of the machine. It is like a shipping container: the same box +fits on any ship, so the app runs the same on a Pi, a laptop or a NAS. + +Where you meet it: [what you need](README.md#what-you-need). + +## Compose file + +A short text file, `docker-compose.yml`, that tells Docker how to run an app: which +container, which port and which folder holds its data. It is like a recipe card that +Docker follows every time it starts the app. + +Where you meet it: [other NAS and home servers](other-nas.md). + +## NAS + +A NAS (network attached storage) is a small box full of disks that keeps files for your +home network, such as one from Synology or QNAP. Many can also run apps. It is like a +shared cupboard that everyone at home can reach. + +Where you meet it: [which machine?](machine.md#a-nas-you-already-have) + +## Home server + +Any computer at home that stays on to run apps for your household: a Raspberry Pi, a mini +PC, an old laptop or a NAS. It is like a fridge: it runs all the time in a corner and you +rarely think about it. + +Where you meet it: [which machine?](machine.md) + +## Raspberry Pi + +A cheap, credit-card-sized computer that runs Linux and uses very little power. It is like +a phone's insides without the screen, made to sit in a corner and work all day. + +Where you meet it: [Raspberry Pi and Linux](linux.md). + +## VPS + +A VPS (virtual private server) is a server you rent in a data centre, by the month. You +reach it over the internet and keep no hardware at home. It is like renting a storage unit +instead of using your own attic: handy, but your things are in someone else's building. + +Where you meet it: [which machine?](machine.md#a-rented-server-a-vps) + +## IP address + +The number that tells devices on a network where to find each other, such as +`192.168.1.20`. It is like a street address for a device. At home, your router hands +these out. + +Where you meet it: [when the machine's name doesn't answer](terminal.md#when-the-machines-name-doesnt-answer). + +## localhost + +A name that always means "this same machine". `http://localhost:8092` opens Flowy only in +a browser on the machine the apps run on. It is like saying "here" instead of an address: +it means something different on every device. + +Where you meet it: [when something doesn't open](first-steps.md#when-something-doesnt-open). + +## Port + +A number that picks one program on a machine, such as `8092` for Flowy. If the IP address +is a building's address, the port is the flat number: same building, different door. + +Where you meet it: [good to know](linux.md#good-to-know). + +## HTTPS + +The secure way a browser talks to a website, with addresses that start with `https://`. +What you send is encrypted on the way. It is like a sealed envelope instead of a postcard. +Phones only install web apps and show their notifications over HTTPS. + +Where you meet it: [use them on your phones](phones.md). + +## Domain + +A name you own on the internet, such as `example.com`, that you can point at your own +machine. It is like a name on a letterbox: people find you by the name, not the number. +You don't need one: Tailscale gives the apps their addresses. + +Where you meet it: [your own domain with a reverse proxy](phones.md#your-own-domain-with-a-reverse-proxy). + +## Tailscale + +Tailscale is a free service that links your own devices into one private network, called +your tailnet, wherever they are. Only devices signed in to your account (or that you +share with) can reach it. It is like a private hallway between your phone and your home +server. + +Where you meet it: [Tailscale is a VPN, but not that kind](phones.md#tailscale-is-a-vpn-but-not-that-kind). + +## VPN + +A VPN (virtual private network) is a private, encrypted link over the internet. Some VPN +apps hide your browsing; Tailscale is the other kind and only links your own devices. It +is like a private tunnel under a public road. + +Where you meet it: [Tailscale is a VPN, but not that kind](phones.md#tailscale-is-a-vpn-but-not-that-kind). + +## Reverse proxy + +A program that takes visits to your domain from the internet and passes each one to the +right app, adding HTTPS on the way. It is like a receptionist who answers the front door +and walks each visitor to the right room. + +Where you meet it: [your own domain with a reverse proxy](phones.md#your-own-domain-with-a-reverse-proxy). + +## Port forwarding + +A router setting that lets the internet reach one port on a machine at home. It is like +giving a stranger a key to one door of your house. The apps don't need it with Tailscale, +and you should never forward the apps' own ports. + +Where you meet it: [can I put the apps on the internet?](security.md#can-i-put-the-apps-on-the-internet) + +## Admin page + +Each app's control room, at its address with `/_/` at the end. The owner signs in there +to add people and see or change all the data. It is like the staff-only room behind a +shop counter. + +Where you meet it: [add your household](first-steps.md#2-add-your-household). + +## Web app + +A web app is a website that you can install on your phone's home screen, where it opens +and sends notifications like an app from a store. It is like a shortcut that grew into a +full app. Installing one needs an `https://` address. + +Where you meet it: [install the app on the phone](phones.md#install-the-app-on-the-phone). + +## Setup code + +A one-time code the installer shows for each new app. You type it when you make the first +account, so nobody else who finds a fresh install can claim it. It is like the code on a +new safe that you replace with your own. + +Where you meet it: [make your account](first-steps.md#1-make-your-account). + +## Owner and member + +The first account in an app is its owner, who can add people and open the admin page. +Everyone the owner adds is a member, who just uses the app. It is like the person who +holds the lease and the people who live there with them. + +Where you meet it: [add your household](first-steps.md#2-add-your-household). + +## Backup + +A copy of your data kept somewhere else, so you can get it back if a disk breaks or +something goes wrong. It is like a spare house key at a friend's place: useful only if it +isn't kept in the same house. + +Where you meet it: [updates and backups](updates-and-backups.md#backups).