bootstrap.sh (1829B) - 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 
     36 if [ "$smallinstall" = "1" ]; then
     37     for file in $(gitdotfiles ls-files | sed '/^\.config\/\(zsh\|git\/config\|nvim\|tmux\)\|^\.zshenv/d'); do
     38         rm -f "$HOME/$file"
     39         gitdotfiles update-index --skip-worktree "$HOME/$file"
     40         rmdir -p "$(dirname "$HOME/$file")" 2>/dev/null
     41     done
     42 fi
     43 
     44 rm -f "$HOME/README.md" "$HOME/COPYING" "$HOME/bootstrap.sh"
     45 gitdotfiles update-index --skip-worktree "$HOME/README.md" "$HOME/COPYING" "$HOME/bootstrap.sh"
     46 
     47 cd "$HOME"
     48 rm -rf "$tempdir"
     49 
     50 if [ -d "$backupdest" ]; then
     51     echo
     52     echo "Some files from the repository were already created in this machine, they have"
     53     echo "been moved to $backupdest."
     54 fi
     55 
     56 echo
     57 echo "Installation finished."