forked from defunkt/toes
148 lines
5.1 KiB
Bash
Executable File
148 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
##
|
|
# toes installer
|
|
# Usage: curl -fsSL https://toes.dev/install | sh
|
|
#
|
|
# Installs or updates toes on a Raspberry Pi.
|
|
# Must be run as the 'toes' user with passwordless sudo.
|
|
|
|
REPO="https://git.nose.space/defunkt/toes"
|
|
DEST=~/toes
|
|
APPS_DIR=~/apps
|
|
DATA_DIR=~/data
|
|
|
|
# ── Helpers ──────────────────────────────────────────────
|
|
|
|
b=$'\033[1m' d=$'\033[2m' g=$'\033[32m' c=$'\033[36m' y=$'\033[33m' r=$'\033[0m'
|
|
|
|
quiet() { "$@" > /dev/null 2>&1; }
|
|
|
|
info() { echo " ${d}>>${r} $1"; }
|
|
|
|
fail() { echo " ${y}ERROR:${r} $1" >&2; exit 1; }
|
|
|
|
# ── Preflight ────────────────────────────────────────────
|
|
|
|
echo ""
|
|
echo " ${d}╔══════════════════════════════════╗${r}"
|
|
echo " ${d}║${r} ${b}🐾 toes${r} ${d}- personal web appliance ║${r}"
|
|
echo " ${d}╚══════════════════════════════════╝${r}"
|
|
echo ""
|
|
|
|
[ "$(whoami)" = "toes" ] || fail "Must be run as the 'toes' user."
|
|
sudo -n true 2>/dev/null || fail "Requires passwordless sudo."
|
|
|
|
# ── System packages ──────────────────────────────────────
|
|
|
|
info "Updating system packages"
|
|
quiet sudo apt-get update
|
|
quiet sudo apt-get install -y git libcap2-bin avahi-utils fish unzip
|
|
|
|
if [ "$(getent passwd toes | cut -d: -f7)" != "/usr/bin/fish" ]; then
|
|
info "Setting fish as default shell"
|
|
quiet sudo chsh -s /usr/bin/fish toes
|
|
fi
|
|
|
|
# ── Bun ──────────────────────────────────────────────────
|
|
|
|
BUN="$HOME/.bun/bin/bun"
|
|
|
|
if [ ! -x "$BUN" ]; then
|
|
info "Installing bun"
|
|
curl -fsSL https://bun.sh/install | bash > /dev/null 2>&1
|
|
[ -x "$BUN" ] || fail "bun installation failed."
|
|
fi
|
|
|
|
sudo ln -sf "$BUN" /usr/local/bin/bun
|
|
|
|
sudo setcap 'cap_net_bind_service=+ep' "$BUN"
|
|
|
|
# ── Clone or pull ────────────────────────────────────────
|
|
|
|
if [ -d "$DEST/.git" ]; then
|
|
info "Pulling latest toes"
|
|
git -C "$DEST" fetch origin main
|
|
git -C "$DEST" reset --hard origin/main
|
|
else
|
|
info "Cloning toes"
|
|
git clone "$REPO" "$DEST"
|
|
fi
|
|
|
|
# ── Directories ──────────────────────────────────────────
|
|
|
|
mkdir -p "$APPS_DIR" "$DATA_DIR" "$DATA_DIR/toes"
|
|
|
|
# ── Dependencies & build ─────────────────────────────────
|
|
|
|
cd "$DEST"
|
|
|
|
info "Installing dependencies"
|
|
quiet bun install
|
|
|
|
info "Building"
|
|
rm -rf "$DEST/dist"
|
|
quiet bun run build
|
|
|
|
# ── Bundled apps ─────────────────────────────────────────
|
|
|
|
REPOS_DIR="$DATA_DIR/repos"
|
|
mkdir -p "$REPOS_DIR"
|
|
|
|
info "Installing bundled apps"
|
|
for app_dir in "$DEST"/apps/*/; do
|
|
app=$(basename "$app_dir")
|
|
[ -f "$app_dir/package.json" ] || continue
|
|
echo " $app"
|
|
cp -a "$app_dir" "$APPS_DIR/$app"
|
|
quiet bun install --frozen-lockfile --cwd "$APPS_DIR/$app" || quiet bun install --cwd "$APPS_DIR/$app"
|
|
|
|
# Seed bare repo for git-based versioning
|
|
bare="$REPOS_DIR/$app.git"
|
|
quiet git -C "$APPS_DIR/$app" init -b main
|
|
quiet git -C "$APPS_DIR/$app" add -A
|
|
quiet git -C "$APPS_DIR/$app" -c user.name=toes -c user.email=toes@localhost commit -m "install"
|
|
if [ -d "$bare" ]; then
|
|
quiet git -C "$APPS_DIR/$app" push --force "$bare" main
|
|
else
|
|
quiet git clone --bare "$APPS_DIR/$app" "$bare"
|
|
quiet git -C "$bare" config http.receivepack true
|
|
fi
|
|
rm -rf "$APPS_DIR/$app/.git"
|
|
done
|
|
|
|
# ── CLI + SSH ────────────────────────────────────────────
|
|
|
|
info "Installing CLI"
|
|
quiet bun run cli:build
|
|
sudo cp dist/toes /usr/local/bin/toes
|
|
|
|
info "Setting up SSH access"
|
|
quiet sudo bash "$DEST/scripts/setup-ssh.sh"
|
|
|
|
# ── Systemd ──────────────────────────────────────────────
|
|
|
|
info "Installing toes service"
|
|
sudo install -m 644 "$DEST/scripts/toes.service" /etc/systemd/system/toes.service
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable toes
|
|
|
|
info "Restarting toes"
|
|
sudo systemctl restart toes
|
|
|
|
# ── Done ─────────────────────────────────────────────────
|
|
|
|
VERSION=$(git describe --tags --always 2>/dev/null || echo "unknown")
|
|
|
|
echo ""
|
|
echo " ${b}${g}🐾 toes $VERSION is up!${r}"
|
|
echo " ${d}─────────────────────────────${r}"
|
|
echo ""
|
|
echo " Dashboard: ${c}http://$(hostname).local${r}"
|
|
echo " SSH CLI: ${c}ssh cli@$(hostname).local${r}"
|
|
echo ""
|
|
echo " ${d}Grab the CLI:${r}"
|
|
echo " ${c}curl -fsSL http://$(hostname).local/install | bash${r}"
|
|
echo ""
|