Skip to content

Instantly share code, notes, and snippets.

@haldean
Created May 11, 2011 00:35
Show Gist options
  • Save haldean/965681 to your computer and use it in GitHub Desktop.
Save haldean/965681 to your computer and use it in GitHub Desktop.
Bootstrap new Linux and OSX systems with my dotfiles and packages
#!/bin/bash
GITREPO=ssh://haldean@haldean.org/srv/dotfiles.git
APT_PACKAGES='emacs awesome zsh biblatex texlive-latex-extra emacs-goodies-el'
BREW_PACKAGES=
cd
HOMEDIR=`pwd`
GITDIR=$HOMEDIR/.dotfiles
esc=""
green() {
echo "${esc}[32m$1"
tput sgr0
}
red() {
echo "${esc}[31m$1"
tput sgr0
}
plain() {
echo "${esc}[0m$1"
tput sgr0
}
if which apt-get &> /dev/null; then
green "Installing $APT_PACKAGES"
sudo apt-get install $APT_PACKAGES
elif [ `uname` == "Darwin" ]; then
if ! which brew &> /dev/null; then
green 'Installing Homebrew.'
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
fi
if which brew &> /dev/null -a $BREW_PACKAGES; then
green "Installing $BREW_PACKAGES"
brew install $BREW_PACKAGES
elif [ -z $BREW_PACKAGES ]; then
plain 'No Brew packages specified. Skipping.'
else
red 'Failed to install Homebrew.'
fi
else
echo 'No apt-get or Homebrew detected. Skipping package installation.'
fi
if [ ! -d $GITDIR ]; then
green "Cloning git repository $GITREPO to $GITDIR"
git clone $GITREPO $GITDIR
else
green "Dotfile directory exists."
if [ ! -d $GITDIR/.git ]; then
red $GITDIR is not a Git repository. Change GITDIR in the script to \
choose where to check out the dotfiles repository.
exit -1
fi
green "$GITDIR is a Git repository. Refreshing the repository now..."
cd $GITDIR
git pull origin master
fi
cd $GITDIR
for file in `ls -1A`; do
if [ "$file" != ".git" ]; then
echo
green "Creating link for $file"
if [ -e $HOMEDIR/$file ]; then
if [ -L $HOMEDIR/$file ]; then
red "Removing existing link. (Old link went to $(readlink $HOMEDIR/$file))"
rm $HOMEDIR/$file
else
bkup=$file.prebootstrap
red "$HOMEDIR/$file exists. Backing up to $bkup and replacing."
mv $HOMEDIR/$file $HOME/$bkup
fi
fi
ln -s $GITDIR/$file $HOMEDIR/
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment