bootstrap.sh (1926B) - raw


      1 #!/bin/sh
      2 
      3 if [ "$#" = "1" ] && [ "$1" = "--small" ]; then
      4     smallinstall="1"
      5 elif [ "$#" != "0" ]; then
      6     echo "usage: bootstrap.sh [--small]"
      7     echo
      8     echo "    --small: copy only configuration for zsh, git, nvim and tmux (for servers or"
      9     echo "             root user)"
     10     exit 1
     11 fi
     12 
     13 repodest="${XDG_DATA_HOME:-$HOME/.local/share}/dotfiles/repo.git"
     14 backupdest="${XDG_DATA_HOME:-$HOME/.local/share}/dotfiles/old-files"
     15 tempdir="$(mktemp -d)"
     16 mkdir -p "$(dirname $repodest)"
     17 
     18 gitdotfiles() { git --git-dir="$repodest" --work-tree="$HOME" "$@"; }
     19 
     20 git clone --separate-git-dir="$repodest" "https://git.oscarbenedito.com/dotfiles" "$tempdir" || exit 1
     21 gitdotfiles config --local status.showUntrackedFiles no
     22 gitdotfiles config --local core.worktree "$HOME"
     23 
     24 cd "$tempdir"   # make sure we are not in another Git repository
     25 for file in $(gitdotfiles ls-files); do
     26     if [ -f "$HOME/$file" ]; then
     27         mkdir -p "$(dirname "$backupdest/$file")"
     28         mv -f "$HOME/$file" "$backupdest/$file"
     29     fi
     30     mkdir -p "$(dirname "$HOME/$file")"
     31     mv -f "$tempdir/$file" "$HOME/$file"
     32 done
     33 
     34 mkdir -p "$HOME/.cache/zsh"
     35 mkdir -p "$HOME/.local/share/zsh"
     36 
     37 if [ "$smallinstall" = "1" ]; then
     38     for file in $(gitdotfiles ls-files | sed '/^\.config\/\(zsh\|git\/config\|nvim\|tmux\)\|^\.zshenv/d'); do
     39         rm -f "$HOME/$file"
     40         gitdotfiles update-index --skip-worktree "$HOME/$file"
     41         rmdir -p "$(dirname "$HOME/$file")" 2>/dev/null
     42     done
     43 fi
     44 
     45 rm -f "$HOME/README.md" "$HOME/COPYING" "$HOME/bootstrap.sh"
     46 gitdotfiles update-index --skip-worktree "$HOME/README.md" "$HOME/COPYING" "$HOME/bootstrap.sh"
     47 
     48 cd "$HOME"
     49 rm -rf "$tempdir"
     50 
     51 echo "Installing nvim pluggins..."
     52 nvim --headless '+qa'
     53 echo
     54 
     55 if [ -d "$backupdest" ]; then
     56     echo
     57     echo "Some files from the repository were already created in this machine, they have"
     58     echo "been moved to $backupdest."
     59 fi
     60 
     61 echo
     62 echo "Installation finished."