From e3a3288b83cd06ddd56cf6afbafa305d1bcdff3d Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 27 May 2017 15:32:37 -0500 Subject: [PATCH] fixed up install script --- .gitignore | 1 + install.sh | 75 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec76ec2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +backup diff --git a/install.sh b/install.sh index 3d4ec9b..e668b14 100755 --- a/install.sh +++ b/install.sh @@ -1,37 +1,74 @@ #!/usr/bin/env bash -BACKUP_DIR="$HOME/.dotfiles_backup" -BASE_DIR="$HOME/.dotfiles" -INCLUDE=".bashrc .bash_profile .vimrc .vim .screenrc .tmux.conf" +home="$HOME" +base_dir="$home/.dotfiles" +backup_dir="$home/.dotfiles/backup" +vim_plugins_dir="$home/.vim/bundle" +vundle_dir="$vim_plugins_dir/Vundle.vim" +include=( + .bash_profile + .bashrc + .screenrc + .tmux.conf + .vim/ftplugin/*.vim + .vimrc +) -if [[ -d "$BACKUP_DIR" ]] ; then - echo "removing previous backup at $BACKUP_DIR" - rm -rf "$BACKUP_DIR" +if [[ -d "$backup_dir" ]] ; then + echo "removing previous backup at $backup_dir" + rm -rf "$backup_dir" fi -echo "backing up existing dotfiles into $BACKUP_DIR" -mkdir -p "$BACKUP_DIR" -for FNAME in $INCLUDE; do +echo "backing up existing dotfiles into $backup_dir" +mkdir -p "$backup_dir" +for filename in ${include[@]}; do + source_path="$base_dir/$filename" + dest_path="$home/$filename" + backup_path="$backup_dir/$filename" + echo "file name: $filename" + echo "source path: $source_path" + echo "dest path: $dest_path" + echo "backup path: $backup_path" + # if a file doesn't actually exist in the repo, do nothing. - if [[ ! -a "$BASE_DIR/$FNAME" ]]; then - echo "WARNING: file $BASE_DIR/$FNAME does not exist" + if [[ ! -a "$source_path" ]]; then + echo "no file found at source path $source_path, skipping" continue fi # back up existing dotfiles, just for safety - FULLPATH="$HOME/$FNAME" - if [[ -a "$FULLPATH" && ! -h "$FULLPATH" ]]; then - echo "mv $FULLPATH -> $BACKUP_DIR/$FNAME" - mv "$FULLPATH" "$BACKUP_DIR/$FNAME" + if [[ -a "$dest_path" ]]; then + if [[ -h "$dest_path" ]]; then + # existing file is a symlink. delete it. + echo "removing old link at $dest_path" + rm "$dest_path" + else + # existing file is an original preferences file. archive it. + if [[ ! -d $(dirname "$backup_path") ]]; then + mkdir -pv $(dirname "$backup_path") + fi + echo "archiving old preferences file at $dest_path" + mv -v "$dest_path" "$backup_path" + echo "ok we archived it" + fi fi # symlink in the versioned dotfiles. - echo "ln $BASE_DIR/$FNAME" "$HOME/$FNAME" - ln -sf "$BASE_DIR/$FNAME" "$HOME/$FNAME" + echo "linking preferences file" + ln -sv "$source_path" "$dest_path" + echo "ok we linked it" + echo "--------------------------------------------------------------------------------" done +if [[ ! -d "$vim_plugins_dir" ]]; then + mkdir -p "$vim_plugins_dir" +fi + # setup Vundle -echo "cloning Vundle" -git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim +if [[ ! -d $vundle_dir ]]; then + echo "cloning Vundle" + git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim +fi + echo "installing Vim plugins" vim +PluginInstall +qall