mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-24 20:41:31 +01:00
190 lines
6.1 KiB
Bash
Executable File
190 lines
6.1 KiB
Bash
Executable File
#!/bin/bash
|
|
## brethil's dotfiles installation script
|
|
## 20 June 2016
|
|
|
|
# Get the location for the dotfiles
|
|
DOTFILES=$PWD
|
|
|
|
PACKAGES="vim zsh antibody git grc ccze bmon mtr tmux byobu htop"
|
|
|
|
function setup_git {
|
|
# set up some git stuff
|
|
git config --global include.path $DOTFILES/gitconfig
|
|
}
|
|
|
|
function install_vimrc {
|
|
# TODO: check if vim-plug is installed
|
|
if [ -f "$HOME/.vimrc" ]; then
|
|
mv "$HOME/.vimrc"{,.bak} && echo "Backed up old vimrc"
|
|
fi
|
|
ln -s "$DOTFILES/.vimrc" "$HOME/.vimrc"
|
|
}
|
|
|
|
function setup_ackrc {
|
|
ln -s "$DOTFILES/ackrc" "$HOME/.ackrc"
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
# 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 [ ! -f $HOME/.ssh/id_rsa ]; then
|
|
echo "Creating ssh key (4096bit)..."
|
|
|
|
echo "Enter ssh-key comment (leave empty for default: user@host)"
|
|
read comment
|
|
if [[ $comment ]]; then
|
|
ssh-keygen -t ed25519 -C "$comment"
|
|
else
|
|
ssh-keygen -t ed25519
|
|
fi
|
|
# fix permissions
|
|
chmod 0700 "$HOME/.ssh"
|
|
fi
|
|
|
|
if [[ -f $ssh_config ]]; then
|
|
until [[ $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
|
|
|
|
exec 3>&1 # save stdout file descriptor
|
|
|
|
# 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
|
|
|
|
exec 1>>$ssh_config # redirect everything below to the $ssh_config file
|
|
if [[ "$modifyssh" == "n" ]]; then
|
|
echo "Did not modify $ssh_config."
|
|
exec 1>&3 # restore stdout
|
|
return
|
|
fi
|
|
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'
|
|
echo '#ControlMaster autoask # ask for confirmation before using a shared connection'
|
|
echo '#ControlMaster auto # do not ask for confirmation'
|
|
echo '#ControlPath ~/.ssh/%r@%h:%p'
|
|
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)"
|
|
echo "# End of ssh config."
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
|
|
# First setup
|
|
function brethil_dotfiles_setup {
|
|
antibody &>/dev/null || (echo "Please install antibody then continue." 1>&2 && echo "Other useful packages: $PACKAGES" && exit)
|
|
bin="$HOME/bin"
|
|
projects="$HOME/projects"
|
|
git="$HOME/git"
|
|
mkdir -p "$bin" "$projects" "$git" && echo "Created dirs $bin, $projects, $git"
|
|
|
|
# prepare .zshrc
|
|
cp "$HOME/.zshrc"{,.pre-brethil-dotfiles}
|
|
exec 3>&1 # save stdout
|
|
exec 1>>"$HOME/.zshrc"
|
|
echo -e "\n\n# brethil's dotfiles:"
|
|
echo "export DOTFILES=$DOTFILES"
|
|
echo "source \$DOTFILES/brethil_dotfile.sh"
|
|
echo -e "# End of brethil's dotfiles\n\n"
|
|
exec 1>&3 # restore stdout
|
|
|
|
antibody bundle "$DOTFILES/antibody_plugins.txt"
|
|
antibody update
|
|
|
|
fix_annoyances
|
|
setup_vim
|
|
# Create ssh config
|
|
create_ssh_config
|
|
# git config
|
|
setup_git
|
|
# ipython profile
|
|
setup_ipython
|
|
# pdbpp rc
|
|
setup_pdbprc
|
|
# ackrc
|
|
setup_ackrc
|
|
|
|
ZSH="$(antibody path robbyrussell/oh-my-zsh)"
|
|
ln -s "$DOTFILES/brethil.zsh-theme" "${ZSH}/themes/" # TODO: improve this
|
|
ln -s "$DOTFILES/brethil-minimal.zsh-theme" "${ZSH}/themes/"
|
|
}
|
|
|
|
|
|
function main(){
|
|
set -e
|
|
set -o pipefail
|
|
# Setup
|
|
# brethil_dotfiles_setup
|
|
source "$DOTFILES/colors.sh"
|
|
|
|
echo -e "$BOLD$GREEN Install complete!"
|
|
echo ""
|
|
echo "$WHITE Set \$DOTFILES to $DOTFILES"
|
|
echo -e "$RED Functions definitions:$WHITE \$DOTFILES/functions.sh\n\tyou can add your own functions in ~/.dotfiles_functions"
|
|
echo -e "$RED Aliases definitions:$WHITE \$DOTFILES/aliases.sh\n\tyou can add your own aliases in ~/.dotfiles_aliases)"
|
|
echo -e "$RED Colors definitions:$WHITE \$DOTFILES/colors.sh"
|
|
echo -e "$CLEAR"
|
|
echo "More zsh plugins can be added using antibody, adding them at \$DOTFILES/antibody_plugins.txt"
|
|
|
|
echo "Type '. ~/.zshrc' or 'exec zsh -l' to source the new configuration."
|
|
}
|
|
|
|
main
|