You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. #!/usr/bin/env bash
  2. #
  3. # A script to convert the local system to use my dotfiles my local dotfiles over
  4. # the provided ones already on the system. This script will backup any of the
  5. # existing dot files, before linking to the ones in this repository.
  6. #
  7. # Helper Functions
  8. # Make a backup of the existing file if it exists
  9. # Then link to our supplied dotfile
  10. link() {
  11. # Only make a backup if an existing file is there and is not a link
  12. if [ -f "$1/$2" ] && [ ! -L "$1/$2" ]; then
  13. cp "$1/$2" "$1/$2.old"
  14. echo "Backed up original $2 to $1/$2.old"
  15. fi
  16. ln -sf "$PWD/$3" "$1/$2"
  17. }
  18. link_dir() {
  19. # Only make a backup if an existing directory is there and is not a link
  20. if [ -d "$1/$2" ] && [ ! -L "$1/$2" ]; then
  21. mv "$1/$2" "$1/$2.old"
  22. echo "Backed up original $2 to $1/$2.old"
  23. fi
  24. # Don't overwrite links
  25. if [ ! -L "$1/$2" ]; then
  26. echo "ln -sf $3 $1/$2"
  27. ln -sf "$3" "$1/$2"
  28. fi
  29. }
  30. set -x
  31. set -e
  32. # Configure .vimrc
  33. link "$HOME" ".vimrc" "vimrc"
  34. # Download pathogen if it doesn't exist already
  35. VIM_AUTOLOAD=$HOME/.vim/autoload
  36. mkdir -p $VIM_AUTOLOAD
  37. if [ ! -f "$VIM_AUTOLOAD/pathogen.vim" ]; then
  38. curl -LSso $VIM_AUTOLOAD/pathogen.vim https://tpo.pe/pathogen.vim
  39. fi
  40. # Configure Pathogen Plugins
  41. VIM_BUNDLE=$HOME/.vim/bundle
  42. mkdir -p $VIM_BUNDLE
  43. plugins=($(ls -d $PWD/.vim/bundle/* | tr -s ' '))
  44. echo "${plugins[@]}"
  45. for plugin in ${plugins[@]}; do
  46. parts=($(echo "$plugin" | tr '/' ' '))
  47. plugin_name=${parts[-1]}
  48. echo "$VIM_BUNDLE $plugin_name $plugin"
  49. link_dir $VIM_BUNDLE $plugin_name $plugin
  50. done
  51. # Configure .gitconfig
  52. link "$HOME" ".gitconfig" "gitconfig"
  53. # Configure .zshrc
  54. link "$HOME" ".zshrc" "zshrc"
  55. # Create an auto updater for the dotfiles
  56. if [ ! -f "$HOME/.update_dotfiles.sh" ]; then
  57. echo "#!/usr/bin/env sh" > $HOME/.update_dotfiles.sh
  58. echo "echo 'Updating dotfiles'" >> $HOME/.update_dotfiles.sh
  59. echo "cd $PWD" >> $HOME/.update_dotfiles.sh
  60. echo "git checkout master" >> $HOME/.update_dotfiles.sh
  61. echo "git pull" >> $HOME/.update_dotfiles.sh
  62. echo "git submodule init" >> $HOME/.update_dotfiles.sh
  63. echo "git submodule update" >> $HOME/.update_dotfiles.sh
  64. chmod +x $HOME/.update_dotfiles.sh
  65. fi