1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-24 20:41:31 +01:00
dotfiles/install.sh

252 lines
9.0 KiB
Bash
Raw Normal View History

2017-06-12 16:22:05 +02:00
#!/bin/bash
## brethil's dotfiles installation file
## 20 June 2016
# Get the location for the dotfiles
DOTFILES=$PWD
2017-07-14 21:20:20 +02:00
ZSHTMP="$HOME/.zshrctmp"
echo -e "\n\n# brethil's dotfiles:" >> $ZSHTMP
echo "DOTFILES=$DOTFILES" >> $ZSHTMP
echo "source \$DOTFILES/brethil_dotfile.sh" >> $ZSHTMP
echo -e "# End of brethil's dotfiles\n\n"
function setup_git {
# set up some git stuff
git config --global pull.ff only
git config --global merge.ff only
}
2017-06-12 16:22:05 +02:00
function install_rmate {
2017-07-14 21:20:20 +02:00
# Install python version of the textmate rmate remote (from github)
2017-06-12 16:22:05 +02:00
if [[ $(whoami) == "root" ]]; then
destpath="/usr/bin"
else
destpath="$HOME/bin"
fi
2017-07-14 21:20:20 +02:00
if [[ -f $destpath/rmate ]]; then
echo "rmate already exists: not installed"
return 1
2017-07-14 21:20:20 +02:00
else
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"
return 0
fi
2017-06-12 16:22:05 +02:00
}
function install_vimrc {
2017-07-14 21:20:20 +02:00
# Install vimrc from github.com/amix/vimrc
git clone "https://github.com/amix/vimrc.git" "$HOME/.vim_runtime" && sh "$HOME/.vim_runtime/install_awesome_vimrc.sh" || return 1
2017-06-12 16:22:05 +02:00
}
2018-03-31 02:33:42 +02:00
2017-06-12 16:22:05 +02:00
function install_zsh_plugins {
# Install fast-syntax-highlighting (git: zdharma), zsh-autosuggestions (git:zsh-users), alias-tips
2017-06-12 16:22:05 +02:00
ZSH_PLUGINS="$HOME/.oh-my-zsh/custom/plugins"
mkdir -p "$ZSH_PLUGINS"
git clone https://github.com/zdharma/fast-syntax-highlighting.git "${ZSH_PLUGINS}/fast-syntax-highlighting" || error=true
git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_PLUGINS}/zsh-autosuggestions" || error=true
git clone https://github.com/djui/alias-tips.git "${ZSH_PLUGINS}/alias-tips" || error=true
2017-07-14 21:20:20 +02:00
if [[ $error ]]; then
return 1
2017-07-14 21:20:20 +02:00
else
return 0
fi
2017-06-12 16:22:05 +02:00
}
# 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..."
2017-06-12 16:22:05 +02:00
ssh_config="$HOME/.ssh/config"
2017-07-14 21:20:20 +02:00
if [ ! -f $HOME/.ssh/id_rsa ]; then
echo "Creating ssh key (4096bit)..."
2017-07-14 21:20:20 +02:00
echo "Enter ssh-key comment (leave empty for default: user@host)"
read comment
if [[ $comment ]]; then
ssh-keygen -t rsa -b 4096 -C $comment
2017-07-14 21:20:20 +02:00
else
ssh-keygen -t rsa -b 4096
fi
2017-07-14 21:20:20 +02:00
# fix permissions
2017-06-12 16:22:05 +02:00
chmod 0700 "$HOME/.ssh"
fi
2017-06-12 16:22:05 +02:00
if [[ -f $ssh_config ]]; then
until [[ $modifyssh == "y" || $modifyssh == "n" ]]; do
2017-06-12 16:22:05 +02:00
echo "Do you want to modify the existing ssh config? (New values will be appended) (y/n)"
read modifyssh
done
2017-06-12 16:22:05 +02:00
fi
exec 3>&1 # save stdout file descriptor
exec 1>$ssh_config # redirect everything below to the $ssh_config file
2017-06-12 16:22:05 +02:00
if [[ "$modifyssh" != "n" ]]
then
echo "# brethil's dotfiles setup start"
echo 'TCPKeepAlive=yes'
echo 'ServerAliveCountMax=6'
echo "## Uncomment to enable compression for all ssh sessions"
echo '#Compression=yes'
echo '## Uncomment the following to enable ssh ControlMaster and ssh session persistence'
echo '#ControlMaster auto'
echo '#ControlPath /tmp/%r@%h:%p'
echo '#ControlPersist yes'
echo 'Host *'
echo 'ServerAliveInterval 300'
echo '## Enable the following if you want to use the rmate textmate remote'
echo "#Host *"
echo "#RemoteForward 52698 localhost:52698"
echo '## Enable the following if you want to use a reverse ssh tunnel to use mecp command on remote hosts'
echo "Host *"
echo "Remoteforward 2222 localhost:22"
echo '# end of brethil dotfiles setup #'
exec 1>&3 # restore stdout
echo ".ssh/ssh_config configured. Edit it to enable custom options:"
2017-07-14 21:20:20 +02:00
echo "- Compression"
echo "- Remote forwarding port 52698->52698 (Textmate rmate remote)"
echo "- Remote forwarding remote:2222->localhost:22 (mecp)"
2017-06-12 16:22:05 +02:00
else
echo "Did not modify $ssh_config."
fi
echo "# End of ssh config."
}
2017-07-14 21:20:20 +02:00
# First setup
2017-06-12 16:22:05 +02:00
function brethil_dotfiles_setup {
2017-07-14 21:20:20 +02:00
bin="$HOME/bin"
2017-06-12 16:22:05 +02:00
projects="$HOME/projects"
git="$HOME/git"
2017-07-14 21:20:20 +02:00
mkdir -p "$bin" "$projects" "$git" && echo "Created dirs $bin, $projects, $git"
2017-06-12 16:22:05 +02:00
# Install packages
# zsh
# grc: generic colourizer, colors output of any command
2017-07-14 21:20:20 +02:00
# ccze: similar to the above
# byobu: configuration/wrapper for tmux
2017-06-12 16:22:05 +02:00
# 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
2020-02-14 16:37:42 +01:00
# htop: like top, but bettah
packages="zsh git grc ccze bmon mtr pv tmux byobu htop"
2017-07-14 21:20:20 +02:00
# Check if running as root, if try using sudo to install packages.
# If sudo is not installed, launch a shell to try and install it
if [[ $(id -u) != 0 ]]; then
if [[ ! -f $(which sudo) ]] ; then
unset yn
until [[ $yn == "y" || $yn == "n" ]]; do
echo "Cannot install new packages without root access. Do you want to try to manually install sudo? (yn) "
2017-07-14 21:20:20 +02:00
read yn
done
if [[ $yn == "y" ]]; then
echo "Launching an interactive shell. Type exit after installing sudo."
# Launch bash
$(which bash)
2017-07-14 21:20:20 +02:00
else
echo "Quitting."
exit 0
fi
elif [[ -f $(which sudo) ]]; then
2017-07-14 21:20:20 +02:00
sudo="sudo "
fi
2017-06-12 16:22:05 +02:00
fi
2017-06-12 16:22:05 +02:00
if [[ $(which apt-get ) ]]; then
2017-07-14 21:20:20 +02:00
install_command="${sudo}apt-get install"
2017-06-12 16:22:05 +02:00
elif [[ $(which pacman) ]]; then
2020-02-14 16:37:42 +01:00
pacman -Sy yay # also install the yay aur package managery
packages="$packages"
install_command="${sudo}yay -Sy"
2017-06-12 16:22:05 +02:00
elif [[ $(which yum) ]]; then
2017-07-14 21:20:20 +02:00
install_command="${sudo}yum"
2017-06-12 16:22:05 +02:00
elif [[ $(which port) ]]; then
2017-07-14 21:20:20 +02:00
install_command="${sudo}port install"
2017-06-12 16:22:05 +02:00
elif [[ $(which brew) ]]; then
2017-07-14 21:20:20 +02:00
install_command="${sudo}brew install"
2017-06-12 16:22:05 +02:00
else
2017-07-14 21:20:20 +02:00
echo "I do not know how to install the required packages. Quitting."
exit 0
2017-06-12 16:22:05 +02:00
fi
# actually install the packages:
2017-07-14 21:20:20 +02:00
$install_command $packages
2017-07-14 21:20:20 +02:00
# Install oh-my-zsh
echo "Installing oh-my-zsh..."
sh -c "$(curl -sL zsh.dioporc.one | sed 's/env zsh/#env zsh/')" # comment the part that launches zsh
2017-07-14 21:20:20 +02:00
# oh-my-zsh's zshrc has been installed, prepend the dotfiles setup to it
cat "$HOME/.zshrc" >> $ZSHTMP
2017-07-14 21:20:20 +02:00
mv $ZSHTMP $HOME/.zshrc
2017-07-14 21:20:20 +02:00
# Increase history size
echo "export HISTSIZE=100000" >> $HOME/.zshrc
2017-07-14 21:20:20 +02:00
## Fix scrolling in byobu
if [[ $(uname) == "Darwin" ]]; then
sed -i '' 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux
else
2017-06-12 16:22:05 +02:00
sed -i 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux
fi
2017-07-14 21:20:20 +02:00
# Set m and M to enable/disable mouse mode in tmux/byobu
echo 'bind-key m source $BYOBU_PREFIX/share/byobu/keybindings/mouse.tmux.enable \; display-message "Mouse: ON"' >> ~/.tmux.conf
echo 'bind-key M source $BYOBU_PREFIX/share/byobu/keybindings/mouse.tmux.disable \; display-message "Mouse: Off"' >> ~/.tmux.conf
## Install the rmate client for textmate
#install_rmate && echo "Installed rmate Textmate remote "|| echo "Failed to install rmate Textmate remote"
2017-06-12 16:22:05 +02:00
# Install vim awesomerc (git amix/vimrc)
2017-07-14 21:20:20 +02:00
install_vimrc && echo "Installed vim awesome rc" || echo "Failed to install vim awesome rc"
2017-06-12 16:22:05 +02:00
# Create ssh config
create_ssh_config
# git config
setup_git
2017-06-12 16:22:05 +02:00
# Install new zsh plugins in $ZSH/custom/plugins/
2017-07-14 21:20:20 +02:00
install_zsh_plugins && echo "Installed custom zsh plugins in $ZSH/custom/plugins/" || echo "Failed to install custom zsh plugins"
2017-07-14 21:20:20 +02:00
# Source the plugins defined in brethil_dotfile.sh ($plugins)
if [[ $(uname) == "Darwin" ]]; then
2017-07-14 21:20:20 +02:00
sed -i "" -e 's/plugins=.*/plugins=\( $plugins \)/' $HOME/.zshrc
else
2017-07-14 21:20:20 +02:00
sed -i -e 's/plugins=.*/plugins=\( $plugins \)/' $HOME/.zshrc
fi
2017-07-14 21:20:20 +02:00
# Symlink brethil.zsh-theme
2018-03-31 02:33:42 +02:00
ln -s $DOTFILES/brethil.zsh-theme $HOME/.oh-my-zsh/custom/
# Symlink brethil-minimal.zsh-theme
2018-03-31 02:33:42 +02:00
ln -s $DOTFILES/brethil-minimal.zsh-theme $HOME/.oh-my-zsh/custom/
2017-06-12 16:22:05 +02:00
# Set brethil theme
2017-07-14 21:20:20 +02:00
if [[ $(uname) == "Darwin" ]]; then # MacOS has a different syntax for sed
sed -i '' 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc
else
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="brethil"/' $HOME/.zshrc
fi
#TODO: replace brethil theme with powerline?
2017-06-12 16:22:05 +02:00
}
# Setup
brethil_dotfiles_setup
2017-07-14 21:20:20 +02:00
echo "Functions definitions in $DOTFILES/functions.sh (you can add your own functions in ~/.dotfiles_functions)"
echo "Aliases definitions in $DOTFILES/aliases.sh (you can add your own aliases in ~/.dotfiles_aliases)"
2017-06-12 16:22:05 +02:00
echo "Colors are defined in $DOTFILES/colors.sh"
2017-07-14 21:20:20 +02:00
echo "Type . ~/.zshrc to source the new dotfiles, or simply launch another shell. )"