| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- #!/bin/sh
- # Setup Script - Modeline and Notes {{{
- # vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
- #
- # Automated Setup Script - cinaeco/dotfiles
- #
- # This script creates appropriate symlinks in the home folder and pulls
- # extra software and plugins where available.
- #
- # Run from where it's located within dotfiles directory i.e. `./setup.sh`
- #
- # }}}
- # Script Helper Functions {{{
- #
- # These are mostly taken from spf13-vim. They are primarily here to setup
- # vundle beforehand, to avoid the chicken-and-egg issue.
- #
- debug_mode='0'
- lnif() {
- if [ -e "$1" ]; then
- ln -sf "$1" "$2"
- fi
- ret="$?"
- debug
- }
- msg() {
- printf '%b\n' "$1" >&2
- }
- success() {
- if [ "$ret" -eq '0' ]; then
- msg "\e[32m[✔]\e[0m ${1}${2}"
- fi
- }
- debug() {
- if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
- msg "An error occured in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
- fi
- }
- upgrade_repo() {
- msg "trying to update $1"
- if [ "$1" = "$app_name" ]; then
- cd "$HOME/.$app_name-3" &&
- git pull origin "$git_branch"
- fi
- if [ "$1" = "vundle" ]; then
- cd "$HOME/.vim/bundle/vundle" &&
- git pull origin master
- fi
- ret="$?"
- success "$2"
- debug
- }
- create_vimlinks() {
- dotfilesvim="$HOME/dotfiles/vim"
- if [ ! -d "$HOME/.cinaeco-vim" ]; then
- mkdir -p "$HOME/.cinaeco-vim"
- fi
- endpath="$HOME/.cinaeco-vim"
- if [ ! -d "$endpath/.vim/bundle" ]; then
- mkdir -p "$endpath/.vim/bundle"
- fi
- lnif "$dotfilesvim/vimrc" "$HOME/.vimrc"
- lnif "$dotfilesvim/vimrc.bundles" "$HOME/.vimrc.bundles"
- lnif "$endpath/.vim" "$HOME/.vim"
- ret="$?"
- success "$1"
- debug
- }
- clone_vundle() {
- if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
- git clone https://github.com/gmarik/vundle.git "$HOME/.vim/bundle/vundle"
- else
- upgrade_repo "vundle" "Successfully updated vundle"
- fi
- ret="$?"
- success "$1"
- debug
- }
- setup_vundle() {
- system_shell="$SHELL"
- export SHELL='/bin/sh'
- vim -u "$HOME/.vimrc.bundles" +BundleInstall! +BundleClean +qall
- export SHELL="$system_shell"
- success "$1"
- debug
- }
- # }}}
- # Make known_hosts file if none {{{
- #
- # Otherwise, zsh throws an error for our .zshrc
- #
- if test -f ~/.ssh/known_hosts; then
- ret="$?"
- success "File 'known_hosts' found"
- else
- mkdir -p ~/.ssh
- touch ~/.ssh/known_hosts
- ret="$?"
- success "File 'known_hosts' created (blank)"
- fi
- # }}}
- # Get the ack search tool {{{
- #
- # Requires perl 5.8.8 or higher. Curl may need to have proxy settings.
- #
- if test -f ~/bin/ack; then
- ret="$?"
- success "Ack found"
- else
- mkdir -p ~/bin
- curl http://beyondgrep.com/ack-2.04-single-file > ~/bin/ack && chmod 0755 ~/bin/ack
- ret="$?"
- success "Ack installed from beyondgrep.com"
- fi
- # }}}
- # Git: colorise output, edit with vim {{{
- #
- # Makes status', diffs and logs much nicer to use.
- #
- git config --global color.ui true
- git config --global core.editor "vim"
- success "Git colour and editor setup"
- # }}}
- # Initialise and clone any submodules {{{
- git submodule init
- git submodule update
- success "Submodules done"
- # }}}
- # Setup Backup Folder for old configuration files {{{
- #
- # This way the setup script is pretty non-destructive, and can be run
- # repeatedly without bad side effects.
- #
- BACKUP_DIR="/tmp/$(date)"
- mkdir "$BACKUP_DIR"
- # }}}
- # Zsh {{{
- [ -f ~/.zshrc ] && mv ~/.zshrc "$BACKUP_DIR"
- [ -f ~/.zshenv ] && mv ~/.zshenv "$BACKUP_DIR"
- ln -s dotfiles/zsh/zshrc ~/.zshrc
- ln -s dotfiles/zsh/zshenv ~/.zshenv
- success "Zsh config linked"
- # }}}
- # Vimperator {{{
- [ -d ~/.vimperator ] && mv ~/.vimperator "$BACKUP_DIR"
- [ -f ~/.vimperatorrc ] && mv ~/.vimperatorrc "$BACKUP_DIR"
- ln -s dotfiles/vimperator ~/.vimperator
- ln -s dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
- success "Vimperator config linked"
- # }}}
- # Screen {{{
- [ -f ~/.screenrc ] && mv ~/.screenrc "$BACKUP_DIR"
- ln -s dotfiles/screen/screenrc ~/.screenrc
- success "Screen config linked"
- # }}}
- # Tmux {{{
- [ -f ~/.tmux.conf ] && mv ~/.tmux.conf "$BACKUP_DIR"
- ln -s dotfiles/tmux/tmux.conf ~/.tmux.conf
- success "Tmux config linked"
- # }}}
- # Powerline {{{
- # `.config` is a shared config location, so take more care
- [ -d ~/.config/powerline ] && mv ~/.config/powerline "$BACKUP_DIR"
- [ ! -d ~/.config ] && mkdir ~/.config
- ln -s ../dotfiles/powerline/config ~/.config/powerline
- success "Powerline config linked"
- # }}}
- # Nethack {{{
- [ -f ~/.nethackrc ] && mv ~/.nethackrc "$BACKUP_DIR"
- ln -s dotfiles/nethack/nethackrc ~/.nethackrc
- success "Nethack config linked"
- # }}}
- # Irssi {{{
- [ -d ~/.irssi ] && mv ~/.irssi "$BACKUP_DIR"
- ln -s dotfiles/irssi ~/.irssi
- success "Irssi config linked"
- # }}}
- # Mongo {{{
- [ -f ~/.mongorc.js ] && mv ~/.mongorc.js "$BACKUP_DIR"
- ln -s dotfiles/mongo/mongorc.js ~/.mongorc.js
- success "Mongo config linked"
- # }}}
- # Ack {{{
- [ -f ~/.ackrc ] && mv ~/.ackrc "$BACKUP_DIR"
- ln -s dotfiles/ack/ackrc ~/.ackrc
- success "Ack config linked"
- # }}}
- # Emacs {{{
- [ -f ~/.emacs ] && mv ~/.emacs "$BACKUP_DIR"
- ln -s dotfiles/emacs/emacs ~/.emacs
- success "Emacs config linked"
- # }}}
- # Vim {{{
- [ -d ~/.vim ] && mv ~/.vim "$BACKUP_DIR"
- [ -f ~/.vimrc ] && mv ~/.vimrc "$BACKUP_DIR"
- [ -f ~/.vimrc.bundles ] && mv ~/.vimrc.bundles "$BACKUP_DIR"
- create_vimlinks "Setting up vim symlinks"
- clone_vundle "Successfully cloned vundle"
- setup_vundle "Now updating/installing plugins using Vundle"
- # }}}
- # Success {{{
- ret="$?"
- success "Setup complete!"
- # }}}
|