repo_tools/gclone

41 lines
911 B
Bash
Executable File

#!/bin/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.\n'
exit 1
fi
token_url="https://luke:${token}@git.drheck.dev/luke/${project}.git"
url="https://luke@git.drheck.dev/luke/${project}.git"
if [[ "$project" == 'pass' ]]; then
if [[ -n "$@" ]]; then
pass git pull "$@" "$token_url"
else
pass git pull "token_url"
fi
else
if [[ -n "$@" ]]; then
readarray -t out <<< "$(git clone "$@" "$token_url" 2>&1)"
else
readarray -t out <<< "$(git clone "$token_url" 2>&1)"
fi
new_dir="$(awk -F\' '{print $2}' <<< "$out")"
cd "$new_dir"
gpg_key='75D6600BEF4E8E8F'
git config user.signingkey "$gpg_key"!
git config commit.gpgsign true
git remote remove origin
git push --set-upstream "$url" main
fi