-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
225 lines (211 loc) · 11.2 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env bash
INSTALL_TYPE="${1:-min}" # Defaults to minimal install
INSTALL_TYPE="${INSTALL_TYPE,,}" # Lowercase
main() {
source /etc/os-release
case $ID in
alpine|ubuntu)
run_install $ID
;;
*)
echo "$ID is not supported"
;;
esac
}
run_install() { echo "Running $1 installer"; cd "$HOME" || exit 1; "${1}_install"; }
set_url_and_version() {
repo_name=$(echo "$1" | cut -d"/" -f2)
repo_name=${repo_name^^} # Uppercase
repo_name=${repo_name//-/_} # Convert `-` to `_`
# Sets release url e.g. RIPGREP_URL=https://github.com/BurntSushi/ripgrep/releases/latest/download
eval "${repo_name}_URL"="https://github.com/$1/releases/latest/download"
latest_tag=$(curl -sL "https://api.github.com/repos/$1/releases/latest" | grep tag_name | cut -d '"' -f4)
# Strip v (first charcter) from tag
if [ "$2" = "true" ]; then latest_tag="${latest_tag:1}"; fi
# Sets release version e.g. RIPGREP_VERSION=14.1.0
eval "${repo_name}_VERSION"="$latest_tag"
}
set_all_url_and_version() {
set_url_and_version "jqlang/jq"
set_url_and_version "sxyazi/yazi"
set_url_and_version "neovim/neovim"
set_url_and_version "dandavison/delta"
set_url_and_version "BurntSushi/ripgrep"
set_url_and_version "scarvalhojr/aoc-cli"
set_url_and_version "sharkdp/fd" true
set_url_and_version "sharkdp/bat" true
set_url_and_version "eza-community/eza" true
set_url_and_version "jesseduffield/lazygit" true
}
common_root_install() {
# Manual install of man pages for release binaries
sudo mkdir -p /usr/local/share/man/man1
# Set release url and version
set_all_url_and_version
# Install MUSL ripgrep from source
[ -n "$RIPGREP_VERSION" ] && \
curl -sL "$RIPGREP_URL/ripgrep-$RIPGREP_VERSION-x86_64-unknown-linux-musl.tar.gz" \
| tar xz "ripgrep-${RIPGREP_VERSION}-x86_64-unknown-linux-musl/rg" "ripgrep-$RIPGREP_VERSION-x86_64-unknown-linux-musl/doc/rg.1" --strip-components=1 && \
sudo install rg /usr/local/bin && sudo mv doc/rg.1 /usr/local/share/man/man1 && rm -r rg doc
# Install MUSL aoc-cli from source
[ -n "$AOC_CLI_VERSION" ] && \
curl -sL "$AOC_CLI_URL/aoc-cli-$AOC_CLI_VERSION-x86_64-unknown-linux-musl.tar.gz" \
| tar xz "aoc-cli-${AOC_CLI_VERSION}-x86_64-unknown-linux-musl/aoc" --strip-components=1 && \
sudo install aoc /usr/local/bin && rm aoc
# Install LINUX lazygit from source
[ -n "$LAZYGIT_VERSION" ] && \
curl -sL "$LAZYGIT_URL/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" | tar xz lazygit && \
sudo install lazygit /usr/local/bin && rm lazygit
# Install LINUX jq
[ -n "$JQ_VERSION" ] && \
curl -sLo jq "$JQ_URL/jq-linux-amd64" && \
curl -sL "$JQ_URL/$JQ_VERSION.tar.gz" | tar xz "$JQ_VERSION/jq.1" --strip-components=1 && \
sudo install jq /usr/local/bin && sudo mv jq.1 /usr/local/share/man/man1 && rm jq
# Install zoxide
curl -sLS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh |\
bash -s -- --bin-dir /usr/local/bin --man-dir /usr/local/share/man >/dev/null
}
common_user_install() {
# Create the top level directories before stowing so that stow does not symlink from the top level
mkdir -p "$HOME/.config/"{nvim,tmux,yazi,zsh} "$HOME/.vim"
# Clone the dotfiles
[ -d "$HOME/dotfiles" ] || git clone --depth=1 https://github.com/mau-mauricelim/dotfiles.git "$HOME/dotfiles" >/dev/null
# Stow the dotfiles
cd "$HOME/dotfiles" && git pull https://github.com/mau-mauricelim/dotfiles.git HEAD && \
git remote set-url origin [email protected]:mau-mauricelim/dotfiles.git && \
stow . && git restore . && cd "$HOME" || exit 1
# Create a symlink for zshenv to HOME
ln -sf "$HOME/.config/zsh/.zshenv" "$HOME/.zshenv"
# Source the latest zshenv
source "$HOME/.zshenv"
# Create ZDOTDIR and XDG_DATA_HOME directories
mkdir -p "$ZDOTDIR" "$XDG_DATA_HOME/"{nvim,vim}/{undo,swap,backup}
# Zsh Theme - Powerlevel10k (Requires manual font installation)
[ -d "$ZDOTDIR/powerlevel10k" ] || git clone -q --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZDOTDIR/powerlevel10k"
# Zsh Auto Suggestions
[ -d "$ZDOTDIR/zsh-autosuggestions" ] || git clone -q --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$ZDOTDIR/zsh-autosuggestions"
# Zsh Syntax Highlighting
[ -d "$ZDOTDIR/fast-syntax-highlighting" ] || git clone -q --depth=1 https://github.com/zdharma-continuum/fast-syntax-highlighting.git "$ZDOTDIR/fast-syntax-highlighting"
# fzf
[ -d "$ZDOTDIR/fzf" ] || git clone -q --depth 1 https://github.com/junegunn/fzf.git "$ZDOTDIR/fzf"
command -v fzf >/dev/null || "$ZDOTDIR/fzf/install" --xdg --no-update-rc --completion --key-bindings >/dev/null 2>&1
# Vim syntax and indent
mkdir -p "$HOME/.vim/"{indent,syntax}
[ -d "$HOME/.vim/vim-qkdb-syntax" ] || git clone -q --depth=1 https://github.com/katusk/vim-qkdb-syntax.git "$HOME/.vim/vim-qkdb-syntax"
ln -sf "$HOME/.vim/vim-qkdb-syntax/indent/"{k,q}.vim "$HOME/.vim/indent"
ln -sf "$HOME/.vim/vim-qkdb-syntax/syntax/k.vim" "$HOME/.vim/syntax"
[ -d "$HOME/.vim/vim-q-syntax" ] || git clone -q --depth=1 https://github.com/jshinonome/vim-q-syntax.git "$HOME/.vim/vim-q-syntax"
ln -sf "$HOME/.vim/vim-q-syntax/syntax/q.vim" "$HOME/.vim/syntax"
# Symlink Vim syntax and indent files to Neovim
ln -sf "$HOME/.vim/indent" "$XDG_CONFIG_HOME/nvim" && \
ln -sf "$HOME/.vim/syntax" "$XDG_CONFIG_HOME/nvim"
# bash and zsh key bindings for Git objects, powered by fzf.
[ -f "$XDG_CONFIG_HOME/fzf/fzf-git.sh" ] || curl -sLo "$XDG_CONFIG_HOME/fzf/fzf-git.sh" https://raw.githubusercontent.com/junegunn/fzf-git.sh/main/fzf-git.sh
# TPM installation
[ "$INSTALL_TYPE" = "full" ] && \
git clone -q --depth=1 https://github.com/tmux-plugins/tpm "$XDG_CONFIG_HOME/tmux/plugins/tpm" && "$XDG_CONFIG_HOME/tmux/plugins/tpm/bin/install_plugins"
# Install nvm, node.js, and npm
if ! command -v npm >/dev/null; then
PROFILE=/dev/null bash -c 'curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash >/dev/null' && \
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "$HOME/.nvm" || printf %s "$XDG_CONFIG_HOME/nvm")"; \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
nvm install node >/dev/null
fi
# Install q language server for neovim
sudo npm --global i @jo.shinonome/qls yarn || npm --global i @jo.shinonome/qls yarn
# Install yazi themes
git clone -q --depth=1 https://github.com/yazi-rs/flavors.git flavors && \
mkdir -p "$XDG_CONFIG_HOME/yazi/flavors" && \
cp -r flavors/*.yazi "$XDG_CONFIG_HOME/yazi/flavors" && rm -rf flavors
# Run Lazy install, clean and update non-interactively from command line inside tmux
[ "$INSTALL_TYPE" = "full" ] && \
tmux new -d "nvim --headless '+Lazy! sync' +qa && echo 'nvim sync lazy from the cmdline in tmux complete' |& tee /tmp/tmux.log"
timeout 60s bash -c -- 'while true; do if grep -q "nvim sync lazy from the cmdline in tmux complete" /tmp/tmux.log >/dev/null 2>&1; then rm /tmp/tmux.log; break; fi; done'
# Start zsh and exit (It'll allow powerlevel10k to do everything it needs to do on first run.)
echo exit | script -qec zsh /dev/null >/dev/null
# Set Zsh as the default shell
sudo chsh -s "$(which zsh)"
# Clear the npm cache
[ -d "$HOME/.npm" ] && rm -rf "$HOME/.npm"
# Clean up tmp directories
rm -rf /tmp/tmp.*
}
install_fd() {
[ -n "$FD_VERSION" ] && \
curl -sL "$FD_URL/fd-v$FD_VERSION-x86_64-unknown-linux-$1.tar.gz" \
| tar xz "fd-v$FD_VERSION-x86_64-unknown-linux-$1/fd" "fd-v$FD_VERSION-x86_64-unknown-linux-$1/fd.1" --strip-components=1 && \
sudo install fd /usr/local/bin && sudo mv fd.1 /usr/local/share/man/man1 && rm fd
}
install_bat() {
[ -n "$BAT_VERSION" ] && \
curl -sL "$BAT_URL/bat-v$BAT_VERSION-x86_64-unknown-linux-$1.tar.gz" \
| tar xz "bat-v$BAT_VERSION-x86_64-unknown-linux-$1/bat" "bat-v$BAT_VERSION-x86_64-unknown-linux-$1/bat.1" --strip-components=1 && \
sudo install bat /usr/local/bin && sudo mv bat.1 /usr/local/share/man/man1 && rm bat
}
install_eza() {
[ -n "$EZA_VERSION" ] && \
curl -sL "$EZA_URL/eza_x86_64-unknown-linux-$1.tar.gz" | tar xz && \
curl -sL "$EZA_URL/man-$EZA_VERSION.tar.gz" | tar xz "./target/man-$EZA_VERSION/eza.1" --strip-components=3 && \
sudo install eza /usr/local/bin && sudo mv eza.1 /usr/local/share/man/man1 && rm eza
}
install_delta() {
[ -n "$DELTA_VERSION" ] && \
curl -sL "$DELTA_URL/delta-$DELTA_VERSION-x86_64-unknown-linux-$1.tar.gz" \
| tar xz "delta-$DELTA_VERSION-x86_64-unknown-linux-$1/delta" --strip-components=1 && \
sudo install delta /usr/local/bin && rm delta
}
install_yazi() {
[ -n "$YAZI_VERSION" ] && \
curl -sLo yazi.zip "$YAZI_URL/yazi-x86_64-unknown-linux-$1.zip" && \
unzip -qj yazi.zip "yazi-x86_64-unknown-linux-$1/yazi" && \
sudo install yazi /usr/local/bin && rm yazi yazi.zip
}
# Alpine uses MUSL binaries
alpine_install() {
# Install required packages
# coreutils is for dircolors
# procps is for vim-tmux-navigator
# build-base installs a C compiler for nvim-treesitter
# Busybox binaries (default) doesn't support all features. E.g. `grep -P`
# util-linux-misc is for script and column
# docs installs the documentation companion package
# shadow is for chsh and usermod
# ncurses installs tput for fzf-git (fzf-tmux)
sudo apk -q --no-progress --no-cache add \
tar bzip2 rlwrap curl git vim stow openssh tmux grep neovim \
mandoc man-pages less docs \
zsh coreutils procps build-base xclip util-linux-misc nodejs npm shadow ncurses
# Common root installs
common_root_install
# Install MUSL binaries from source
for bin in fd bat eza delta yazi; do "install_$bin" musl; done
# Common user installs
common_user_install
}
ubuntu_install() {
# Install required packages
# ca-certificates is required for build success
# file is required for yazi
# build-essential installs a C compiler for nvim-treesitter
sudo apt-get -qq update >/dev/null 2>&1 && \
sudo apt-get -qq install -y --no-install-recommends \
zsh tar bzip2 unzip rlwrap curl ca-certificates git vim man less stow openssh-server tmux file build-essential xclip >/dev/null
# Common root installs
common_root_install
# Install GNU binaries from source
for bin in fd bat eza delta yazi; do "install_$bin" gnu; done
# Install GNU Neovim from source
curl -LO "$NEOVIM_URL/nvim-linux64.tar.gz" && \
sudo rm -rf /opt/nvim && \
sudo tar -C /opt -xzf nvim-linux64.tar.gz && rm nvim-linux64.tar.gz
# Common user installs
common_user_install
# Clean up
sudo apt-get -qq remove ca-certificates >/dev/null && \
sudo apt-get -qq autoclean -y && \
sudo apt-get -qq clean -y && \
sudo apt-get -qq autoremove -y >/dev/null && \
sudo rm -rf /var/cache/apt/archives /var/lib/apt/lists
}
# This is put in braces to ensure that the script does not run until it is downloaded completely
{ main "$@" || exit 1; }