Last active
December 17, 2015 23:29
-
-
Save CarloMicieli/5689712 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # | |
| # Simple script to setup github | |
| # (2013) Carlo Micieli | |
| # | |
| NONE='\x1b[00m' | |
| RED='\x1b[31m' | |
| SSH_DIR="$HOME/.ssh" | |
| SSH_DIR_BKP="${SSH_DIR}_bkp" | |
| function echo_red() { | |
| echo -ne ${RED} | |
| echo -e $1 | |
| echo -e ${NONE} | |
| } | |
| function setup_git() | |
| { | |
| GIT_USER=$1 | |
| GIT_MAIL=$2 | |
| echo -ne 'Setting the auto color settings...' | |
| git config --global color.ui auto | |
| echo 'OK' | |
| echo -ne 'Setting the default editor...' | |
| git config --global core.editor nano | |
| echo 'OK' | |
| echo -ne 'Setting the global git user...' | |
| git config --global user.name ${GIT_USER} | |
| git config --global user.email ${GIT_MAIL} | |
| echo 'OK' | |
| echo '' | |
| echo 'Current git user:' | |
| echo -ne ${RED} | |
| git config --get --global user.name | |
| git config --get --global user.email | |
| echo -e ${NONE} | |
| if [ -d "$SSH_DIR" ]; then | |
| echo -ne 'Performing keys backup...' | |
| rm -rf $SSH_DIR_BKP | |
| mv $SSH_DIR $SSH_DIR_BKP | |
| echo 'OK' | |
| fi | |
| echo 'Setting the ssh keys...' | |
| ssh-keygen -t rsa -C ${GIT_MAIL} | |
| echo 'OK' | |
| xclip -sel clip < ~/.ssh/id_rsa.pub | |
| echo 'Paste the key on' | |
| echo_red '\t [https://github.com/settings/ssh]' | |
| read -p 'Press [Enter] after the public key is copied...' | |
| ssh -T git@github.com | |
| } | |
| function usage() | |
| { | |
| cat << EOF | |
| usage $0 options | |
| This script setup git for the current user. | |
| OPTIONS: | |
| -u the global git user name | |
| -m the global git mail address | |
| EOF | |
| } | |
| ## parsing command line options | |
| USER= | |
| MAIL= | |
| while getopts “hm:u:” OPTION | |
| do | |
| case $OPTION in | |
| h) | |
| usage | |
| exit 1 | |
| ;; | |
| m) | |
| MAIL=$OPTARG | |
| ;; | |
| u) | |
| USER=$OPTARG | |
| ;; | |
| ?) | |
| usage | |
| exit | |
| ;; | |
| esac | |
| done | |
| if [[ -z $USER ]] || [[ -z $MAIL ]] | |
| then | |
| usage | |
| exit 1 | |
| fi | |
| setup_git $USER, $MAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment