dotfiles/install.sh

190 lines
6.6 KiB
Bash
Executable File

#!/bin/bash
## brethil's dotfiles installation file
## 20 June 2016
# Get the location for the dotfiles
DOTFILES=$PWD
echo -e "\n\n# Beginning of brethil's dotfiles:" >> ~/.zshrc
echo "DOTFILES=$DOTFILES" >> ~/.zshrc
echo "source \$DOTFILES/brethil_dotfile.sh" >> ~/.zshrc
function install_rmate {
## Ruby version:
#curl -Lo ~/bin/rmate https://raw.github.com/textmate/rmate/master/bin/rmate
## Python version:
echo "Installing rmate (python)..."
if [[ $(whoami) == "root" ]]; then
destpath="/usr/bin"
else
destpath="$HOME/bin"
fi
curl -sL https://raw.githubusercontent.com/sclukey/rmate-python/master/bin/rmate >> $destpath/rmate
chmod a+x $destpath/rmate
ln -s $destpath/rmate $destpath/mate || "Could not create symbolic link to $destpath/mate (already exists?)"
echo "Installed rmate (and mate symlink) in $destpath"
}
function install_vimrc {
git clone https://github.com/amix/vimrc.git $HOME/.vim_runtime
sh $HOME/.vim_runtime/install_awesome_vimrc.sh
}
function install_zsh_plugins {
# Install fast-syntax-highlighting zsh-autosuggestions
ZSH_PLUGINS="$HOME/.oh-my-zsh/custom/plugins"
git clone https://github.com/zdharma/fast-syntax-highlighting.git ${ZSH_PLUGINS}/fast-syntax-highlighting
git clone git://github.com/zsh-users/zsh-autosuggestions ${ZSH_PLUGINS}/zsh-autosuggestions
}
# Add an ssh config file with:
# - Connection multiplexer for faster multiple connections
# - Keep connections alive (avoid timeout disconnections)
function create_ssh_config {
echo "# Configuring ssh..."
ssh_config="$HOME/.ssh/config"
if [ ! -d $HOME/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096
chmod 0700 "$HOME/.ssh"
fi
if [[ -f $ssh_config ]]; then
while [ "$modifyssh" != "y" ] && [ "$modifyssh" != "n" ]
do
echo "Do you want to modify the existing ssh config? (New values will be appended) (y/n)"
read modifyssh
done
fi
if [[ "$modifyssh" != "n" ]]
then
echo "# brethil's dotfiles setup start" >> $ssh_config
echo 'TCPKeepAlive=yes' >> $ssh_config
echo 'ServerAliveCountMax=6' >> $ssh_config
## Compression will slow things down when copying large files, but improve
## speed if only using a shell, my reccommendation is to enable it on a by-host
## basis in ~/.ssh/config
#echo ' Compression=yes' >> $ssh_config
#echo 'ControlMaster auto' >> $ssh_config
#echo 'ControlPath /tmp/%r@%h:%p' >> $ssh_config
#echo 'ControlPersist yes' >> $ssh_config
echo 'Host *' >> $ssh_config
echo 'ServerAliveInterval 300' >> $ssh_config
echo '# end of brethil dotfiles setup #' >> $ssh_config
## Enable the following if you want to use the rmate textmate remote
#echo "Host *" >> $ssh_config
#echo "RemoteForward 52698 localhost:52698" >> $ssh_config
## Enable the following if you want to use a reverse ssh tunnel (mecp)
#echo "Host *" >> $ssh_config
#echo "Remoteforward 2222 localhost:22" >> $ssh_config
#
echo ".ssh folder configured, enabled ControlMaster for all connections."
echo "Compression disabled, enable by uncommenting 'Compression' in ~/.ssh/config"
echo "Remote forwarding port 52698->52698 (Textmate) and port 2222->22 (mecp) for all hosts."
else
echo "Did not modify $ssh_config."
fi
echo "# End of ssh config."
}
# Run after first copying to a remote machine
function brethil_dotfiles_setup {
bin="$HOME/bin/"
#python="$HOME/python"
projects="$HOME/projects"
git="$HOME/git"
mkdir -p "$bin"
mkdir -p "$projects"
mkdir -p "$git"
echo "Created dirs $bin, $projects, $git"
# Install packages
# zsh
# byobu: configuration/wrapper for tmux
# grc: generic colourizer, colors output of any command
# bmon: bandwidth monitor, monitors bandwith usage, shows graph
# mtr: mytraceroute, traceroute tool
# pv: pipe view, monitor the progress of data through a pipe
# byobu: tmux wrapper
packages="zsh git grc bmon mtr pv tmux byobu"
# Check if running as root, if not, quit.
if [[ ! $(id -g) == 0 ]]; then
echo "This has to be run as root to install new software from the repos. Quitting..."
exit 0
fi
if [[ $(which apt-get ) ]]; then
install_command="apt-get install"
elif [[ $(which pacman) ]]; then
install_command="pacman -Sy"
elif [[ $(which yum) ]]; then
install_command="yum"
elif [[ $(which port) ]]; then
install_command="port install"
elif [[ $(which brew) ]]; then
install_command="brew install"
else
echo "Could not install required packages"
error=true
fi
if [[ ! $error ]]; then
$install_command $packages
# Install oh-my-zsh
echo "Installing oh-my-zsh..."
sh -c "$(curl -sL zsh.dioporc.one)"
## Fix scrolling in byobu
sed -i 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux
echo "bind m setw -g mode-mouse on" >> ~/.tmux.conf
echo "bind M setw -g mode-mouse off" >> ~/.tmux.conf
fi
# Install the rmate client for textmate
install_rmate
# Install vim awesomerc (git amix/vimrc)
install_vimrc
# Create ssh config
create_ssh_config
# Install new zsh plugins in $ZSH/custom/plugins/
install_zsh_plugins
# Comment enabled plugins in ~/.zshrc
sed -e '/plugins=\(\.*\)/ s/^#*/#/' -i $HOME/.zshrc
# Enable these plugins:
plugins="plugins=(git common-aliases fast-syntax-highlighting zsh-autosuggestions colored-man-pages)"
echo $plugins >> $HOME/.zshrc
# Copy brethil.zsh-theme
ln -s $DOTFILES/brethil.zsh-theme $HOME/.oh-my-zsh/themes/
# Set brethil theme
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc
}
# Setup
brethil_dotfiles_setup
echo "Functions are defined in $DOTFILES/functions.sh (you can add extra functions in ~/.dotfiles_functions)"
echo "Aliases are defined in $DOTFILES/aliases.sh (you can add extra aliases in ~/.dotfiles_aliases)"
echo "Colors are defined in $DOTFILES/colors.sh"
echo "These 3 files are sourced by $DOTFILES/brethil_dotfile.sh, which is in turn sourced by ~/.zshrc"
echo "Type . ~/.zshrc to source the new dotfiles, or simply launch another shell."