setup.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/bin/sh
  2. # Setup Script - Modeline and Notes {{{
  3. # vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
  4. #
  5. # Automated Setup Script - cinaeco/dotfiles
  6. #
  7. # This script creates appropriate symlinks in the home folder and pulls
  8. # extra software and plugins where available.
  9. #
  10. # Run from where it's located within dotfiles directory i.e. `./setup.sh`
  11. #
  12. # }}}
  13. # Script Helper Functions {{{
  14. #
  15. # These are mostly taken from spf13-vim. They are primarily here to setup
  16. # vundle beforehand, to avoid the chicken-and-egg issue.
  17. #
  18. debug_mode='0'
  19. lnif() {
  20. if [ -e "$1" ]; then
  21. ln -sf "$1" "$2"
  22. fi
  23. ret="$?"
  24. debug
  25. }
  26. msg() {
  27. printf '%b\n' "$1" >&2
  28. }
  29. success() {
  30. if [ "$ret" -eq '0' ]; then
  31. msg "\e[32m[✔]\e[0m ${1}${2}"
  32. fi
  33. }
  34. debug() {
  35. if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
  36. msg "An error occured in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
  37. fi
  38. }
  39. upgrade_repo() {
  40. msg "trying to update $1"
  41. if [ "$1" = "$app_name" ]; then
  42. cd "$HOME/.$app_name-3" &&
  43. git pull origin "$git_branch"
  44. fi
  45. if [ "$1" = "vundle" ]; then
  46. cd "$HOME/.vim/bundle/vundle" &&
  47. git pull origin master
  48. fi
  49. ret="$?"
  50. success "$2"
  51. debug
  52. }
  53. create_vimlinks() {
  54. dotfilesvim="$HOME/dotfiles/vim"
  55. if [ ! -d "$HOME/.cinaeco-vim" ]; then
  56. mkdir -p "$HOME/.cinaeco-vim"
  57. fi
  58. endpath="$HOME/.cinaeco-vim"
  59. if [ ! -d "$endpath/.vim/bundle" ]; then
  60. mkdir -p "$endpath/.vim/bundle"
  61. fi
  62. lnif "$dotfilesvim/vimrc" "$HOME/.vimrc"
  63. lnif "$dotfilesvim/vimrc.bundles" "$HOME/.vimrc.bundles"
  64. lnif "$endpath/.vim" "$HOME/.vim"
  65. ret="$?"
  66. success "$1"
  67. debug
  68. }
  69. clone_vundle() {
  70. if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
  71. git clone https://github.com/gmarik/vundle.git "$HOME/.vim/bundle/vundle"
  72. else
  73. upgrade_repo "vundle" "Successfully updated vundle"
  74. fi
  75. ret="$?"
  76. success "$1"
  77. debug
  78. }
  79. setup_vundle() {
  80. system_shell="$SHELL"
  81. export SHELL='/bin/sh'
  82. vim -u "$HOME/.vimrc.bundles" +BundleInstall! +BundleClean +qall
  83. export SHELL="$system_shell"
  84. success "$1"
  85. debug
  86. }
  87. # }}}
  88. # Make known_hosts file if none {{{
  89. #
  90. # Otherwise, zsh throws an error for our .zshrc
  91. #
  92. if test -f ~/.ssh/known_hosts; then
  93. ret="$?"
  94. success "File 'known_hosts' found"
  95. else
  96. mkdir -p ~/.ssh
  97. touch ~/.ssh/known_hosts
  98. ret="$?"
  99. success "File 'known_hosts' created (blank)"
  100. fi
  101. # }}}
  102. # Get the ack search tool {{{
  103. #
  104. # Requires perl 5.8.8 or higher. Curl may need to have proxy settings.
  105. #
  106. if test -f ~/bin/ack; then
  107. ret="$?"
  108. success "Ack found"
  109. else
  110. mkdir -p ~/bin
  111. curl http://beyondgrep.com/ack-2.04-single-file > ~/bin/ack && chmod 0755 ~/bin/ack
  112. ret="$?"
  113. success "Ack installed from beyondgrep.com"
  114. fi
  115. # }}}
  116. # Git: colorise output, edit with vim {{{
  117. #
  118. # Makes status', diffs and logs much nicer to use.
  119. #
  120. git config --global color.ui true
  121. git config --global core.editor "vim"
  122. success "Git colour and editor setup"
  123. # }}}
  124. # Initialise and clone any submodules {{{
  125. git submodule init
  126. git submodule update
  127. success "Submodules done"
  128. # }}}
  129. # Setup Backup Folder for old configuration files {{{
  130. #
  131. # This way the setup script is pretty non-destructive, and can be run
  132. # repeatedly without bad side effects.
  133. #
  134. BACKUP_DIR="/tmp/$(date)"
  135. mkdir "$BACKUP_DIR"
  136. # }}}
  137. # Zsh {{{
  138. [ -f ~/.zshrc ] && mv ~/.zshrc "$BACKUP_DIR"
  139. [ -f ~/.zshenv ] && mv ~/.zshenv "$BACKUP_DIR"
  140. ln -s dotfiles/zsh/zshrc ~/.zshrc
  141. ln -s dotfiles/zsh/zshenv ~/.zshenv
  142. success "Zsh config linked"
  143. # }}}
  144. # Vimperator {{{
  145. [ -d ~/.vimperator ] && mv ~/.vimperator "$BACKUP_DIR"
  146. [ -f ~/.vimperatorrc ] && mv ~/.vimperatorrc "$BACKUP_DIR"
  147. ln -s dotfiles/vimperator ~/.vimperator
  148. ln -s dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
  149. success "Vimperator config linked"
  150. # }}}
  151. # Screen {{{
  152. [ -f ~/.screenrc ] && mv ~/.screenrc "$BACKUP_DIR"
  153. ln -s dotfiles/screen/screenrc ~/.screenrc
  154. success "Screen config linked"
  155. # }}}
  156. # Tmux {{{
  157. [ -f ~/.tmux.conf ] && mv ~/.tmux.conf "$BACKUP_DIR"
  158. ln -s dotfiles/tmux/tmux.conf ~/.tmux.conf
  159. success "Tmux config linked"
  160. # }}}
  161. # Powerline {{{
  162. # `.config` is a shared config location, so take more care
  163. [ -d ~/.config/powerline ] && mv ~/.config/powerline "$BACKUP_DIR"
  164. [ ! -d ~/.config ] && mkdir ~/.config
  165. ln -s ../dotfiles/powerline/config ~/.config/powerline
  166. success "Powerline config linked"
  167. # }}}
  168. # Nethack {{{
  169. [ -f ~/.nethackrc ] && mv ~/.nethackrc "$BACKUP_DIR"
  170. ln -s dotfiles/nethack/nethackrc ~/.nethackrc
  171. success "Nethack config linked"
  172. # }}}
  173. # Irssi {{{
  174. [ -d ~/.irssi ] && mv ~/.irssi "$BACKUP_DIR"
  175. ln -s dotfiles/irssi ~/.irssi
  176. success "Irssi config linked"
  177. # }}}
  178. # Mongo {{{
  179. [ -f ~/.mongorc.js ] && mv ~/.mongorc.js "$BACKUP_DIR"
  180. ln -s dotfiles/mongo/mongorc.js ~/.mongorc.js
  181. success "Mongo config linked"
  182. # }}}
  183. # Sqlite {{{
  184. [ -f ~/.sqliterc ] && mv ~/.sqliterc "$BACKUP_DIR"
  185. ln -s dotfiles/sqlite/sqliterc ~/.sqliterc
  186. success "Sqlite config linked"
  187. # }}}
  188. # Ack {{{
  189. [ -f ~/.ackrc ] && mv ~/.ackrc "$BACKUP_DIR"
  190. ln -s dotfiles/ack/ackrc ~/.ackrc
  191. success "Ack config linked"
  192. # }}}
  193. # Emacs {{{
  194. [ -f ~/.emacs ] && mv ~/.emacs "$BACKUP_DIR"
  195. ln -s dotfiles/emacs/emacs ~/.emacs
  196. success "Emacs config linked"
  197. # }}}
  198. # ZFS {{{
  199. [ -f ~/bin/destroy-zfs-auto-snaps ] && mv ~/.vimrc "$BACKUP_DIR"
  200. ln -s ../dotfiles/zfs/destroy-zfs-auto-snaps ~/bin
  201. success "ZFS utilities installed"
  202. # }}}
  203. # Vim {{{
  204. [ -d ~/.vim ] && mv ~/.vim "$BACKUP_DIR"
  205. [ -f ~/.vimrc ] && mv ~/.vimrc "$BACKUP_DIR"
  206. [ -f ~/.vimrc.bundles ] && mv ~/.vimrc.bundles "$BACKUP_DIR"
  207. create_vimlinks "Setting up vim symlinks"
  208. clone_vundle "Successfully cloned vundle"
  209. setup_vundle "Now updating/installing plugins using Vundle"
  210. # }}}
  211. # Success {{{
  212. ret="$?"
  213. success "Setup complete!"
  214. # }}}