-
-
Save douglasjacobsen/3ea4421c0d8ae8c460b0 to your computer and use it in GitHub Desktop.
Git setup for acme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ORG=ACME-Climate | |
REPO=ACME | |
ERROR=0 | |
IS_GIT=`which git` | |
if [ "${IS_GIT}" == "" ]; then | |
echo "ERROR: Git is not installed on your system." | |
echo " Please install git prior to running this script." | |
ERROR=1 | |
fi | |
IS_CURL=`which curl` | |
if [ "${IS_CURL}" == "" ]; then | |
echo "ERROR: This script requires curl. Please install it prior to using this script." | |
ERROR=1 | |
fi | |
if [ ${ERROR} == 1 ]; then | |
echo "Exiting due to previous error." | |
exit 1 | |
fi | |
## Get github uername | |
echo "" | |
echo "Please enter your github username:" | |
read GITHUB_USERNAME | |
## Get github password | |
echo "Generate a personal access token here: https://github.com/settings/tokens" | |
echo " This token is used to access the web API on github, and get a list of all forks." | |
echo "Please enter your github personal access token" | |
read GITHUB_TOKEN | |
## Setup gitconfig file with user.name and user.email | |
if [ ! -e ~/.gitconfig ]; then | |
echo "" | |
echo "What is your full name?" | |
read NAME | |
echo "" | |
echo "What is your email address? (Use one that is verifed on your github account)" | |
read EMAIL | |
echo "" | |
echo "Git will be configured with the following settings:" | |
echo " user.name = ${NAME}" | |
echo " user.email = ${EMAIL}" | |
echo "" | |
echo "Should we proceed? (yes/no)" | |
read ANS | |
if [ "${ANS}" == "yes" ]; then | |
git config --global user.name "${NAME}" | |
git config --global user.email "${EMAIL}" | |
else | |
echo "" | |
echo "**************************************" | |
echo "Answer was not yes. Aborting script..." | |
echo "**************************************" | |
exit 0 | |
fi | |
else | |
NAME=`git config --global user.name` | |
EMAIL=`git config --global user.email` | |
if [ "${NAME}" == "" ]; then | |
echo "" | |
echo "What is your full name?" | |
read NAME | |
echo "" | |
echo "Git is now configured with your name as: ${NAME}" | |
git config --global user.name ${NAME} | |
else | |
echo "" | |
echo "Git is configured with your name as: ${NAME}" | |
fi | |
if [ "${EMAIL}" == "" ]; then | |
echo "" | |
echo "What is your email address? (Use one that is verifed on your github account)" | |
read EMAIL | |
echo "" | |
echo "Git is now configured with your email as: ${EMAIL}" | |
git config --global user.email ${EMAIL} | |
else | |
echo "" | |
echo "Git is configured with your email as: ${EMAIL}" | |
fi | |
fi | |
git config --global github.user ${GITHUB_USERNAME} | |
git config --global core.autocrlf input | |
git config --global core.whitespace trailing-space | |
## Turn on ui coloring: | |
HAS_COLOR=`git config --global color.ui` | |
if [ "${HAS_COLOR}" == "" ]; then | |
git config --global color.ui true | |
fi | |
## Set push.default globally | |
PUSH_DEF=`git config --global push.default` | |
if [ "${PUSH_DEF}" == "" ]; then | |
GIT_VER=`git --version | awk '{print $3}'` | |
GIT_MAJOR_VER=${GIT_VER%%.*} | |
GIT_MINOR_VER=${GIT_VER#*.} | |
GIT_MINOR_VER=${GIT_MINOR_VER%.*} | |
GIT_SUBMINOR_VER=${GIT_VER##*.} | |
if [ ${GIT_MAJOR_VER} -le 1 ]; then | |
if [ ${GIT_MINOR_VER} -le 8]; then | |
if [ ${GIT_SUBMINOR_VER} -le 2]; then | |
git config --global push.default nothing | |
fi | |
fi | |
fi | |
PUSH_DEF=`git config --global push.default` | |
if [ "${PUSH_DEF}" == "" ]; then | |
git config --global push.default simple | |
fi | |
fi | |
git config --global pull.ff only | |
## Define the editor for git commits | |
HAS_EDIT=`git config --global core.editor` | |
if [ "${HAS_EDIT}" == "" ]; then | |
echo "" | |
echo "What is your deafult editor? (Please enter the full path)" | |
read EDITOR | |
git config --global core.editor ${EDITOR} | |
fi | |
ssh git@github.com &> .test | |
SSH_TEST=`grep "success" .test` | |
while [ "${SSH_TEST}" == "" ]; do | |
echo "" | |
echo "ERROR: You do not have your ssh keys properly setup on github." | |
echo "Please navigate to: https://github.com/settings/ssh and add an ssh key." | |
echo "You can use the following guide to help create a new ssh key. https://help.github.com/articles/generating-ssh-keys" | |
echo "" | |
echo "Press enter when your ssh key has been configured properly." | |
read test | |
ssh git@github.com &> .test | |
SSH_TEST=`grep "success" .test` | |
done | |
rm .test | |
echo "" | |
echo "This script will setup your repository in the current working directory." | |
echo "Would you like to change this? (yes/no)" | |
ROOT_DIR=${PWD} | |
read ANS | |
if [ "${ANS}" == "yes" ]; then | |
echo "" | |
echo "Enter the full path where you would like your repositories setup." | |
read ROOT_DIR | |
fi | |
mkdir -p ${ROOT_DIR} | |
cd ${ROOT_DIR} | |
## Create a fork (Uncomment to create a fork for your github username) | |
#curl -s -H "Authorization: TOKEN ${GITHUB_TOKEN}" -X POST -i https://api.github.com/repos/${ORG}/${REPO}/forks &> /dev/null | |
## Clone repository | |
echo "" | |
echo "Cloning ${ORG}/${REPO} into ${REPO}" | |
git clone git@github.com:${ORG}/${REPO}.git &> /dev/null | |
cd ${REPO} | |
## Rename origin | |
echo "Would you like to rename origin to ACME-Climate/ACME? (Enter yes/no)" | |
read ANS | |
if [ "${ANS}" == "yes" ]; then | |
git remote rename origin ${ORG}/${REPO} &> /dev/null | |
fi | |
## Add all forks. | |
FORK_URL="https://api.github.com/repos/${ORG}/${REPO}/forks" | |
FORK_LIST=`curl -s -H "Authorization: TOKEN ${GITHUB_TOKEN}" -i ${FORK_URL} | grep '"full_name"' | awk '{print $2}' | sed "s/,//g" | sed "s/\"//g"` | |
for FORK in ${FORK_LIST} | |
do | |
echo " Adding remote: ${FORK}" | |
git remote add ${FORK} git@github.com:${FORK}.git &> /dev/null | |
done | |
## Fetch all history | |
echo "" | |
echo "Fetching history." | |
git fetch --all &> /dev/null | |
git fetch --tags &> /dev/null | |
## Setup commit template message | |
git config commit.template ${PWD}/.git/hooks/commit.template | |
## Clone the hooks repository into the hooks directory. | |
rm -rf ${PWD}/.git/hooks | |
git clone git@github.com:ACME-Climate/ACME-Hooks.git ${PWD}/.git/hooks | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment