Added standalone method to install script and README file.

This commit is contained in:
Tony Grosinger 2014-01-04 15:35:36 -08:00
parent e7f9bd0376
commit 53a1c6bf1e
2 changed files with 114 additions and 36 deletions

21
README.md Normal file
View File

@ -0,0 +1,21 @@
Tony's DotFiles
===============
This is a collection of all the files that I want very easily available on any new machine that I sit down at. The install script is designed to be run either from the cloned repository or as a stand-alone script through curl. See the usage details for examples.
Usage
-----
** Method 1 **
The first method requires cloning the repository and running the install script manually.
git clone git@github.com:tgrosinger/dotfiles.git ~/.dotfiles
cd ~/.dotfiles
./install.sh
** Method 2 **
The second method does not require cloning the repository however it does require that Git and Curl is installed on the target machine.
\curl -sSL https://raw.github.com/tgrosinger/dotfiles/master/install.sh | bash

View File

@ -1,12 +1,28 @@
#!/bin/bash
# Make sure git is installed. Exit if it isn't
if which git; then
echo "Please install git before continuing"
exit 1
fi
################################################################################
#Copyright (C) 2013 Tony Grosinger. All rights reserved.
#
#Description:
# This script can be run in two modes depending on the file structure of the
# current working directory or the arguments passed to it.
#
# Mode 1: From within a cloned repository or downloaded snapshot with all files
# already present and ready to be symlinked
#
# Mode 2: Standalone or through Curl in which case all required files will be
# downloaded automatically to `~/.dotfiles` before creating symlinks.
#
#Change History:
# Date Author Description
# ---------- -------------- ------------------------------------
# 2014-01-04 agrosinger Updated to two mode operation
################################################################################
REPO_DIR="$( cd "$( dirname "$0" )" && pwd )"
################################################################################
# Define functions
################################################################################
# Remove a file if it exists then create a symlink to the one contained in ${REPO_DIR}
function linkFile() {
@ -20,41 +36,82 @@ function createDirectory() {
mkdir $1
}
# Perform the actual work of copying files and creating symlinks.
# Requires a home directory argument.
function performSetup() {
if [ ${#} != 1 ]; then
echo "Must pass home directory to ${FUNCNAME}"
exit 1
fi
home=${1}
echo "Moving to Home directory...";
pushd ${home};
echo "Adding id_rsa.pub to authorized keys if necessary"
if [ ! -e ".ssh/authorized_keys" ] ; then
cp ${REPO_DIR}/.ssh/id_rsa.pub .ssh/authorized_keys
elif ! grep -q `cat ${REPO_DIR}/.ssh/id_rsa.pub` ".ssh/authorized_keys"; then
cat ${REPO_DIR}/.ssh/id_rsa.pub >> .ssh/authorized_keys
fi
echo "Linking shell configs...";
linkFile ".bashrc"
echo "Linking vim...";
linkFile ".vimrc"
createDirectory ".vim"
createDirectory ".vim/swaps"
createDirectory ".vim/backups"
echo "Linking Git...";
linkFile ".gitconfig"
echo "Linking tmux...";
linkFile ".tmux.conf"
echo "Linking inputrc..."
linkFile ".inputrc"
popd
}
################################################################################
# Initialize (Determine mode)
################################################################################
# Determine which mode we are running in. (Is the file in the current directory?)
if [ -f install.sh ]; then
echo "Running in Mode 1: Already cloned repository"
REPO_DIR="$( cd "$( dirname "$0" )" && pwd )"
else
echo "Running in Mode 2: Direct from Curl"
# Make sure git is installed. Exit if it isn't.
if ! which git; then
echo "Please install git before continuing."
echo "Alternatively, download the files and run manually from https://github.com/tgrosinger/dotfiles/archive/master.zip"
exit 1
fi
# Clone the repository into current location using readonly url.
echo "Cloning dotfiles repository to ~/.dotfiles"
git clone https://github.com/tgrosinger/dotfiles.git ~/.dotfiles
REPO_DIR="~/.dotfiles"
fi
################################################################################
# Main Operation
################################################################################
echo "This will create symlinks and destroy any conflicting configs already in place.";
read -p "Continue? [y/N] " choice
# Perform the logic
case "$choice" in
Y|y|yes )
echo "Moving to Home directory...";
cd ~;
echo "Adding id_rsa.pub to authorized keys if necessary"
if [ ! -e ".ssh/authorized_keys" ] ; then
cp ${REPO_DIR}/.ssh/id_rsa.pub .ssh/authorized_keys
elif ! grep -q `cat ${REPO_DIR}/.ssh/id_rsa.pub` ".ssh/authorized_keys"; then
cat ${REPO_DIR}/.ssh/id_rsa.pub >> .ssh/authorized_keys
fi
echo "Linking shell configs...";
linkFile .bashrc
echo "Linking vim...";
linkFile .vimrc
createDirectory ~/.vim
createDirectory ~/.vim/swaps
createDirectory ~/.vim/backups
echo "Linking Git...";
linkFile .gitconfig
echo "Linking tmux...";
linkFile .tmux.conf
echo "Linking inputrc..."
linkFile .inputrc
Y|y|yes )
performSetup ${HOME}
echo "Done! Restart your shell to see changes"
;;
* ) echo "Aborted!";;
* ) echo "Aborted!";;
esac