This commit is contained in:
LuKe Tidd 2022-11-18 16:13:18 -05:00
parent 6f2bd20e67
commit 498c89dc27
4 changed files with 97 additions and 1 deletions

View File

@ -1,3 +1,3 @@
# repo_tools
wrapper scripts to securely access repos here
wrapper scripts to securely access repos here

36
gclone Executable file
View File

@ -0,0 +1,36 @@
#!/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"
git remote remove origin
git push --set-upstream "$url" main
fi

30
gpull Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
if [[ -z "$1" ]]; then
printf 'Need a project:\n\n' >&2
pass show gitea/token >&2
exit 1
fi
project="$1"
shift
unset token
token="$(pass show gitea/token/${project})"
if [[ -z "$token" ]]; then
printf 'Failed to get token.\n'
exit 1
fi
url="https://luke:${token}@git.drheck.dev/luke/${project}.git"
if [[ "$project" == 'pass' ]]; then
if [[ -n "$@" ]]; then
pass git pull "$@" "$url"
else
pass git pull "$url"
fi
else
if [[ -n "$@" ]]; then
git pull "$@" "$url"
else
git pull "$url"
fi
fi

30
gpush Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
if [[ -z "$1" ]]; then
printf 'Need a project:\n\n' >&2
pass show gitea/token >&2
exit 1
fi
project="$1"
shift
unset token
token="$(pass show gitea/token/${project})"
if [[ -z "$token" ]]; then
printf 'Failed to get token.\n'
exit 1
fi
url="https://luke:${token}@git.drheck.dev/luke/${project}.git"
if [[ "$project" == 'pass' ]]; then
if [[ -n "$@" ]]; then
pass git push "$@" "$url"
else
pass git push "$url"
fi
else
if [[ -n "$@" ]]; then
git push "$@" "$url"
else
git push "$url"
fi
fi