askrobots / hello-server
Public
The smallest thing worth installing on a server of your own: a test for one-click installs
danq9
hello-server 2026.11v1: the smallest thing worth installing on your own server
7298f7b
8 hours, 48 minutes ago
History
install.sh · 1.4 KB · 44 lines
| 1 | #!/bin/sh |
| 2 | # Install hello-server on a fresh Ubuntu server, at one version, as a service on port 80. |
| 3 | # sh install.sh 2026.11v1 (a tag, a branch or a full commit id; default: the newest on main) |
| 4 | # Safe to run again: it moves the copy to the version asked for and restarts the service. |
| 5 | set -eu |
| 6 | |
| 7 | REF=${1:-main} |
| 8 | REPO=${REPO:-https://gitstable.com/git/askrobots/hello-server.git} |
| 9 | DIR=/opt/hello-server |
| 10 | |
| 11 | if [ ! -d "$DIR/.git" ]; then |
| 12 | git clone --quiet "$REPO" "$DIR" |
| 13 | fi |
| 14 | git -C "$DIR" fetch --quiet --tags origin |
| 15 | git -C "$DIR" checkout --quiet --detach "$REF" 2>/dev/null || git -C "$DIR" checkout --quiet --detach "origin/$REF" |
| 16 | |
| 17 | COMMIT=$(git -C "$DIR" rev-parse HEAD) |
| 18 | printf '{"version": "%s", "commit": "%s", "installed_at": "%s"}\n' \ |
| 19 | "$REF" "$COMMIT" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$DIR/installed.json" |
| 20 | |
| 21 | cat > /etc/systemd/system/hello-server.service <<UNIT |
| 22 | [Unit] |
| 23 | Description=hello-server (installed from $REPO at $REF) |
| 24 | After=network-online.target |
| 25 | Wants=network-online.target |
| 26 | |
| 27 | [Service] |
| 28 | ExecStart=/usr/bin/python3 $DIR/server.py |
| 29 | DynamicUser=yes |
| 30 | AmbientCapabilities=CAP_NET_BIND_SERVICE |
| 31 | NoNewPrivileges=yes |
| 32 | ProtectSystem=strict |
| 33 | ProtectHome=yes |
| 34 | PrivateTmp=yes |
| 35 | Restart=on-failure |
| 36 | |
| 37 | [Install] |
| 38 | WantedBy=multi-user.target |
| 39 | UNIT |
| 40 | |
| 41 | systemctl daemon-reload |
| 42 | systemctl enable --quiet hello-server |
| 43 | systemctl restart hello-server |
| 44 | echo "hello-server $REF ($COMMIT) is running on port 80" |