irongit
dotzsh/install.sh
229 lines7.3 KBBourne Again Shell (bash)
1#!/bin/bash
2
3# Colored echos
4echop() {
5 echo -e "\e[35m$1\e[0m"
6}
7echor() {
8 echo -e "\e[31m$1\e[0m"
9}
10echog() {
11 echo -e "\e[32m$1\e[0m"
12}
13echot() {
14 echo -e "\e[36m$1\e[0m"
15}
16echob() {
17 echo -e "\e[34m$1\e[0m"
18}
19echoy() {
20 echo -e "\e[33m$1\e[0m"
21}
22
23# Clock animation
24BLA_clock=(๐Ÿ•› ๐Ÿ• ๐Ÿ•‘ ๐Ÿ•’ ๐Ÿ•“ ๐Ÿ•” ๐Ÿ•• ๐Ÿ•– ๐Ÿ•— ๐Ÿ•˜ ๐Ÿ•™ ๐Ÿ•š)
25
26# Use $prefix for commands that might need sudo
27prefix="$([[ $(whoami) == "root" ]] && echo "" || echo "sudo")"
28LAST_OUTPUT=$(mktemp)
29[ -d "$HOME" ] || { echor "$HOME is not a directory. You are cancelled." && exit 1; }
30export PATH="$PATH:/usr/local/go/bin:/usr/local/go/bin:$HOME/go/bin:$HOME/.local/bin"
31
32# Ensure sudo and run command in background with animation, returns 1 if there was an issue
33# $1: command used to check if the 2nd command should be ran ("" is always true)
34# $2: command to run in the background
35# $3: text to append to animation
36# $4: success message
37# $5: failure message (after LAST_OUTPUT)
38# $6: Ignore output if set
39animate() {
40 # Return when check is success
41 [[ -n "$1" ]] && eval "$1" && echob "โ„น๏ธ No action required. $4" && return 0
42
43 # Ensure sudo
44 [[ "$(whoami)" == "root" ]] || sudo -v || exit 1
45
46 # Run with output to tmp
47 eval "$2" &>"$LAST_OUTPUT" &
48
49 # Wait and animate the command
50 local pid=$!
51 while kill -0 $pid 2>/dev/null; do
52 for frame in "${BLA_clock[@]}"; do
53 printf "\r%s %s " "${frame}" "$3"
54 sleep 0.2
55 done
56 done
57
58 # Clear and output error if needed
59 printf "\033[2K\r"
60 { { wait $pid || [[ -n "$6" ]]; } && echog "โœ… $4"; } || { cat "$LAST_OUTPUT" && echor "\n๐Ÿ”ด $5" && return 1; }
61}
62
63echo "Ensuring base tools are installed."
64
65# Install basic tools on debian
66if [ -f /etc/debian_version ]; then
67 # Set the installer prefix
68 installer="$prefix apt-get -y"
69
70 # Update system
71 echop "Detected Debian. Updating and upgrading now!"
72 animate "" \
73 "$installer update && $installer upgrade" \
74 "Updating system" \
75 "System up to date!" \
76 "Failed to update system" || exit 1
77
78 # Install build essential
79 animate "dpkg -s build-essential &>/dev/null" \
80 "$installer install build-essential" \
81 "Installing build-essential" \
82 "build-essential installed" \
83 "Failed to install build-essential" || exit 1
84
85# Install basic tools for arch
86elif [ -f /etc/arch-release ]; then
87 # Set pacman prefix
88 installer="$prefix pacman"
89 install_cmd="$installer -S --noconfirm"
90
91 # Update system
92 echob "Arch Detected. You are elite. Updating and upgrading now!"
93 login_sudo
94 animate "$installer -Syu"
95 echog "โœ… System up to date!"
96
97 # Install base-devel
98 login_sudo
99 pacman -Q base-devel &>/dev/null ||
100 { echo "Installing base-devel" && animate "$installer base-devel" && printf "\e[1A\e[2K"; } ||
101 { cat /tmp/last_output && echor "Failed to install base-devel"; }
102 echog "โœ… base-devel installed"
103
104 # Install paru
105 login_sudo
106 command -v paru &>/dev/null ||
107 { echo "Installing paru" && animate "git clone https://aur.archlinux.org/paru.git /tmp/paru &&
108 cd /tmp/paru && makepkg -si" && printf "\e[1A\e[2K"; } ||
109 { cat /tmp/last_output && echor "Failed to install paru"; }
110 echog "โœ… paru installed"
111fi
112
113# Install zsh
114animate "command -v zsh &>/dev/null" \
115 "$installer install zsh" \
116 "Installing zsh" \
117 "zsh installed" \
118 "Failed to install zsh" || exit 1
119
120# Install curl (crazy but this happens sometimes)
121animate "command -v curl &>/dev/null" \
122 "$installer install curl" \
123 "Installing curl" \
124 "curl installed" \
125 "Failed to install curl" || exit 1
126
127# Install unzip
128animate "command -v unzip &>/dev/null" \
129 "$installer install unzip" \
130 "Installing unzip" \
131 "unzip installed" \
132 "Failed to install unzip" || exit 1
133
134# Install git
135animate "command -v git &>/dev/null" \
136 "$installer install git" \
137 "Installing git" \
138 "git installed" \
139 "Failed to install git" || exit 1
140
141# Install cargo
142animate "[ -f ~/.cargo/env ]" \
143 "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" \
144 "Installing cargo" \
145 "cargo installed" \
146 "Failed to install cargo" || exit 1
147. ~/.cargo/env
148
149# Install lsd with cargo
150animate "command -v lsd &>/dev/null" \
151 "cargo install lsd" \
152 "Installing lsd" \
153 "lsd installed" \
154 "Failed to install cargo" || exit 1
155
156# Install golang
157latest_go_version="$(curl -fsSL "https://go.dev/VERSION?m=text" | head -1)"
158filename="$latest_go_version.$([[ "$(uname -m)" == "Linux" ]] && { printf "linux"; } || printf "darwin").$(uname -m).tar.gz"
159animate "[[ \"$(go version 2>/dev/null | awk '{print $3}')\" == \"$latest_go_version\" ]]" \
160 "curl -fsSL https://go.dev/dl/go1.26.1.linux-amd64.tar.gz | $prefix tar xvzf - -C /usr/local" \
161 "Installing go" \
162 "go installed" \
163 "Failed to install go" || exit 1
164
165# Install lazygit with go
166animate "command -v lazygit &>/dev/null" \
167 "go install github.com/jesseduffield/lazygit@latest" \
168 "Installing lazygit" \
169 "lazygit installed" \
170 "Failed to install lazygit" || exit 1
171
172# Install yazi
173filename="yazi-$(uname -m)-$(
174 { [[ "$(uname -s)" == "Linux" ]] && printf "unknown-linux-%s" "$(ldd --version 2>&1 | grep -qi musl && echo musl || echo gnu)"; } || printf "apple-darwin"
175).zip"
176animate "[ -d /usr/local/yazi ]" \
177 "rm -rf /tmp/yazi* && $prefix rm -rf /usr/local/yazi &&
178 curl -fsSL https://github.com/sxyazi/yazi/releases/download/v26.1.22/yazi-x86_64-unknown-linux-gnu.zip -o /tmp/yazi.zip &&
179 unzip /tmp/yazi.zip -d /tmp && $prefix mv /tmp/yazi-x86_64-unknown-linux-gnu/ /usr/local/yazi/ && $prefix mv /usr/local/yazi/ya* /usr/local/bin" \
180 "Installing yazi" \
181 "yazi installed" \
182 "Failed to install yazi" || exit 1
183
184# Install fnm
185animate "[ -d ~/.local/share/fnm ]" \
186 "curl -fsSL https://fnm.vercel.app/install | bash" \
187 "Installing fnm" \
188 "fnm installed" \
189 "Failed to install fnm" \
190 "ignore fail"
191
192# Install uv
193animate "[ -f ~/.local/bin/uv ]" \
194 "curl -LsSf https://astral.sh/uv/install.sh | sh" \
195 "Installing uv" \
196 "uv installed" \
197 "Failed to install uv" || exit 1
198[ -f ~/.venv/bin/activate ] || (cd ~ && uv venv &>/dev/null)
199
200# Install zoxide
201animate "[ -f ~/.local/bin/zoxide ]" \
202 "curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh" \
203 "Installing zoxide" \
204 "zoxide installed" \
205 "Failed to install zoxide"
206
207# Create backups
208[ -d ~/.config ] || mkdir -p ~/.config
209[ -f ~/.zshrc ] && mv ~/.zshrc ~/.zshrc.bak && echot "Backup ~/.zshrc -> ~/.zshrc.bak"
210[ -f ~/.zshenv ] && mv ~/.zshenv ~/.zshenv.bak && echot "Backup ~/.zshenv -> ~/.zshenv.bak"
211[ -d ~/.config/zsh ] && rm -rf ~/.config/zsh.bak && mv ~/.config/zsh ~/.config/zsh.bak
212
213# Clone config repo
214echo 'export ZDOTDIR=$HOME/.config/zsh' >~/.zshenv
215export ZDOTDIR=$HOME/.config/zsh
216animate "" \
217 "git clone https://github.com/huncholane/dotzsh ~/.config/zsh" \
218 "Cloning dotzsh" \
219 "dotzsh cloned. Just a few more things." \
220 "Failed to clone dotzsh" || exit 1
221
222# Install antidote
223animate "[ -d ~/.config/zsh/.antidote ]" \
224 "git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-~}/.antidote" \
225 "Installing antidote" \
226 "antidote installed" \
227 "Failed to install antidote" || exit 1
228
229echot "\nRun 'exec zsh' to see the magic"