Add deploy.sh — credentials from ~/.config/koncad/deploy.env

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
DanielandClaude Sonnet 4.6 committed 2026-04-06 20:54:53 +02:00
1 parent a971e97b10
commit 2f62bf55e0
1 file changed
+77
Executable
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# KonCad deployment script
# Credentials stored in: ~/.config/koncad/deploy.env
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG="$HOME/.config/koncad/deploy.env"
if [[ ! -f "$CONFIG" ]]; then
echo "ERROR: $CONFIG not found."
echo "Create it with:"
echo " mkdir -p ~/.config/koncad"
echo " cat > $CONFIG <<EOF"
echo " GITEA_TOKEN=your_token"
echo " GITEA_URL=https://git.d4nn13.de"
echo " GITEA_USER=d4nn13"
echo " GITEA_REPO=KonCad"
echo " DEPLOY_HOST=daniel@172.30.16.10"
echo " DEPLOY_PATH=/opt/KonCad"
echo " EOF"
echo " chmod 600 $CONFIG"
exit 1
fi
# shellcheck source=/dev/null
source "$CONFIG"
# ── Parse args ────────────────────────────────────────────────────────────────
DO_GIT=1
DO_SSH=1
MSG="${1:-}"
for arg in "$@"; do
case "$arg" in
--git-only) DO_SSH=0 ;;
--ssh-only) DO_GIT=0 ;;
--help|-h)
echo "Usage: ./deploy.sh [commit message] [--git-only] [--ssh-only]"
exit 0 ;;
esac
done
# ── Git commit + push ─────────────────────────────────────────────────────────
if [[ "$DO_GIT" -eq 1 ]]; then
cd "$SCRIPT_DIR"
# Set token in remote temporarily
git remote set-url origin "https://${GITEA_USER}:${GITEA_TOKEN}@${GITEA_URL#https://}/${GITEA_USER}/${GITEA_REPO}.git"
git add -A
if git diff --cached --quiet; then
echo "→ Git: nothing to commit"
else
COMMIT_MSG="${MSG:-deploy $(date '+%Y-%m-%d %H:%M')}"
git commit -m "$COMMIT_MSG"
echo "→ Git: committed — $COMMIT_MSG"
fi
git push origin master
echo "→ Git: pushed to ${GITEA_URL}/${GITEA_USER}/${GITEA_REPO}"
# Strip token from remote URL
git remote set-url origin "https://${GITEA_URL#https://}/${GITEA_USER}/${GITEA_REPO}.git"
fi
# ── rsync to server ───────────────────────────────────────────────────────────
if [[ "$DO_SSH" -eq 1 ]]; then
rsync -av --delete \
--exclude='.git' \
--exclude='.env' \
--exclude='deploy.sh' \
"$SCRIPT_DIR/" "${DEPLOY_HOST}:${DEPLOY_PATH}/"
echo "→ SSH: synced to ${DEPLOY_HOST}:${DEPLOY_PATH}"
fi
echo "✓ Done"