2017-06-12 16:22:05 +02:00
|
|
|
#!/bin/bash
|
2020-02-14 16:37:47 +01:00
|
|
|
## brethil's dotfiles installation script
|
2017-06-12 16:22:05 +02:00
|
|
|
## 20 June 2016
|
|
|
|
|
|
|
|
# Get the location for the dotfiles
|
|
|
|
DOTFILES=$PWD
|
|
|
|
|
2020-02-14 16:37:47 +01:00
|
|
|
# Install packages
|
|
|
|
# vim, zsh
|
2020-03-01 19:43:32 +01:00
|
|
|
# antibody: zsh plugin manager
|
2020-02-14 16:37:47 +01:00
|
|
|
# grc: generic colourizer, colors output of any command
|
|
|
|
# ccze: similar to the above
|
|
|
|
# byobu: configuration/wrapper for tmux
|
|
|
|
# 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
|
|
|
|
# htop: like top, but bettah
|
2019-12-07 22:28:16 +01:00
|
|
|
# bat: a cat clone on wings
|
2020-11-22 17:01:38 +01:00
|
|
|
PACKAGES="vim zsh antibody git grc ccze bmon mtr tmux byobu htop"
|
2020-02-14 16:37:42 +01:00
|
|
|
|
|
|
|
function setup_git {
|
|
|
|
# set up some git stuff
|
2020-11-22 16:58:46 +01:00
|
|
|
git config --global include.path $DOTFILES/gitconfig
|
2020-02-14 16:37:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
2020-02-14 16:37:42 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-02 15:08:34 +02:00
|
|
|
function setup_ackrc {
|
|
|
|
ln -s "$DOTFILES/ackrc" "~/.ackrc"
|
|
|
|
}
|
|
|
|
|
2020-02-14 16:37:46 +01:00
|
|
|
function setup_vim {
|
2020-11-22 17:02:12 +01:00
|
|
|
# Install vim awesomerc (git amix/vimrc)
|
|
|
|
install_vimrc && echo "Installed vim awesome rc" || echo "Failed to install vim awesome rc"
|
2019-12-26 21:51:01 +01:00
|
|
|
ln -s "$DOTFILES/my_configs.vim" "$HOME/.vim_runtime/my_configs.vim"
|
|
|
|
mkdir -p ~/.vim_runtime/my_plugins/twilight/colors
|
|
|
|
ln -s "$DOTFILES/twilight256.vim" ~/.vim_runtime/my_plugins/twilight/colors/
|
2019-12-26 21:51:01 +01:00
|
|
|
(cd ~/.vim_runtime/my_plugins && git add -f * && git commit -m "bretello dotfiles")
|
2020-02-14 16:37:46 +01:00
|
|
|
}
|
2018-03-31 02:33:42 +02:00
|
|
|
|
2020-11-22 16:40:38 +01:00
|
|
|
function setup_ipython {
|
|
|
|
python -m pip install pip ipython || python -m pip install --user pip ipython
|
|
|
|
ipython -c "1+1" # run ipython once so that we are sure that the profile directories exist
|
|
|
|
ln -s "$DOTFILES/ipython/profile_default/ipython_config.py" "$HOME/.ipython/profile_default/"
|
|
|
|
ln -s "$DOTFILES/ipython/profile_default/startup" "$HOME/.ipython/profile_default/startup"
|
|
|
|
}
|
2020-01-27 11:38:26 +01:00
|
|
|
|
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..."
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2017-06-12 16:22:05 +02:00
|
|
|
ssh_config="$HOME/.ssh/config"
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2017-07-14 21:20:20 +02:00
|
|
|
if [ ! -f $HOME/.ssh/id_rsa ]; then
|
|
|
|
echo "Creating ssh key (4096bit)..."
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2017-07-14 21:20:20 +02:00
|
|
|
echo "Enter ssh-key comment (leave empty for default: user@host)"
|
|
|
|
read comment
|
2017-07-17 01:28:35 +02:00
|
|
|
if [[ $comment ]]; then
|
2020-03-01 19:48:55 +01:00
|
|
|
ssh-keygen -t ed25519 -C "$comment"
|
2017-07-14 21:20:20 +02:00
|
|
|
else
|
2020-03-01 19:48:55 +01:00
|
|
|
ssh-keygen -t ed25519
|
2017-07-17 01:28:35 +02:00
|
|
|
fi
|
2017-07-14 21:20:20 +02:00
|
|
|
# fix permissions
|
2017-06-12 16:22:05 +02:00
|
|
|
chmod 0700 "$HOME/.ssh"
|
|
|
|
fi
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2017-06-12 16:22:05 +02:00
|
|
|
if [[ -f $ssh_config ]]; then
|
2017-07-17 01:28:35 +02:00
|
|
|
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
|
2020-02-14 16:37:42 +01:00
|
|
|
done
|
2017-06-12 16:22:05 +02:00
|
|
|
fi
|
2020-02-14 16:37:42 +01:00
|
|
|
|
|
|
|
exec 3>&1 # save stdout file descriptor
|
2020-02-14 16:37:44 +01:00
|
|
|
|
|
|
|
# add the ssh rc that symlinks the used SSH_AUTH_SOCK. This will be executed on every ssh login.
|
|
|
|
# The idea is that if the user is logging in using ssh -A, the symlink will point to the correct
|
|
|
|
# location of the ssh auth socket and the remote ssh agent will be used.
|
|
|
|
# SSH_AUTH_SOCK is declared in brethil_dotfile.sh
|
|
|
|
exec 1>>~/.ssh/rc
|
|
|
|
echo '#!/bin/bash'
|
|
|
|
echo 'if test "$SSH_AUTH_SOCK" ; then'
|
|
|
|
echo ' ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock'
|
|
|
|
echo 'fi '
|
|
|
|
chmod 755 ~/.ssh/rc
|
|
|
|
|
2020-02-14 16:37:44 +01:00
|
|
|
exec 1>>$ssh_config # redirect everything below to the $ssh_config file
|
2020-02-14 16:37:47 +01:00
|
|
|
if [[ "$modifyssh" == "n" ]]; then
|
2017-06-12 16:22:05 +02:00
|
|
|
echo "Did not modify $ssh_config."
|
2020-02-14 16:37:47 +01:00
|
|
|
exec 1>&3 # restore stdout
|
|
|
|
return
|
2017-06-12 16:22:05 +02:00
|
|
|
fi
|
2020-02-14 16:37:47 +01:00
|
|
|
echo "# brethil's dotfiles setup start"
|
|
|
|
echo 'TCPKeepAlive=yes'
|
|
|
|
echo 'ServerAliveCountMax=6'
|
|
|
|
echo
|
|
|
|
echo "## Uncomment to enable compression for all ssh sessions"
|
|
|
|
echo '#Compression=yes'
|
|
|
|
echo
|
|
|
|
echo '## Uncomment the following to enable ssh ControlMaster and ssh session persistence'
|
2020-04-04 19:58:31 +02:00
|
|
|
echo '#ControlMaster autoask # ask for confirmation before using a shared connection'
|
|
|
|
echo '#ControlMaster auto # do not ask for confirmation'
|
2020-01-14 23:50:41 +01:00
|
|
|
echo '#ControlPath ~/.ssh/%r@%h:%p'
|
2020-02-14 16:37:47 +01:00
|
|
|
echo '#ControlPersist yes'
|
|
|
|
echo
|
|
|
|
echo 'Host *'
|
|
|
|
echo ' ServerAliveInterval 300'
|
|
|
|
echo
|
|
|
|
echo '## Enable the following if you want to use the rmate textmate remote'
|
|
|
|
echo "#Host *"
|
|
|
|
echo "# RemoteForward 52698 localhost:52698"
|
|
|
|
echo
|
|
|
|
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
|
|
|
|
echo '# end of brethil dotfiles setup #'
|
|
|
|
|
|
|
|
exec 1>&3 # restore stdout
|
|
|
|
echo ".ssh/ssh_config configured. Edit it to enable custom options:"
|
|
|
|
echo "- Compression"
|
|
|
|
echo "- Remote forwarding remote:2222->localhost:22 (revere tunnel to scp back to the original host using mecp)"
|
2017-06-12 16:22:05 +02:00
|
|
|
echo "# End of ssh config."
|
|
|
|
}
|
|
|
|
|
2020-02-14 16:37:47 +01:00
|
|
|
function fix_annoyances {
|
|
|
|
## 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
|
|
|
|
sed -i 's/set -g terminal-overrides/#set -g terminal-overrides/' /usr/share/byobu/profiles/tmux
|
|
|
|
fi
|
|
|
|
|
|
|
|
# remove ls from the grc.zsh config: # TODO: fix this on MacOS
|
|
|
|
sed 's|ls \\|#ls \\|' /etc/grc.zsh
|
|
|
|
|
|
|
|
# TODO: add iptables, docker to grc.zsh
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-14 21:20:20 +02:00
|
|
|
# First setup
|
2017-06-12 16:22:05 +02:00
|
|
|
function brethil_dotfiles_setup {
|
2020-03-01 19:43:32 +01:00
|
|
|
antibody &>/dev/null || (echo "Please install antibody then continue." 1>&2 && echo "Other useful packages: $PACKAGES" && exit)
|
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"
|
|
|
|
|
2020-02-14 16:37:47 +01:00
|
|
|
# prepare .zshrc
|
2020-02-14 16:37:48 +01:00
|
|
|
exec 3>&1 # save stdout
|
2020-05-02 15:08:34 +02:00
|
|
|
exec 1>"$HOME/.zshrc"
|
2020-02-14 16:37:47 +01:00
|
|
|
echo -e "\n\n# brethil's dotfiles:"
|
|
|
|
echo "DOTFILES=$DOTFILES"
|
|
|
|
echo "source \$DOTFILES/brethil_dotfile.sh"
|
|
|
|
echo -e "# End of brethil's dotfiles\n\n"
|
2020-02-14 16:37:48 +01:00
|
|
|
exec 1>&3 # restore stdout
|
2020-02-14 16:37:47 +01:00
|
|
|
|
2020-03-01 19:52:31 +01:00
|
|
|
antibody bundle $DOTFILES/antibody_plugins.txt
|
|
|
|
antibody update
|
|
|
|
|
2020-02-14 16:37:47 +01:00
|
|
|
fix_annoyances
|
|
|
|
setup_vim
|
2017-06-12 16:22:05 +02:00
|
|
|
# Create ssh config
|
|
|
|
create_ssh_config
|
2020-02-14 16:37:42 +01:00
|
|
|
# git config
|
|
|
|
setup_git
|
2020-11-22 16:40:38 +01:00
|
|
|
# ipython profile
|
|
|
|
setup_ipython
|
2020-01-27 11:38:26 +01:00
|
|
|
# pdbpp rc
|
|
|
|
setup_pdbprc
|
2020-05-02 15:08:34 +02:00
|
|
|
# ackrc
|
|
|
|
setup_ackrc
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2020-03-01 19:43:32 +01:00
|
|
|
oh_my_zsh_path="$(antibody path robbyrussell/oh-my-zsh)"
|
2017-07-14 21:20:20 +02:00
|
|
|
# Symlink brethil.zsh-theme
|
2020-03-01 19:43:32 +01:00
|
|
|
ln -s $DOTFILES/brethil.zsh-theme ${oh_my_zsh_path}/themes/ # TODO: improve this
|
2017-07-17 01:28:35 +02:00
|
|
|
# Symlink brethil-minimal.zsh-theme
|
2020-03-01 19:43:32 +01:00
|
|
|
ln -s $DOTFILES/brethil-minimal.zsh-theme ${oh_my_zsh_path}/themes/
|
2020-02-14 16:37:42 +01:00
|
|
|
|
2020-02-14 16:37:47 +01:00
|
|
|
# TODO: powerline?
|
2020-05-02 15:08:34 +02:00
|
|
|
|
|
|
|
|
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. )"
|