|
|
@@ -1,248 +1,112 @@
|
|
|
#!/bin/sh
|
|
|
-# Setup Script - Modeline and Notes {{{
|
|
|
+# Setup Script {{{
|
|
|
# vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
|
|
|
#
|
|
|
-# Automated Setup Script - cinaeco/dotfiles
|
|
|
+# Creates links to configuration files in a user's home folder and downloads
|
|
|
+# extra software and plugins.
|
|
|
#
|
|
|
-# 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
|
|
|
#
|
|
|
-# Run from where it's located within dotfiles directory i.e. `./setup.sh`
|
|
|
+# ./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'
|
|
|
+# Support Functions {{{
|
|
|
|
|
|
-# Backup Folder for old configuration files {{{
|
|
|
-#
|
|
|
-# The setup script is non-destructive, and can be run repeatedly - all old
|
|
|
-# config files or symlinks from previous runs can be recovered from
|
|
|
-# timestamped temp folders.
|
|
|
-#
|
|
|
-BACKUP_DIR="/tmp/$(date)"
|
|
|
-mkdir "$BACKUP_DIR"
|
|
|
-# }}}
|
|
|
+# Folder for backing up present configuration files.
|
|
|
+backup_dir="/tmp/$(date)"
|
|
|
+mkdir "$backup_dir"
|
|
|
|
|
|
-# Symlink Attempt
|
|
|
-lnif() {
|
|
|
- if [ -e "$1" ]; then
|
|
|
- ln -sf "$1" "$2"
|
|
|
- fi
|
|
|
- ret="$?"
|
|
|
- debug
|
|
|
-}
|
|
|
-
|
|
|
-# Backup files to backup folder
|
|
|
+# Backup a given file.
|
|
|
backup() {
|
|
|
- [ -f "$1" ] && mv "$1" "$BACKUP_DIR"
|
|
|
- ret="$?"
|
|
|
- debug
|
|
|
+ [ -e "$1" ] && mv "$1" "$backup_dir"
|
|
|
}
|
|
|
|
|
|
-# Backup directories to backup folder
|
|
|
-backup_dir() {
|
|
|
- [ -d "$1" ] && mv "$1" "$BACKUP_DIR"
|
|
|
- ret="$?"
|
|
|
- debug
|
|
|
+# Create links after backing up.
|
|
|
+linkup() {
|
|
|
+ backup "$2"
|
|
|
+ ln -s "$1" "$2"
|
|
|
}
|
|
|
|
|
|
-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]}"
|
|
|
- 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/.tmp-vim" ]; then
|
|
|
- mkdir -p "$HOME/.tmp-vim"
|
|
|
- fi
|
|
|
- vimfolder="$HOME/.tmp-vim"
|
|
|
-
|
|
|
- if [ ! -d "$vimfolder/.vim/bundle" ]; then
|
|
|
- mkdir -p "$vimfolder/.vim/bundle"
|
|
|
- fi
|
|
|
-
|
|
|
- lnif "$dotfilesvim/vimrc" "$HOME/.vimrc"
|
|
|
- lnif "$dotfilesvim/vimrc.bundles" "$HOME/.vimrc.bundles"
|
|
|
- lnif "$vimfolder/.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"
|
|
|
+# Download vim-plug, a vim plugin manager.
|
|
|
+#
|
|
|
+# Also place vim-plug where it can be auto-loaded.
|
|
|
+download_vim_plug() {
|
|
|
+ folder=~/.vim/plugged/vim-plug
|
|
|
+ if [ ! -e $folder ]; then
|
|
|
+ echo "Vim Plugin Manager cloning"
|
|
|
+ git clone https://github.com/junegunn/vim-plug.git $folder --depth 1
|
|
|
else
|
|
|
- upgrade_repo "vundle" "Successfully updated vundle"
|
|
|
+ echo "Vim Plugin Manager updating"
|
|
|
+ cd $folder && git pull
|
|
|
fi
|
|
|
- ret="$?"
|
|
|
- success "$1"
|
|
|
- debug
|
|
|
+ mkdir -p ~/.vim/autoload
|
|
|
+ linkup "$folder/plug.vim" ~/.vim/autoload/plug.vim
|
|
|
}
|
|
|
|
|
|
-setup_vundle() {
|
|
|
- system_shell="$SHELL"
|
|
|
- export SHELL='/bin/sh'
|
|
|
- vim -u "$HOME/.vimrc.bundles" +PluginInstall! +PluginClean! +qall
|
|
|
- export SHELL="$system_shell"
|
|
|
-
|
|
|
- success "$1"
|
|
|
- debug
|
|
|
+# Run vim-plug's install process.
|
|
|
+#
|
|
|
+# Vim is loaded with only the registry of plugins and the `nocompatible` flag.
|
|
|
+install_vim_plugins() {
|
|
|
+ vim -u ~/dotfiles/vim/plugins.vim -N +PlugInstall +PlugClean +qall
|
|
|
}
|
|
|
-# }}}
|
|
|
|
|
|
-# 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
|
|
|
-# }}}
|
|
|
+# Make known_hosts file if none
|
|
|
+mkdir -p ~/.ssh
|
|
|
+touch ~/.ssh/known_hosts
|
|
|
+echo "We touched all the known hosts."
|
|
|
|
|
|
-# Git: colorise output, edit with vim {{{
|
|
|
-#
|
|
|
-# Makes status', diffs and logs much nicer to use.
|
|
|
-#
|
|
|
+# Git config
|
|
|
git config --global color.ui true
|
|
|
git config --global core.editor "vim"
|
|
|
-success "Git colour and editor setup"
|
|
|
-# }}}
|
|
|
+echo "Git config done."
|
|
|
|
|
|
-# Initialise and clone any submodules {{{
|
|
|
+# Initialise and clone any submodules
|
|
|
git submodule sync
|
|
|
git submodule update --init
|
|
|
-success "Submodules done"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Zsh {{{
|
|
|
-backup ~/.zshrc
|
|
|
-backup ~/.zshenv
|
|
|
-lnif ~/dotfiles/zsh/zshrc ~/.zshrc
|
|
|
-lnif ~/dotfiles/zsh/zshenv ~/.zshenv
|
|
|
-success "Zsh config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Vimperator {{{
|
|
|
-backup_dir ~/.vimperator
|
|
|
-backup ~/.vimperatorrc
|
|
|
-lnif ~/dotfiles/vimperator ~/.vimperator
|
|
|
-lnif ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
|
|
|
-success "Vimperator config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Screen {{{
|
|
|
-backup ~/.screenrc
|
|
|
-lnif ~/dotfiles/screen/screenrc ~/.screenrc
|
|
|
-success "Screen config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Tmux {{{
|
|
|
-backup ~/.tmux.conf
|
|
|
-lnif ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
|
|
|
-success "Tmux config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Powerline {{{
|
|
|
-# `.config` is a shared config location, so take more care
|
|
|
-backup_dir ~/.config/powerline
|
|
|
-[ ! -d ~/.config ] && mkdir ~/.config
|
|
|
-lnif ~/dotfiles/powerline/config ~/.config/powerline
|
|
|
-success "Powerline config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Irssi {{{
|
|
|
-backup_dir ~/.irssi
|
|
|
-lnif ~/dotfiles/irssi ~/.irssi
|
|
|
-success "Irssi config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Ack {{{
|
|
|
-backup ~/.ackrc
|
|
|
-lnif ~/dotfiles/ack/ackrc ~/.ackrc
|
|
|
-success "Ack config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Emacs {{{
|
|
|
-backup ~/.emacs
|
|
|
-lnif ~/dotfiles/emacs/emacs ~/.emacs
|
|
|
-success "Emacs config linked"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# ZFS {{{
|
|
|
-backup ~/bin/destroy-zfs-auto-snaps
|
|
|
-lnif ~/dotfiles/zfs/destroy-zfs-auto-snaps ~/bin
|
|
|
-success "ZFS utilities installed"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Vim {{{
|
|
|
-backup_dir ~/.vim
|
|
|
-backup ~/.vimrc
|
|
|
-backup ~/.vimrc.bundles
|
|
|
-create_vimlinks "Setting up vim symlinks"
|
|
|
-clone_vundle "Successfully cloned vundle"
|
|
|
-setup_vundle "Now updating/installing plugins using Vundle"
|
|
|
-# }}}
|
|
|
-
|
|
|
-# Success {{{
|
|
|
-ret="$?"
|
|
|
-success "Setup complete!"
|
|
|
-# }}}
|
|
|
+echo "Submodules done."
|
|
|
+
|
|
|
+# Zsh
|
|
|
+linkup ~/dotfiles/zsh/zshrc ~/.zshrc
|
|
|
+linkup ~/dotfiles/zsh/zshenv ~/.zshenv
|
|
|
+echo "Zsh linked."
|
|
|
+
|
|
|
+# Vimperator
|
|
|
+linkup ~/dotfiles/vimperator ~/.vimperator
|
|
|
+linkup ~/dotfiles/vimperator/vimperatorrc ~/.vimperatorrc
|
|
|
+echo "Vimperator linked."
|
|
|
+
|
|
|
+# Screen
|
|
|
+linkup ~/dotfiles/screen/screenrc ~/.screenrc
|
|
|
+echo "Screen linked."
|
|
|
+
|
|
|
+# Tmux
|
|
|
+linkup ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
|
|
|
+echo "Tmux linked."
|
|
|
+
|
|
|
+# Irssi
|
|
|
+linkup ~/dotfiles/irssi ~/.irssi
|
|
|
+echo "Irssi linked."
|
|
|
+
|
|
|
+# Ack
|
|
|
+linkup ~/dotfiles/ack/ackrc ~/.ackrc
|
|
|
+echo "Ack linked."
|
|
|
+
|
|
|
+# Powerline
|
|
|
+mkdir -p ~/.config
|
|
|
+linkup ~/dotfiles/powerline/config ~/.config/powerline
|
|
|
+echo "Powerline linked."
|
|
|
+
|
|
|
+# Vim (and NeoVim)
|
|
|
+linkup ~/dotfiles/vim/vimrc ~/.vimrc
|
|
|
+linkup ~/dotfiles/vim/vimrc ~/.nvimrc
|
|
|
+mkdir -p ~/.vim-tmp
|
|
|
+linkup ~/.vim-tmp ~/.vim
|
|
|
+linkup ~/.vim-tmp ~/.nvim
|
|
|
+download_vim_plug
|
|
|
+install_vim_plugins
|
|
|
+echo "Vim linked."
|
|
|
+
|
|
|
+echo "Setup complete!"
|