From e6ea97ff4ab0d1b51e76c15844ca608b9290c6d2 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 8 Feb 2012 14:04:02 +0000 Subject: [PATCH 1/5] initial version of install.sh --- install.sh | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..7ea6f59 --- /dev/null +++ b/install.sh @@ -0,0 +1,132 @@ +#! /usr/bin/env bash + +# +# Configuration +# + +TARGET=$HOME +DOTFILES_LINK='.dotfiles' +PRIVATE_PATH='private' +SYMLINK=(bundle emacs.d erlang gemrc gitconfig gitignore hgrc irbrc \ + powconfig rspec tmux.conf) + +# +# Main Functions +# + +install_symlinks () { + # Symlink dotfiles root + symlink "$ROOT_PATH" "$TARGET/$DOTFILES_LINK" + + # Setup private dotfiles + local private_rakefile="$ROOT_PATH/$PRIVATE_PATH/Rakefile" + if [ -f "$private_rakefile" ]; then + rake --rakefile="$private_rakefile" symlink + fi + + # Symlink each path + for i in ${SYMLINK[@]}; do + symlink "$DOTFILES_LINK/$i" "$TARGET/.$i" + done + + # Symlink shell init file for bash and zsh + for i in profile zprofile; do + symlink "$DOTFILES_LINK/load_shellrc.sh" "$TARGET/.$i" + done +} + +install_homebrew () { + /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)" +} + +install_rbenv () { + git_clone 'git://github.com/sstephenson/rbenv.git' "$TARGET/.rbenv" +} + +isntall_nvm () { + git_clone 'https://github.com/creationix/nvm.git' "$TARGET/.nvm" +} + +install_virtualenv () { + curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | bash +} + + +# +# Initial Setup +# + +if [ -n "${BASH_SOURCE[0]}" ] && [ -f "${BASH_SOURCE[0]}" ] ; then + ROOT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +elif [ -n "$0" ] && [ -f "$0" ]; then + ROOT_PATH="$( cd "$( dirname "$0" )" && pwd )" +else + echo "[ERROR] Can't determine dotfiles' root path." + exit 1 +fi + + +# +# Helper functions +# + +symlink() { + if [ ! -e "$2" ]; then + echo " symlink: $2 --> $1" + ln -s "$1" "$2" + else + echo " exists: $2" + fi +} + +git_clone () { + if [ ! -e "$2" ]; then + git clone "$1" "$2" + else + echo "[ERROR] $2 already exists" + fi +} + + +# +# Argument Handling +# + +case "$1" in + target) + echo "Target directory is: $TARGET" + ;; + symlinks|links) + echo 'Installing: symlinks...' + install_symlinks + ;; + homebrew|brew) + echo 'Installing: Homebrew...' + install_homebrew + ;; + rbenv) + echo 'Installing: rbenv...' + install_rbenv + ;; + nvm) + echo 'Installing: nvm...' + install_nvm + ;; + virtualenv|venv) + echo 'Installing: virtualenv-burrito...' + install_virtualenv + ;; + *) + echo 'usage: ./install.sh [command]' + echo '' + echo 'Available commands:' + echo ' target: Print target directory used by other commands.' + echo ' symlinks: Install symlinks for various dotfiles into' \ + 'target directory.' + echo ' homebrew: Install Homebrew (Mac OS X only).' + echo ' rbenv: Install rbenv, a Ruby version manager.' + echo ' nvm: Install nvm, a Node.js version manager.' + echo ' virtualenv: Install virtualenv-burrito, a Python version and' \ + 'environment manager.' + ;; +esac From 9e11cd139d16a5f94206d905a6c21942260d73f0 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 8 Feb 2012 14:29:05 +0000 Subject: [PATCH 2/5] a couple of tweaks to install.sh --- install.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/install.sh b/install.sh index 7ea6f59..83abc16 100755 --- a/install.sh +++ b/install.sh @@ -4,11 +4,13 @@ # Configuration # -TARGET=$HOME -DOTFILES_LINK='.dotfiles' -PRIVATE_PATH='private' -SYMLINK=(bundle emacs.d erlang gemrc gitconfig gitignore hgrc irbrc \ +TARGET="$HOME" +DOTFILES_LINK=".dotfiles" +SYMLINK_PATH="$DOTFILES_LINK" +PRIVATE_PATH="private" +SYMLINKS=(bundle emacs.d erlang gemrc gitconfig gitignore hgrc irbrc \ powconfig rspec tmux.conf) +LOAD_FILES=(profile zprofile) # # Main Functions @@ -25,12 +27,12 @@ install_symlinks () { fi # Symlink each path - for i in ${SYMLINK[@]}; do - symlink "$DOTFILES_LINK/$i" "$TARGET/.$i" + for i in ${SYMLINKS[@]}; do + symlink "$SYMLINK_PATH/$i" "$TARGET/.$i" done # Symlink shell init file for bash and zsh - for i in profile zprofile; do + for i in ${LOAD_FILES[@]}; do symlink "$DOTFILES_LINK/load_shellrc.sh" "$TARGET/.$i" done } @@ -93,34 +95,30 @@ git_clone () { # case "$1" in - target) - echo "Target directory is: $TARGET" - ;; symlinks|links) - echo 'Installing: symlinks...' install_symlinks ;; homebrew|brew) - echo 'Installing: Homebrew...' install_homebrew ;; rbenv) - echo 'Installing: rbenv...' install_rbenv ;; nvm) - echo 'Installing: nvm...' install_nvm ;; virtualenv|venv) - echo 'Installing: virtualenv-burrito...' install_virtualenv ;; + info) + echo "Target directory: $TARGET" + echo "Detected dotfiles root: $ROOT_PATH" + ;; *) echo 'usage: ./install.sh [command]' echo '' echo 'Available commands:' - echo ' target: Print target directory used by other commands.' + echo ' info: Target and source directory info.' echo ' symlinks: Install symlinks for various dotfiles into' \ 'target directory.' echo ' homebrew: Install Homebrew (Mac OS X only).' From e5dae1cc42f837446cbaa43bae0f8fce83c73995 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 8 Feb 2012 14:38:58 +0000 Subject: [PATCH 3/5] a bit cleaner --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 83abc16..c370bf0 100755 --- a/install.sh +++ b/install.sh @@ -59,9 +59,9 @@ install_virtualenv () { # if [ -n "${BASH_SOURCE[0]}" ] && [ -f "${BASH_SOURCE[0]}" ] ; then - ROOT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + ROOT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) elif [ -n "$0" ] && [ -f "$0" ]; then - ROOT_PATH="$( cd "$( dirname "$0" )" && pwd )" + ROOT_PATH=$(cd "$(dirname "$0")" && pwd) else echo "[ERROR] Can't determine dotfiles' root path." exit 1 From caa62c81ed256ac7d9b8acf17d48d085ee719d51 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 8 Feb 2012 14:41:57 +0000 Subject: [PATCH 4/5] update private submodule and changed install.sh to use private/install.sh instead of Rakefile --- install.sh | 5 ++--- private | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index c370bf0..932ba30 100755 --- a/install.sh +++ b/install.sh @@ -21,9 +21,8 @@ install_symlinks () { symlink "$ROOT_PATH" "$TARGET/$DOTFILES_LINK" # Setup private dotfiles - local private_rakefile="$ROOT_PATH/$PRIVATE_PATH/Rakefile" - if [ -f "$private_rakefile" ]; then - rake --rakefile="$private_rakefile" symlink + if [ -f "$ROOT_PATH/$PRIVATE_PATH/install.sh" ]; then + "$ROOT_PATH/$PRIVATE_PATH/install.sh" links fi # Symlink each path diff --git a/private b/private index f2c2d3e..b1a1019 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit f2c2d3e55fb1588d529fd7650bd625fea7a774a2 +Subproject commit b1a10190408a8e35123ee834c2e3b2f680e2eff6 From 2e7df17ab9d39a4b968a6644d7c359f7fc00dd0f Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 8 Feb 2012 14:43:45 +0000 Subject: [PATCH 5/5] removed Rakefile, install.sh does all it used to do --- Gemfile | 3 -- Gemfile.lock | 10 ------ Rakefile | 87 ---------------------------------------------------- 3 files changed, 100 deletions(-) delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 Rakefile diff --git a/Gemfile b/Gemfile deleted file mode 100644 index b3d4bf6..0000000 --- a/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'http://rubygems.org/' - -gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 3b9cde2..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,10 +0,0 @@ -GEM - remote: http://rubygems.org/ - specs: - rake (0.9.2.2) - -PLATFORMS - ruby - -DEPENDENCIES - rake diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 0a9f889..0000000 --- a/Rakefile +++ /dev/null @@ -1,87 +0,0 @@ -# encoding: utf-8 - -$HOME = File.expand_path(ENV['HOME'] || '~') -$DOTFILES = File.expand_path('..', __FILE__) -$DOTPFILES = "#{$DOTFILES}/private" - -desc "Create all symlinks in home folder (#{$HOME})" -task :symlink => 'symlink:all' -task :link => 'symlink:all' - -namespace :symlink do - - # Paths to symlink from dotfiles - paths = [ - 'bundle', 'emacs.d', 'erlang', 'gemrc', 'gitconfig', 'gitignore', - 'hgrc', 'irbrc', 'powconfig', 'rspec', 'tmux.conf' - ] - - # Target directory to put symlinks in (defaults to home folder). - target = File.expand_path(ENV["TARGET"] ? ENV["TARGET"] : $HOME) - - task :dotfiles do - link_paths($DOTFILES, "#{target}/.dotfiles") - end - - desc "Execute \"rake symlink\" in #{$DOTPFILES}" - task :private do - system "rake --rakefile=\"#{$DOTPFILES}/Rakefile\" symlink" - end - - task :all => ["symlink:private", "symlink:paths", "symlink:shell_loaders"] - - task :paths => :dotfiles do - paths.each do |path| - link_paths(".dotfiles/#{path}", "#{target}/.#{path}") - end - end - - task :shell_loaders => :dotfiles do - link_paths(".dotfiles/load_shellrc.sh", "#{target}/.profile") - link_paths(".dotfiles/load_shellrc.sh", "#{target}/.zprofile") - end -end - -namespace :install do - desc "Install Homebrew" - task :homebrew do - system '/usr/bin/ruby -e ' + - '"$(curl -fsSL https://raw.github.com/gist/323731)"' - end - - desc "Install rbenv to #{$HOME}/.rbenv" - task :rbenv do - target = File.join($HOME, '.rbenv') - git_clone('git://github.com/sstephenson/rbenv.git', target) - end - - desc "Install nvm to #{$HOME}/.nvm" - task :nvm do - target = File.join($HOME, '.nvm') - git_clone('https://github.com/creationix/nvm.git', target) - end - - desc "Install virtualenv-burrito" - task :virtualenv do - system 'curl -s https://raw.github.com/brainsik/virtualenv-burrito/' + - 'master/virtualenv-burrito.sh | bash' - end -end - - -def link_paths(src, to) - if !File.exists?(to) - puts " symlink: #{to} --> #{src}" - File.symlink(src, to) - else - puts " exists: #{to}" - end -end - -def git_clone(repo, target) - if File.exist?(target) - puts "#{target} already exists." - else - system "git clone \"#{repo}\" \"#{target}\"" - end -end