Files
opora_members/setup_git_auth.sh
T

18 lines
784 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
HOST="git.itguild.info"
USER_NAME="${1:-apuc}"
# Keep the token out of shell history, process arguments, and project files.
read -r -s -p "Введите персональный токен Git для ${USER_NAME}: " TOKEN
printf '\n'
if [[ -z "$TOKEN" ]]; then
echo "Токен пустой — ничего не сохранено." >&2
exit 1
fi
# Cache credentials in memory for up to 30 days (lost on reboot/cache expiry).
git config --global credential.helper 'cache --timeout=2592000'
printf 'protocol=https\nhost=%s\nusername=%s\npassword=%s\n\n' "$HOST" "$USER_NAME" "$TOKEN" | git credential approve
unset TOKEN
echo "Git credential-cache настроен для HTTPS; секрет сохранён только в памяти."