#!/usr/bin/env bash NAME="waldek" EMAIL="waldek@mailbox.org" DEFAULT_SHELL="xonsh" DEPENDENCIES_APT="zsh git tig tmux vim-nox htop python3 python3-pip python3-venv" DEPENDENCIES_PIP="xonsh[full] xontrib-sh" SOURCES_DIR=~/sources/gitea_irisib BOOTSTRAP_DIR=~/sources/gitea_irisib/bootstrap CUSTOM_ZSHRC=$BOOTSTRAP_DIR/custom.zsh CUSTOM_ENV=$BOOTSTRAP_DIR/env.sh GITEA_HTTPS="https://gitea.86thumbs.net" GITEA_SSH="ssh://gitea@86thumbs.net:3022" GITEA_CLONE=$GITEA_HTTPS XONSH_VENV=~/.virtualenvs/base LOG=/dev/null if [[ -z $(groups | grep sudo) ]]; then echo "you need to be in the sudo group to run this script..." exit 1 else echo "all good! let's setup your system" fi function install_apt_dependencies () { sudo apt-get update > /dev/null && echo "cache updated" sudo apt-get install -y --no-install-recommends $DEPENDENCIES_APT > /dev/null && echo "all installed!" echo "--- ${FUNCNAME[0]} done" } function setup_sources_dir () { local dst=$SOURCES_DIR if ! [[ -d $dst ]]; then mkdir -p $dst && echo "created $dst directory" else echo "$dst exists already" fi echo "--- ${FUNCNAME[0]} done" } function setup_global_git_config () { content=$(cat << EOF \n [user]\n \tname = $NAME\n \temail = $EMAIL\n [filter "lfs"]\n \tclean = git-lfs clean -- %f\n \tsmudge = git-lfs smudge -- %f\n \tprocess = git-lfs filter-process\n \trequired = true\n [pull]\n \trebase = false\n EOF ) echo -e $content > ~/.gitconfig echo "--- ${FUNCNAME[0]} done" } function clone_bootstrap_to_sources_dir () { local dst=$BOOTSTRAP_DIR if ! [[ -d $dst ]]; then git clone $GITEA_CLONE/waldek/bootstrap.git $dst && echo "cloned bootstrap dir" else cd $dst git pull && echo "updated $dst" cd - fi echo "--- ${FUNCNAME[0]} done" } function install_oh_my_zsh () { local dst=~/.oh-my-zsh if ! [[ -d $dst ]]; then git clone https://github.com/robbyrussell/oh-my-zsh.git $dst cp $dst/templates/zshrc.zsh-template ~/.zshrc else cd $dst git pull && echo "updated $dst" cd - fi echo "--- ${FUNCNAME[0]} done" } function customize_oh_my_zsh () { if [[ -z $(grep $CUSTOM_ZSHRC ~/.zshrc) ]]; then echo "source $CUSTOM_ZSHRC" >> ~/.zshrc && echo "appended $CUSTOM_ZSHRC to zshrc" fi if [[ -z $(grep $CUSTOM_ENV ~/.zshrc) ]]; then echo "source $CUSTOM_ENV" >> ~/.zshrc && echo "appended $CUSTOM_ENV to zshrc" fi echo "--- ${FUNCNAME[0]} done" } function clone_and_setup_vimrc () { local dst=$SOURCES_DIR/vimrc if ! [[ -d $dst ]]; then git clone $GITEA_CLONE/waldek/vimrc.git $dst && echo "cloned bootstrap dir" ln -s $dst/main.vimrc ~/.vimrc git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim vim +VundleInstall +qall else cd $dst git pull && echo "updated $dst" cd - vim +VundleUpdate +qall fi echo "--- ${FUNCNAME[0]} done" } function symlink_config_files () { mkdir -p ~/.config/htop local dst=~/.config/htop/htoprc if ! [[ -L $dst ]]; then rm $dst 2> /dev/null ln -s $(ls $BOOTSTRAP_DIR/htoprc) $dst fi local dst=~/.xonshrc if ! [[ -L $dst ]]; then rm $dst 2> /dev/null ln -s $(ls $BOOTSTRAP_DIR/xonshrc) $dst fi local dst=~/.config/kitty if ! [[ -L $dst ]]; then rm $dst 2> /dev/null ln -s $(ls $BOOTSTRAP_DIR/kitty) $dst fi echo "--- ${FUNCNAME[0]} done" } function install_pip_dependencies () { mkdir -p $XONSH_VENV python3 -m venv $XONSH_VENV source $XONSH_VENV/bin/activate for dep in $DEPENDENCIES_PIP; do pip3 install --upgrade "$dep" > $LOG && echo "installed $dep" done echo "--- ${FUNCNAME[0]} done" } function change_shell () { if [[ "$1" == "xonsh" ]]; then path=$XONSH_VENV/bin/xonsh elif [[ -z "$(grep $1 /etc/shells)" ]]; then echo "$1 not a valid shell, falling back to $(which bash)" path=$(which bash) fi sudo chsh -s $path $USER && echo "set $1 as shell for $USER" echo "--- ${FUNCNAME[0]} done" } function main () { install_apt_dependencies install_pip_dependencies setup_sources_dir setup_global_git_config clone_bootstrap_to_sources_dir install_oh_my_zsh customize_oh_my_zsh clone_and_setup_vimrc symlink_config_files change_shell $DEFAULT_SHELL } main