BlueGit

timfa posprint

Files

posprint / scripts / aur-ssh-setup.sh

aur-ssh-setup.sh

9611cde4 History
aur-ssh-setup.sh 1.0 KiB Download Raw
1#!/usr/bin/env bash
2# Write ~/.ssh/id_ed25519 for AUR pushes from CI or local scripts.
3#
4# Supported GitLab CI variables (pick one):
5# AUR_SSH_PRIVATE_KEY_B64 — base64-encoded private key (one line; can be Masked)
6# AUR_SSH_PRIVATE_KEY — GitLab "File" variable (path to temp file), or raw key text
7set -euo pipefail
8
9KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
10
11install -d -m 700 "$(dirname "$KEY_PATH")"
12
13if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then
14 echo "$AUR_SSH_PRIVATE_KEY_B64" | base64 -d > "$KEY_PATH"
15elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
16 # GitLab CI/CD variable type "File"
17 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
18elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
19 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"
20elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then
21 cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"
22else
23 echo "No AUR SSH key found. Set AUR_SSH_PRIVATE_KEY_B64 or AUR_SSH_PRIVATE_KEY." >&2
24 exit 1
25fi
26
27chmod 600 "$KEY_PATH"
28ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true