Merge branch 'master' of github.com:HariSekhon/DevOps-Bash-tools

pull/4/merge
Hari Sekhon 1 year ago
commit d55db033ef

@ -24,9 +24,7 @@ bash_tools="${bash_tools:-$(dirname "${BASH_SOURCE[0]}")/..}"
#type add_PATH &>/dev/null || . "$bash_tools/.bash.d/paths.sh"
# env var takes preference, then cwd, then $HOME, then /etc/ansible/ansible.cfg
# $srcdir set in .bashrc
# shellcheck disable=SC2154
export ANSIBLE_CONFIG="$bash_tools/.ansible.cfg"
export ANSIBLE_CONFIG=~/.ansible.cfg # symlinked to $bash_tools/configs/.ansible.cfg
if [ -n "${ANSIBLE_HOME:-}" ]; then
add_PATH PYTHONPATH "$ANSIBLE_HOME/lib"

@ -694,6 +694,7 @@ etc.
- `github_api.sh` - queries the GitHub [API](https://docs.github.com/en/rest/reference). Can infer GitHub user, repo and authentication token from local checkout or environment (`$GITHUB_USER`, `$GITHUB_TOKEN`)
- `github_install_binary.sh` - installs a binary from GitHub releases into $HOME/bin or /usr/local/bin. Auto-determines the latest release if no version specified, detects and unpacks any tarball or zip files
- `github_foreach_repo.sh` - executes a templated command for each non-fork GitHub repo, replacing the `{owner}`/`{name}` or `{repo}` placeholders in each iteration
- `github_clone_or_pull_all_repos.sh` - git clones or pulls all repos for a user or organization into directories of the same name under the current directory
- `github_invitations.sh` - lists / accepts repo invitations. Useful to accept a large number of invites to repos generated by automation
- `github_mirror_repos_to_gitlab.sh` - creates/syncs GitHub repos to GitLab for migrations or to cron fast free Disaster Recovery, including all branches and tags, plus the repo descriptions. Note this doesn't include PRs/wikis/releases
- `github_mirror_repos_to_bitbucket.sh` - creates/syncs GitHub repos to BitBucket for migrations or to cron fast free Disaster Recovery, including all branches and tags, plus the repo descriptions. Note this doesn't include PRs/wikis/releases

@ -0,0 +1,90 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2023-06-01 00:55:07 +0100 (Thu, 01 Jun 2023)
#
# https://github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/github.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Git clones all repos for a given owner (user or organization)
Clones repos to the current directory using the same directory names as each repo
By default will clone via SSH. Set the environment variable GIT_HTTPS to any value to use the HTTPS protocol to clone instead
If the directory already exists, enters, switches to the default branch and does a 'git pull'
For an organization, you must set the environment variable \$GITHUB_ORGANIZATION, otherwise by default will attempt to determine your github user via \$GITHUB_USER or your currently authenticated GitHub API user as defined from the utility script github_api.sh
Requires Git and the adjacent github_api.sh script to be installed and configured for authentication
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args=""
help_usage "$@"
max_args 1 "$@"
owner="${GITHUB_ORGANIZATION:-${GITHUB_USER:-$(get_github_user)}}"
github_url="git@github.com:"
if [ -n "${GIT_HTTPS:-}" ]; then
github_url="https://github.com/"
fi
trap_cmd 'echo Exited with error'
get_github_repos "$owner" "${GITHUB_ORGANIZATION:-}" |
while read -r repo; do
if [ -d "$repo" ]; then
timestamp "GitHub repo directory '$repo' already exists, entering directory to update checkout"
pushd "$repo" >/dev/null
echo
branch="$(default_branch)"
timestamp "Switching to default branch '$branch'"
if git status --porcelain | grep -q '^.M'; then
echo
timestamp "Stashing changes in progress"
git stash
echo
fi
git checkout "$branch"
echo
timestamp "Git Pull"
git pull
if git stash list | grep -q .; then
timestamp "Popping stash"
git stash pop 2>/dev/null || :
echo
fi
echo
timestamp "Leaving directory"
popd >/dev/null
else
timestamp "Cloning repo '$owner/$repo' to directory '$repo'"
git clone "$github_url""$owner/$repo"
fi
echo
hr
echo
done
untrap
timestamp "All github repos cloned and up to date for owner '$owner'"

@ -12,7 +12,7 @@ codeship/taps/jet
docker
#insomnia # Kong Rest API testing client desktop app
#iterm2
firefox-developer-edition
#firefox-developer-edition
google-chrome
google-cloud-sdk
keepassxc

Loading…
Cancel
Save