Apps / Software Development / :3030

Gitea

Your own Git hosting, with code review, issues and CI.

No MiniControl yet? Download MiniControl, then install Gitea from its catalog.

Gitea is a self-hosted Git service with repositories, pull requests, issue tracking, a package registry and GitHub-compatible CI. It stores everything in a single SQLite database and a folder of repositories, so it needs no other server. Push your code to the machine and keep it under your own roof.

The web page answers the whole home network. Sign-up is switched off, so only the account made at install (and any you add as that admin) can log in. Git over SSH is off; use HTTP clones.

After the install: Open Gitea and log in with the user name and password shown when the install finished, then create your first repository. Git over SSH is switched off, so clone and push over HTTP.

Free, like the whole catalog.

What MiniControl installs

Packages
brew install gitea
Web page
Port 3030
Keeps running
As LaunchAgent app.minicontrol.gitea, also after a restart
Its data
~/services/gitea
Memory
100–300 MB
Licence
MIT
The install script

What MiniControl runs on your server, word for word. The app shows the same script before it installs.

#!/bin/bash
# Generated by MiniControl for Gitea. Runs on the machine.
set -euo pipefail
export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_ENV_HINTS=1 NONINTERACTIVE=1
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:$PATH"
step() { echo "STEP|$1|$2"; }
fail() { echo "ERR|$1"; exit 1; }
U=$(id -u)
BREW=$(command -v brew || true)
[ -n "$BREW" ] || fail "Homebrew isn't installed. Server Setup → Homebrew installs it."
BP=$("$BREW" --prefix)
step 1 "Checking the machine"
for f in "$HOME"/Library/LaunchAgents/*.plist; do
  if grep -qsF -- 'bin/gitea' "$f"; then fail "Gitea is already set up here, as $(basename "$f" .plist)."; fi
done
if lsof -nP -iTCP:3030 -sTCP:LISTEN >/dev/null 2>&1; then
  fail "Something else already uses port 3030: $(lsof -nP -iTCP:3030 -sTCP:LISTEN | awk 'NR == 2 {print $1}')."
fi
step 2 "Installing with Homebrew"
"$BREW" list --formula gitea >/dev/null 2>&1 || "$BREW" install gitea
step 3 "Setting it up"
mkdir -p "$HOME/services/gitea/log" "$HOME/Library/LaunchAgents" "$HOME/services/gitea/data" "$HOME/services/gitea/repositories"
# Gitea ignores GITEA__ variables from Homebrew, so the settings go in its config file. Written only once, so a reinstall keeps its keys.
if [ ! -f "$HOME/services/gitea/app.ini" ]; then
  MC_SECRET=$(openssl rand -hex 32)
  {
    printf '%s\n' "APP_NAME = Gitea" "RUN_USER = $(id -un)" "RUN_MODE = prod" ""
    printf '%s\n' "[server]" "HTTP_ADDR = 0.0.0.0" "HTTP_PORT = 3030" "DISABLE_SSH = true" "START_SSH_SERVER = false" ""
    printf '%s\n' "[database]" "DB_TYPE = sqlite3" "PATH = $HOME/services/gitea/data/gitea.db" ""
    printf '%s\n' "[repository]" "ROOT = $HOME/services/gitea/repositories" ""
    printf '%s\n' "[log]" "ROOT_PATH = $HOME/services/gitea/log" ""
    printf '%s\n' "[security]" "INSTALL_LOCK = true" "SECRET_KEY = $MC_SECRET" ""
    printf '%s\n' "[service]" "DISABLE_REGISTRATION = true"
  } > "$HOME/services/gitea/app.ini" || fail "Couldn't write Gitea's config file."
fi
PL="$HOME/Library/LaunchAgents/app.minicontrol.gitea.plist"
cat > "$PL" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key><string>app.minicontrol.gitea</string>
  <key>ProgramArguments</key>
  <array>
    <string>$BP/opt/gitea/bin/gitea</string>
    <string>web</string>
    <string>--config</string>
    <string>$HOME/services/gitea/app.ini</string>
    <string>--work-path</string>
    <string>$HOME/services/gitea</string>
  </array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
  <key>ThrottleInterval</key><integer>10</integer>
  <key>ProcessType</key><string>Background</string>
  <key>StandardOutPath</key><string>$HOME/services/gitea/log/launchd.out.log</string>
  <key>StandardErrorPath</key><string>$HOME/services/gitea/log/launchd.err.log</string>
</dict>
</plist>
EOF
plutil -lint "$PL" >/dev/null
[ -x "$BP/opt/gitea/bin/gitea" ] || fail "$BP/opt/gitea/bin/gitea isn't there after the install."
step 4 "Starting Gitea"
# Services run in the logged-in user's session (gui/<uid>), like every service in the panel.
launchctl bootstrap "gui/$U" "$PL" || fail "launchd didn't start it. Services run while you're logged in on the machine; Server Setup's \"Log in automatically after a restart\" fixes that."
if /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate 2>/dev/null | grep -q enabled; then echo "FW|$BP/opt/gitea/bin/gitea"; fi
step 5 "Waiting for it to answer"
# Localhost, the address a recipe bound to (`MC_BIND`), and the Tailscale IP for apps that bind only to it.
# `|| true`: with set -e, a failed substitution in an assignment would end the script.
HOSTS="127.0.0.1 ${MC_BIND:-} $(for t in "$BP/bin/tailscale" /usr/local/bin/tailscale; do [ -x "$t" ] && "$t" ip -4 2>/dev/null && break; done | head -1 || true)"
ok=0
for i in $(seq 1 45); do
  for h in $HOSTS; do
    if curl -fsS -m 3 -o /dev/null "http://$h:3030/api/healthz" 2>/dev/null; then ok=1; break 2; fi
  done
  sleep 2
done
[ "$ok" = 1 ] || echo "WARN|It started, but isn't answering on port 3030 yet. Big apps can take a minute on first start."
MC_CFG=(--config "$HOME/services/gitea/app.ini" --work-path "$HOME/services/gitea")
if "$BP/opt/gitea/bin/gitea" admin user list "${MC_CFG[@]}" 2>/dev/null | grep -qw minicontrol; then
  echo "WARN|Gitea kept its accounts from before, so log in as you did then."
else
  MC_PW=$(openssl rand -hex 12)
  "$BP/opt/gitea/bin/gitea" admin user create "${MC_CFG[@]}" --admin --username minicontrol --email minicontrol@localhost --password "$MC_PW" --must-change-password=false >/dev/null || fail "Couldn't create Gitea's first account."
  echo "WARN|Gitea's login: user name minicontrol, password $MC_PW. Shown once, so save it now."
fi
echo "DONE"

MiniControl isn’t affiliated with Gitea. Questions about Gitea itself go to its makers; about installing it, to [email protected].