#!/usr/bin/env bash NC='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' # Locations GIT=$HOME/git BINS="$HOME/.local/bin" PROGRAMS=$HOME/programs DOTFILES=$HOME/.dotfiles DOTPRIVATE=$HOME/.dotfiles.private XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} # Software version LTEX_VERSION="15.2.0" METALS_VERSION="0.10.8" NNN_VERSION="4.3" NVIM_VERSION="0.5.1" RIPGREP_VERSION="13.0.0" TMUX_VERSION="3.2a" RUST_ANALYZER_VERSION="2021-11-01" # Flags YES=false PRIVATE=false DID_BASH=false DID_NEOVIM=false DID_NNN=false DID_RIPGREP=false DID_TMUX=false msg_info() { echo -e "${GREEN}[INFO] $1${NC}" } msg_warn() { echo -e "${YELLOW}[WARN] $1${NC}" } msg_error() { echo -e "${RED}[ERROR] $1${NC}" } print_help() { echo echo "A script to setup dyamon's dotfiles." echo echo "It takes care of deploying dotfiles for any requested package." echo "It tries hard to be as self-contained as possible installing" echo "dependences locally in a distribution agnostic way." echo echo "Requires 'git' and 'stow' to be installed in the system." echo echo "USAGE:" echo " setup.sh [OPTION ...] [PACKAGE ...]" echo echo "OPTIONs are:" echo " -y | --yes:" echo " do not prompt for missing dependences. Just install them." echo " -p | --private:" echo " clone private dotfiles alongside the main repository." echo " Repos will be cloned via SSH instead of HTTPS." echo " -h | --help:" echo " print this help." echo echo "PACKAGEs are:" echo " bash neovim nnn ripgrep tmux" # extra fonts fzf grimoire mailcap misc mpd mpv ncmpcpp # neomutt readline sxhkd sxiv transmission x11 echo } setup_bash() { if [ "$DID_BASH" = false ]; then DID_BASH=true if [[ "$SHELL" =~ "bash" ]]; then # Dotfiles deployment msg_info "Bash dotfiles deployment..." pushd $DOTFILES >/dev/null stow --verbose --restow bash popd >/dev/null else msg_warn "Default shell is set to '$SHELL'." msg_warn "Set it to $(which bash) to avoid incompatibilities." fi fi } setup_tmux() { if [ "$DID_TMUX" = false ]; then DID_TMUX=true # Dependences setup_bash # Installation msg_info "Installing tmux..." if which tmux >/dev/null 2>&1 ; then msg_info "'tmux' executable found in the system." tmux -V else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'tmux' locally? [yN]: " -n 1 -r /dev/null TMUX="tmux-$TMUX_VERSION" wget "https://github.com/tmux/tmux/releases/download/$TMUX_VERSION/$TMUX.tar.gz" tar -zxvf "$TMUX.tar.gz" pushd "$TMUX" ./configure && make && \ ln -s "$PROGRAMS/$TMUX/tmux" "$BINS/" popd >/dev/null popd >/dev/null tmux -V else msg_warn "You should provide an alternative installation to avoid any problem." fi fi # Dotfiles deployment msg_info "tmux dotfiles deployment..." pushd $DOTFILES >/dev/null stow --verbose --restow tmux popd >/dev/null fi } setup_nnn() { if [ "$DID_NNN" = false ]; then DID_NNN=true # Dependences # trash-cli msg_info "Installing trash-cli (nnn dependency)..." if which trash >/dev/null 2>&1 ; then msg_info "'trash' executable found in the system." trash --version else pushd "$GIT" >/dev/null git clone https://github.com/andreafrancia/trash-cli.git 2>/dev/null cd trash-cli git pull --ff-only pip install . popd >/dev/null fi # Installation msg_info "Installing nnn..." if which nnn >/dev/null 2>&1 ; then msg_info "'nnn' executable found in the system." nnn -V else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'nnn' locally? [yN]: " -n 1 -r /dev/null NNN="nnn-static-$NNN_VERSION.x86_64" wget "https://github.com/jarun/nnn/releases/download/v$NNN_VERSION/$NNN.tar.gz" tar -zxvf "$NNN.tar.gz" ln -s "$PROGRAMS/nnn-static" "$BINS/nnn" popd >/dev/null nnn -V else msg_warn "You should provide an alternative installation to avoid any problem." fi fi # Dotfiles deployment msg_info "nnn dotfiles deployment..." pushd $DOTFILES >/dev/null stow --verbose --restow nnn popd >/dev/null fi } setup_ripgrep() { if [ "$DID_RIPGREP" = false ]; then DID_RIPGREP=true # Installation msg_info "Installing ripgrep..." if which rg >/dev/null 2>&1 ; then msg_info "'ripgrep' executable found in the system." rg --version else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'ripgrep' locally? [yN]: " -n 1 -r /dev/null RIPGREP="ripgrep-$RIPGREP_VERSION-x86_64-unknown-linux-musl" wget "https://github.com/BurntSushi/ripgrep/releases/download/$RIPGREP_VERSION/$RIPGREP.tar.gz" tar -zxvf "$RIPGREP.tar.gz" ln -s "$PROGRAMS/$RIPGREP/rg" "$BINS/" popd >/dev/null rg --version else msg_warn "You should provide an alternative installation to avoid any problem." fi fi # Dotfiles deployment msg_info "Ripgrep dotfiles deployment..." pushd $DOTFILES >/dev/null stow --verbose --restow ripgrep popd >/dev/null fi } setup_neovim() { if [ "$DID_NEOVIM" = false ]; then DID_NEOVIM=true # Dependences setup_bash setup_nnn setup_ripgrep # Metals if which metals >/dev/null 2>&1 ; then msg_info "'metals' executable found in the system." metals --version else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'metals' locally? [yN]: " -n 1 -r /dev/null if which coursier >/dev/null 2>&1 ; then msg_info "'coursier' executable found in the system." coursier --version else curl -L -o coursier https://git.io/coursier-cli chmod u+x coursier coursier --version fi coursier bootstrap \ --java-opt -Xss4m \ --java-opt -Xms100m \ org.scalameta:metals_2.12:$METALS_VERSION \ -r bintray:scalacenter/releases \ -r sonatype:snapshots \ -o ./metals -f popd >/dev/null metals --version else msg_warn "You will need to provide an alternative installation to use LSP functionalities with Scala Metals" fi fi # Rust Analyzer if which rust-analyzer >/dev/null 2>&1 ; then msg_info "'rust-analyzer' executable found in the system." rust-analyzer --version else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'rust-analyzer' locally? [yN]: " -n 1 -r /dev/null RUST="rust-analyzer-x86_64-unknown-linux-gnu" wget "https://github.com/rust-analyzer/rust-analyzer/releases/download/$RUST_ANALYZER_VERSION/$RUST.gz" gzip -d "$RUST.gz" chmod u+x "$RUST" ln -s "$PROGRAMS/$RUST" "$BINS/rust-analyzer" rust-analyzer --version else msg_warn "You will need to provide an alternative installation to use LSP functionalities with Rust Analyzer" fi fi # lTeX-ls if which ltex-ls >/dev/null 2>&1 ; then msg_info "'ltex-ls' executable found in the system." ltex-ls --version else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'ltex-ls' locally? [yN]: " -n 1 -r /dev/null LTEX="ltex-ls-$LTEX_VERSION" wget "https://github.com/valentjn/ltex-ls/releases/download/$LTEX_VERSION/$LTEX-linux-x64.tar.gz" tar -zxvf "$LTEX-linux-x64.tar.gz" ln -s "$PROGRAMS/$LTEX/bin/ltex-ls" "$BINS/" ltex-ls --version else msg_warn "You will need to provide an alternative installation to use LSP functionalities with lTeX." fi fi # Installation msg_info "Installing neovim..." if which nvim >/dev/null 2>&1 ; then msg_info "'nvim' executable found in the system." nvim --version else [ "$YES" = true ] && \ REPLY="Y" || \ read -p "Install 'nvim' locally? [yN]: " -n 1 -r /dev/null NVIM="nvim-linux64" wget "https://github.com/neovim/neovim/releases/download/v$NVIM_VERSION/$NVIM.tar.gz" wget "https://github.com/neovim/neovim/releases/download/v$NVIM_VERSION/$NVIM.tar.gz.sha256sum" if sha256sum --check --status "$NVIM.tar.gz.sha256sum" ; then tar -zxvf "$NVIM.tar.gz" ln -s "$PROGRAMS/$NVIM/bin/nvim" "$BINS/" else print_err "$NVIM.tar.gz checksum check failed." fi popd >/dev/null nvim --version else msg_warn "You should provide an alternative installation to avoid any problem." fi fi # Dotfiles deployment msg_info "Neovim dotfiles deployment..." pushd $DOTFILES >/dev/null stow --verbose --restow neovim popd >/dev/null mkdir -p $XDG_DATA_HOME/nvim/{backup,sessions,swap,undo} pushd $XDG_DATA_HOME/nvim/site/pack/personal/opt/telescope-fzf-native.nvim/ >/dev/null make popd >/dev/null fi } mkdir -p "$GIT" mkdir -p "$BINS" mkdir -p "$PROGRAMS" # Make new binaries available right away export PATH=$BINS:$PATH while [[ $# -gt 0 ]]; do OPTION="$1" case $OPTION in -y|--yes) YES=true shift ;; -p|--private) PRIVATE=true shift ;; -h|--help) print_help exit 0 ;; *) break ;; esac done pushd $HOME >/dev/null if [ "$PRIVATE" = true ]; then [[ -d "$DOTFILES" ]] || \ git clone --recurse-submodules gitolite3@git.dyamon.me:dotfiles.git "$DOTFILES" [[ -d "$DOTPRIVATE" ]] || \ git clone --recurse-submodules gitolite3@git.dyamon.me:dotfiles-private.git "$DOTPRIVATE" else [[ -d "$DOTFILES" ]] || \ git clone --recurse-submodules https://git.dyamon.me/dotfiles "$DOTFILES" fi while [[ $# -gt 0 ]]; do PACKAGE="$1" case $PACKAGE in bash) msg_info "[Package BASH]" setup_bash ;; neovim) msg_info "[Package NEOVIM]" setup_neovim ;; nnn) msg_info "[Package NNN]" setup_nnn ;; ripgrep) msg_info "[Package RIPGREP]" setup_ripgrep ;; tmux) msg_info "[Package TMUX]" setup_tmux ;; *) msg_warn "'$PACKAGE' is not a valid package. Ignoring." ;; esac shift done popd >/dev/null exit 0