#!/usr/bin/env bash if [[ -z "$1" ]]; then printf 'Need a project:\n\n' >&2 pass show gitea/token >&2 exit 1 fi project="$1" shift token="$(pass show gitea/token/${project})" if [[ -z "$token" ]]; then printf 'Failed to get token for %s. ' "$project" >&2 printf 'Must be one of:\n\n' >&2 pass show gitea/token >&2 exit 1 fi gpg_key='75D6600BEF4E8E8F' token_url="https://luke:${token}@git.drheck.dev/luke/${project}.git" url="https://luke@git.drheck.dev/luke/${project}.git" if [[ "$project" == 'pass' ]]; then pass git pull "token_url" else readarray -t out <<< "$(git clone "$token_url" 2>&1)" printf 'out: %s\n' "${out[@]}" new_dir="$(awk -F\' '{print $2}' <<< "$out")" printf 'new dir: %s\n' "$new_dir" if [[ -z "$new_dir" ]]; then printf 'could not get dir from git clone.\n' >&2 exit 1 fi cd "$new_dir" git config user.signingkey "$gpg_key"! git config commit.gpgsign true git remote remove origin GPG_TTY=$(tty) git remote add main "$url" fi