A tiny read-only git web frontend — browse bare repos with just PHP and git, no database, no framework.
#!/usr/bin/env bash
# One-time server setup for git hosting over SSH: creates the dedicated git
# user, the bare-repo storage, and the git-shell-commands (so users can
# self-serve `create`). Independent of foxygit/stagit -- this is just the
# SSH/push/pull side. For the web viewer, see ../deploy.sh (or run
# ../install.sh to do both).
#
# Run as root, from anywhere:
# sudo bash /home/mrfox/foxygit/server/setup-server.sh
#
# Safe to re-run.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
GIT_USER="${GIT_USER:-git}"
GIT_HOME="${GIT_HOME:-/var/git}"
REPOS_DIR="$GIT_HOME/repos"
TEMPLATE_DIR="$GIT_HOME/templates"
SHELL_CMDS_DIR="$GIT_HOME/git-shell-commands"
SSH_DIR="$GIT_HOME/.ssh"
if [ "$(id -u)" -ne 0 ]; then
echo "run this as root (sudo bash $0)" >&2
exit 1
fi
GIT_SHELL_BIN="$(command -v git-shell || true)"
if [ -z "$GIT_SHELL_BIN" ]; then
echo "git-shell not found on PATH (is git installed?)" >&2
exit 1
fi
grep -qxF "$GIT_SHELL_BIN" /etc/shells || echo "$GIT_SHELL_BIN" >> /etc/shells
if ! id "$GIT_USER" >/dev/null 2>&1; then
useradd --create-home --home-dir "$GIT_HOME" --shell "$GIT_SHELL_BIN" "$GIT_USER"
else
usermod --shell "$GIT_SHELL_BIN" "$GIT_USER"
fi
mkdir -p "$REPOS_DIR" "$TEMPLATE_DIR" "$SHELL_CMDS_DIR" "$SSH_DIR"
for cmd in "$ROOT"/git-shell-commands/*; do
install -m 0755 "$cmd" "$SHELL_CMDS_DIR/$(basename "$cmd")"
done
touch "$SSH_DIR/authorized_keys"
chmod 700 "$SSH_DIR"
chmod 600 "$SSH_DIR/authorized_keys"
chown -R "$GIT_USER":"$GIT_USER" "$GIT_HOME"
cat <<EOF
Klart.
Nästa steg:
1. Lägg till publika SSH-nycklar (server/add-key.sh, eller manuellt en per rad i):
$SSH_DIR/authorized_keys
t.ex: ssh-ed25519 AAAA... namn@example.com
2. Skapa ett nytt repo (som valfri användare med nyckel i authorized_keys):
ssh $GIT_USER@<host> create <reponame>
3. Klona:
git clone $GIT_USER@<host>:repos/<reponame>.git
4. Servera repona med foxygit (webbläsning) -- se ../deploy.sh, eller kör
../install.sh för att göra båda delarna i ett svep.
Kontrollera att sshhost i server/git-shell-commands/create matchar din
faktiska domän.
EOF