# gitsync - 100% Vibecode but tested PREFIX ?= /usr BINDIR = $(PREFIX)/bin CONF = $(HOME)/.config/gitsync/gitsync.conf HOST ?= debian@162.19.227.194 REMOTE ?= /var/www/html/git.christianimmanuel.de .PHONY: install uninstall config config-update deploy deploy-web deploy-apache clean ssh-key cron cron-daily uncron KEY = $(HOME)/.ssh/gitsync_ed25519 CRON = 0 12 * * * ping -c1 -W5 162.19.227.194 >/dev/null 2>&1 && $(BINDIR)/gitsync -q install: ## install gitsync to /usr/bin (needs root) install -Dm755 gitsync $(DESTDIR)$(BINDIR)/gitsync uninstall: ## remove gitsync rm -f $(DESTDIR)$(BINDIR)/gitsync config: ## copy example config to ~/.config/gitsync (does not overwrite) @test -f $(CONF) && echo "$(CONF) exists, not touching it" || (install -Dm644 gitsync.conf $(CONF) && echo "created $(CONF)") config-update: ## overwrite ~/.config/gitsync/gitsync.conf with the shipped one (keeps a .bak) @test -f $(CONF) && cp $(CONF) $(CONF).bak && echo "backup at $(CONF).bak" || true install -Dm644 gitsync.conf $(CONF) deploy-web: ## upload only index.php + style.css rsync -a web/index.php web/style.css $(HOST):$(REMOTE)/ deploy-apache: ## upload apache configs (http, https, shared) to /tmp on the server scp apache/git.christianimmanuel.de.conf apache/git.christianimmanuel.de-le-ssl.conf apache/git.christianimmanuel.de-common.conf $(HOST):/tmp/ @echo "on the server: sudo mv /tmp/git.christianimmanuel.de*.conf /etc/apache2/sites-available/ && sudo apache2ctl configtest && sudo systemctl reload apache2" deploy: deploy-web deploy-apache ssh-key: ## create the upload key and print what to do on the server @test -f $(KEY) || ssh-keygen -t ed25519 -N "" -C gitsync -f $(KEY) @echo; echo "on the server (as root):"; echo " adduser --disabled-password --gecos '' git-local" @echo " install -d -m700 -o git-local -g git-local /home/git-local/.ssh" @echo " echo 'restrict,port-forwarding $$(cat $(KEY).pub)' > /home/git-local/.ssh/authorized_keys" @echo " chown git-local:git-local /home/git-local/.ssh/authorized_keys; chmod 600 /home/git-local/.ssh/authorized_keys" @echo " chown -R git-local:www-data $(REMOTE)/repos" @echo; echo "then: ssh -i $(KEY) git-local@162.19.227.194 true" cron: ## sync daily at 12:00 when the server is reachable @( crontab -l 2>/dev/null | grep -v '/gitsync -q'; echo "$(CRON)" ) | crontab - @crontab -l | grep gitsync cron-daily: ## system-wide alternative: /etc/cron.daily/gitsync (run as root, set USER= inside) install -m755 cron/gitsync /etc/cron.daily/gitsync uncron: ## remove the cron job @crontab -l 2>/dev/null | grep -v '/gitsync -q' | crontab - ; echo "removed" clean: ## remove local staging cache rm -rf $(HOME)/.cache/gitsync