PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/install.sh

https://github.com/tomsquest/dotfiles
Shell | 149 lines | 129 code | 19 blank | 1 comment | 11 complexity | 94e603bb12272377d6ac76b677b19bac MD5 | raw file
  1. #!/bin/bash
  2. set -euo pipefail
  3. function make-paths {
  4. echo "Creating additional PATH directories..."
  5. mkdir -p "$HOME/.local/bin"
  6. echo "Creating additional MANPATH directories..."
  7. mkdir -p "$HOME"/.local/man/man{1..8}
  8. }
  9. function create-link {
  10. local -r SRC=$1
  11. local -r DEST=$2
  12. mkdir -p "$(dirname "$DEST")"
  13. if ! [ -L "$DEST" ]; then
  14. ln -ivs "$SRC" "$DEST"
  15. else
  16. echo "Skipping, link already exists: $DEST"
  17. fi
  18. }
  19. function install-from-git-repo {
  20. local -r name="$1"
  21. local -r repo="$2"
  22. local -r dest="$3"
  23. echo "Installing $name..."
  24. if [ -d "$dest" ]; then
  25. (cd "$dest" && git pull --progress)
  26. else
  27. rm -rf "$dest"
  28. git clone --progress "$repo" "$dest"
  29. fi
  30. }
  31. function link-files {
  32. echo "Linking files..."
  33. create-link "$PWD/albertignore" "$HOME/.albertignore"
  34. create-link "$PWD/bashrc" "$HOME/.bashrc"
  35. create-link "$PWD/bin" "$HOME/bin"
  36. create-link "$PWD/gitconfig" "$HOME/.gitconfig"
  37. create-link "$PWD/gitignore" "$HOME/.gitignore"
  38. create-link "$PWD/imwheelrc" "$HOME/.imwheelrc"
  39. create-link "$PWD/libinput-gestures.conf" "$HOME/.config/libinput-gestures.conf"
  40. create-link "$PWD/npmrc" "$HOME/.npmrc"
  41. create-link "$PWD/profile" "$HOME/.profile"
  42. create-link "$PWD/ripgreprc" "$HOME/.ripgreprc"
  43. create-link "$PWD/safe-rm" "$HOME/.safe-rm"
  44. create-link "$PWD/terminator.conf" "$HOME/.config/terminator/config"
  45. create-link "$PWD/vim" "$HOME/.vim"
  46. create-link "$PWD/vimrc" "$HOME/.vimrc"
  47. create-link "$PWD/zsh" "$HOME/.zsh"
  48. create-link "$PWD/zshrc" "$HOME/.zshrc"
  49. for file in $PWD/desktop-shortcuts/*
  50. do
  51. create-link "$file" "$HOME/.local/share/applications/$(basename "$file")"
  52. done
  53. }
  54. function install-fzf {
  55. echo "Installing FZF..."
  56. local -r URL=$(curl -s https://api.github.com/repos/junegunn/fzf-bin/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4)
  57. echo "- Binary"
  58. curl -L --progress-bar "$URL" | tar xz -C /tmp fzf && mv /tmp/fzf $HOME/.local/bin/
  59. echo "- Man page"
  60. curl -sL "https://raw.githubusercontent.com/junegunn/fzf/master/man/man1/fzf.1" > $HOME/.local/man/man1/fzf.1
  61. mkdir -p $HOME/.local/fzf
  62. echo "- Completion"
  63. curl -sL "https://raw.githubusercontent.com/junegunn/fzf/master/shell/completion.zsh" > $HOME/.local/fzf/completion.zsh
  64. echo "- Key bindings"
  65. curl -sL "https://raw.githubusercontent.com/junegunn/fzf/master/shell/key-bindings.zsh" > $HOME/.local/fzf/key-bindings.zsh
  66. }
  67. function install-ripgrep {
  68. echo "Installing Ripgrep..."
  69. local -r TMP_DIR=$(mktemp -d)
  70. local -r URL=$(curl -s https://api.github.com/repos/BurntSushi/ripgrep/releases/latest | grep browser_download_url | grep x86_64-unknown-linux | cut -d '"' -f 4)
  71. curl -L --progress-bar "$URL" | tar zx -C "$TMP_DIR" --strip 1 --wildcards '*/rg' --wildcards '*/rg.1' \
  72. && mv "$TMP_DIR/rg" $HOME/.local/bin/ \
  73. && mv "$TMP_DIR/doc/rg.1" $HOME/.local/man/man1 \
  74. && rm -rf "$TMP_DIR"
  75. }
  76. function install-docker-compose {
  77. echo "Installing Docker-Compose..."
  78. local -r URL=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep Linux-x86_64\" | cut -d '"' -f 4)
  79. local -r DEST="$HOME/.local/bin/docker-compose"
  80. curl -L --progress-bar "$URL" > "$DEST" \
  81. && chmod +x "$DEST"
  82. }
  83. function install-direnv {
  84. echo "Installing Direnv..."
  85. local -r URL=$(curl -s https://api.github.com/repos/direnv/direnv/releases/latest | grep browser_download_url | grep linux-amd64\" | cut -d '"' -f 4)
  86. local -r DEST="$HOME/.local/bin/direnv"
  87. curl -L --progress-bar "$URL" > "$DEST" \
  88. && chmod +x "$DEST"
  89. }
  90. function install-vim-plugins {
  91. echo "Installing Vim plugins..."
  92. vim +PluginInstall +qall
  93. }
  94. function install-dircolors {
  95. echo "Installing dircolors..."
  96. curl -sl "https://raw.githubusercontent.com/seebi/dircolors-solarized/master/dircolors.ansi-dark" > ~/.dircolors
  97. }
  98. function install-direnv {
  99. echo "Installing Direnv through asdf..."
  100. source $HOME/.asdf/asdf.sh
  101. asdf plugin add direnv || true
  102. asdf install direnv 2.20.0
  103. asdf global direnv 2.20.0
  104. echo "source \$(asdf which direnv_use_asdf)" > ~/.config/direnv/direnvrc
  105. }
  106. function copy-sysctl-conf {
  107. echo "Copying sysctl config files..."
  108. for file in $PWD/sysctl.d/*
  109. do
  110. sudo cp "$file" "/etc/sysctl.d/$(basename "$file")"
  111. done
  112. }
  113. function install-all {
  114. make-paths
  115. link-files
  116. install-from-git-repo "Rupa-Z" "https://github.com/rupa/z" "$HOME/.rupa-z"
  117. install-from-git-repo "Zgen" "https://github.com/tarjoilija/zgen" "$HOME/.zgen"
  118. install-from-git-repo "Bash-Sensible" "https://github.com/mrzool/bash-sensible" "$HOME/.bash-sensible"
  119. install-from-git-repo "Vim Vundle" "https://github.com/VundleVim/Vundle.vim" "$HOME/.vundle"
  120. install-from-git-repo "Asdf-vm" "https://github.com/asdf-vm/asdf" "$HOME/.asdf"
  121. install-fzf
  122. install-ripgrep
  123. install-docker-compose
  124. install-vim-plugins
  125. install-dircolors
  126. install-direnv
  127. copy-sysctl-conf
  128. }
  129. install-all