#!/bin/sh
name="git-set-remotes"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
Set all git remotes for my public repositories
Usage: git-set-remotes
Options:
-h, --help print this message and exit
-q, --quiet suppress error messages
-v, --version print version number and exit
EOF
)
. /usr/local/lib/myminiparse.sh
error_msg() {
if [ "$quiet" -eq 0 ]; then
(>&2 /usr/bin/printf "%s: %s\n" "$name" "$1")
fi
}
git_add_or_set() {
if ! git remote add "$1" "$2" >/dev/null 2>&1; then
error_msg "remote '${1}' already exists; resetting the URL"
git remote set-url "$1" "$2" >/dev/null 2>&1
fi
}
if [ ! -d .git ]; then
error_msg "not a git repository"
exit 1
fi
NAME="$(basename "$(pwd)")"
git_add_or_set "origin" "git:${NAME}.git"
git_add_or_set "github" "git@github.com:dricottone/${NAME}.git"
git_add_or_set "gitweb" "deploy-aws2:/var/git/${NAME}.git"