#!/bin/bash # Color codes for output RED='\e[1;31m' GREEN='\e[1;32m' RESET='\e[0m' TICK="\\r[${GREEN}✓${RESET}]" CROSS="\\r[${RED}✗${RESET}]" INFO="\\r[i]" BASE_DEPENDENCIES=(git vim curl yes) YCM_DEPENDENCIES=(gcc g++ cmake python3 rustup) check_dependencies () { echo -ne "${INFO} Checking for dependencies..." for DEPENDENCY in "$@" do command -v "${DEPENDENCY}" > /dev/null EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then echo -e "${CROSS} ${DEPENDENCY} is not installed or cannot be found on this system" exit $EXIT_CODE fi done echo -e "${TICK}" } clone_or_update_repo () { cd ~ || exit 1 if [ -d dotfiles ]; then echo -ne "${INFO} Updating local repo..." cd dotfiles \ && git checkout master >/dev/null 2>&1 \ && git pull >/dev/null 2>&1 echo -e "${TICK}" else echo -ne " ${INFO} Cloning repo..." git clone git@github.com:barrelmaker97/dotfiles.git >/dev/null 2>&1 || git clone https://github.com/barrelmaker97/dotfiles >/dev/null 2>&1 cd dotfiles || exit 1 echo -e "${TICK}" fi } update_install () { check_dependencies "${BASE_DEPENDENCIES[@]}" clone_or_update_repo all_install } all_install () { bash_install git_install scripts_install vim_install } bash_install () { echo -ne " ${INFO} Installing bash configs..." ln -sf "${HOME}"/dotfiles/bashrc "${HOME}"/.bashrc ln -sf "${HOME}"/dotfiles/profile "${HOME}"/.profile echo -e "${TICK}" } git_install () { echo -ne " ${INFO} Installing git configs..." ln -sf "${HOME}"/dotfiles/gitconfig "${HOME}"/.gitconfig echo -e "${TICK}" } tmux_install () { echo -ne " ${INFO} Installing tmux configs..." ln -sf "${HOME}"/dotfiles/tmux.conf "${HOME}"/.tmux.conf echo -e "${TICK}" } scripts_install () { echo -ne " ${INFO} Installing scripts..." ln -sf "${HOME}"/dotfiles/bin "${HOME}"/ echo -e "${TICK}" } vim_install () { echo -ne " ${INFO} Installing vim configs..." ln -sf "${HOME}"/dotfiles/vimrc "${HOME}"/.vimrc rm -rf ~/.vim curl -sfLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim yes "" | vim +PlugInstall +quitall >/dev/null 2>&1 echo -e "${TICK}" } work_install () { echo -ne " ${INFO} Installing work configs..." ln -sf "${HOME}"/dotfiles/work-gitconfig "${HOME}"/.work-gitconfig echo -e "${TICK}" } sshd_install () { echo -ne " ${INFO} Installing sshd configs..." sudo cp -u "${HOME}"/dotfiles/sshd_config /etc/ssh/sshd_config echo -e "${TICK}" } ycm_install () { check_dependencies "${YCM_DEPENDENCIES[@]}" echo -e " ${INFO} Installing youcompleteme..." cd ~/.vim/plugged/YouCompleteMe || exit 1 python3 install.py --rust-completer } help () { echo -e "Usage: \n" echo -e "\tall\t - install all except for: sshd, tmux, work" echo -e "\tbash\t - install bash configs" echo -e "\tgit\t - install git configs" echo -e "\tscripts\t - install scripts" echo -e "\tsshd\t - install sshd configs" echo -e "\ttmux\t - install tmux configs" echo -e "\tvim\t - install vim configs" echo -e "\twork\t - install work configs" echo -e "\tycm\t - install youcompleteme" echo -e "\thelp\t - print this message\n" } # Install all when run without arguments if [ "$#" -eq 0 ]; then update_install exit 0 fi # Action parsing ACTION="$1" case "${ACTION}" in all|bash|git|scripts|sshd|tmux|vim|work|ycm) "${ACTION}"_install ;; help) "${ACTION}" ;; *) echo -e "Invalid action '${ACTION}' specified." help exit 1 ;; esac