-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
274 lines (230 loc) · 9 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
#==============================================================================
# ███████╗██╗ ██╗███████╗██╗ ███╗ ██╗██╗███╗ ██╗ ██╗ █████╗
# ██╔════╝██║ ██║██╔════╝██║ ████╗ ██║██║████╗ ██║ ██║██╔══██╗
# ███████╗███████║█████╗ ██║ ██╔██╗ ██║██║██╔██╗ ██║ ██║███████║
# ╚════██║██╔══██║██╔══╝ ██║ ██║╚██╗██║██║██║╚██╗██║██ ██║██╔══██║
# ███████║██║ ██║███████╗███████╗ ██║ ╚████║██║██║ ╚████║╚█████╔╝██║ ██║
# ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚════╝ ╚═╝ ╚═╝
#==============================================================================
# color defination
red="\e[1;31m"
green="\e[1;32m"
yellow="\e[1;33m"
blue="\e[1;34m"
magenta="\e[1;1;35m"
cyan="\e[1;36m"
orange="\x1b[38;5;214m"
end="\e[1;0m"
# prompt function
msg() {
local actn=$1
local msg=$2
case "$actn" in
act)
echo -e "${green}=>${end} $msg"
;;
att)
echo -e "${yellow}!!${end} $msg"
;;
ask)
echo -e "${orange}??${end} $msg"
;;
dn)
echo -e "${cyan}::${end} $msg\n"
;;
skp)
echo -e "${magenta}[ SKIP ]${end} $msg"
;;
err)
echo -e "${red}>< Ohh no! an error...${end}\n $msg\n"
;;
esac
}
# log file
dir=`pwd`
log="$dir/bash-install-$(date +%I:%M_%p).log"
touch "$log"
# required packages
common_packages=(
bash-completion
bat
curl
eza
fastfetch
figlet
fzf
git
less
zoxide
)
for_opensuse=(
python311
python311-pip
python311-pipx
)
clear && printf "${green}::${end} Starting the script...\n"
sleep 1
echo
# asking some questions
msg ask "Would you like to install a Nerd font? In this case, the ${yellow}JetBrains Mono Nerd Font${end}? It is important. [ y/n ]"
read -p "Select: " font
echo
msg ask "Would you like to use ${cyan}starship${end} as the bash prompt? [ y/n ]"
read -p "Select: " prmpt
# package installation function
fn_install() {
local pkg=$1
if [ -n "$(command -v pacman)" ]; then # Arch Linux
if sudo pacman -Q "$pkg" &> /dev/null; then
msg skp "Skipping $pkg, it was already installed..."
else
msg act "Installing $pkg..."
sudo pacman -S --noconfirm "$pkg" 2>&1 | tee -a "$log" &> /dev/null
if sudo pacman -Q "$pkg" &> /dev/null; then
msg dn "$pkg was installed successfully!"
else
msg err "Could not install $pkg"
fi
fi
elif [ -n "$(command -v dnf)" ]; then # Fedora
if rpm -q "$pkg" &> /dev/null; then
msg skp "Skipping $pkg, it was already installed..."
else
msg act "Installing $pkg..."
sudo dnf install -y "$pkg" 2>&1 | tee -a "$log"
if rpm -q "$pkg" &> /dev/null; then
msg dn "$pkg was installed successfully!"
else
msg err "Could not install $pkg"
fi
fi
elif [ -n "$(command -v zypper)" ]; then # opensuse
if sudo zypper se -i "$pkg" &> /dev/null; then
msg skp "Skipping $pkg, it was already installed..."
else
msg act "Installing $pkg..."
sudo zypper in -y "$pkg" 2>&1 | tee -a "$log"
if sudo zypper se -i "$pkg" &> /dev/null; then
msg dn "$pkg was installed successfully!"
else
msg err "Could not install $pkg"
fi
fi
elif [ -n "$(command -v apt)" ]; then # debian
sudo apt install -y "$pkg" 2>&1 | tee -a "$log"
else
echo "Unsupported distribution."
return 1
fi
}
# install the packages
for pkgs in "${common_packages[@]}"; do
fn_install "$pkgs" 2>&1 | tee -a "$log"
done
if command -v zypper &> /dev/null; then
for pkgs in "${for_opensuse[@]}"; do
fn_install "$pkgs" 2>&1 | tee -a "$log"
done
# installing thefu*k
if command -v pipx &> /dev/null; then
pipx runpip thefuck install setuptools &> /dev/null
sleep 0.5
pipx install --python python3.11 thefuck &> /dev/null 2>&1 | tee -a "$log"
if command -v thefuck &> /dev/null; then
msg dn "thef*ck was installed successfully!" && sleep 1
fi
fi
elif command -v pacman &> /dev/null; then # Arch Linux
fn_install thefuck 2>&1 | tee -a "$log"
elif command -v dnf &> /dev/null; then # Fedora
fn_install thefuck 2>&1 | tee -a "$log"
fi
# installing starship
if command -v pacman &> /dev/null; then
fn_install starship
elif command -v zypper &> /dev/null; then
fn_install starship
elif command -v dnf &> /dev/null; then
sudo dnf copr enable -y atim/starship
fn_install starship
fi
msg act "Installing bash files..." && sleep 0.5
# Check and backup the directories and file
for item in "$HOME/.bash" "$HOME/.bashrc"; do
mkdir -p ~/.Bash-Backup-${USER}
if [[ -d $item ]]; then
case $item in
$HOME/.bash)
msg att "A ${green}.bash${end} directory is available. backing it up.."
mv "$item" "$HOME/.Bash-Backup-${USER}/.bash"-$(date +%I:%M:%S%p) 2>&1 | tee -a "$log"
;;
esac
elif [[ -f $item ]]; then
case $item in
$HOME/.bashrc)
msg att "A ${cyan}.bashrc${end} file is available, backing it up.."
mv "$item" "$HOME/.Bash-Backup-${USER}/.bashrc"-$(date +%I:%M:%S%p) 2>&1 | tee -a "$log"
;;
esac
fi
done
# now copy the .bash directory into the "$HOME" directory.
cp -r "$dir/.bash" "$HOME/" 2>&1 | tee -a "$log"
ln -sf ~/.bash/.bashrc ~/.bashrc 2>&1 | tee -a "$log"
# installing bash autosuggestions and syntal highlighting.
if [ -d ~/.bash ]; then
msg act "Updating some scripts..." && sleep 1
curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - 2>&1 | tee -a "$log" &> /dev/null
bash ble-nightly/ble.sh --install ~/.local/share 2>&1 | tee -a "$log" &> /dev/null
if [ -f ~/.blerc ]; then
msg act "Backing up ~/.blerc file"
mv ~/.blerc "$HOME/Bash-Backup-${USER}/"
ln -sf ~/.bash/.blerc ~/.blerc 2>&1 | tee -a "$log"
fi
if [[ "$prmpt" =~ ^[Y|y]$ ]]; then
if [ -f ~/.config/starship.toml ]; then
msg act "Backing up your old starship.toml..." && sleep 1
mv ~/.config/starship.toml ~/.config/starship.toml.back
fi
cp "$dir/starship.toml" "$HOME/.config/"
msg dn "Copied the new starship.toml file."
# Comment out the PS1 line
sed -i 's/^PS1=/# PS1=/' ~/.bash/.bashrc
# Uncomment the starship init bash line
sed -i 's/^# eval "\(.*starship init bash.*\)"/eval "\1"/' ~/.bash/.bashrc
msg dn "Updated .bashrc file. Commented out PS1 and enabled Starship prompt."
fi
fi
sleep 1
echo
if [[ "$font" =~ ^[Yy]$ ]]; then
msg act "Installing the ${yello}JetBrains Mono Nerd Font${end}"
DOWNLOAD_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/JetBrainsMono.tar.xz"
# Maximum number of download attempts
MAX_ATTEMPTS=2
for ((ATTEMPT = 1; ATTEMPT <= MAX_ATTEMPTS; ATTEMPT++)); do
curl -OL "$DOWNLOAD_URL" && break
msg att "Download attempt $ATTEMPT failed. Retrying in 2 seconds..."
sleep 2
done
# Check if the JetBrainsMono folder exists and delete it if it does
if [ -d ~/.local/share/fonts/JetBrainsMonoNerd ]; then
rm -rf ~/.local/share/fonts/JetBrainsMonoNerd &> /dev/null
fi
# Extract the new files into the JetBrainsMono folder and log the output
tar -xJkf JetBrainsMono.tar.xz -C ~/.local/share/fonts/JetBrainsMonoNerd
# Update font cache and log the output
sudo fc-cache -fv &> /dev/null
# clean up
if [ -d "JetBrainsMono.tar.xz" ]; then
rm -r JetBrainsMono.tar.xz &> /dev/null
fi
else
msg skp "Skipping installing the ${yellow}JetBrainsMono Nerd Font${end}.\n Please install a nerd font manually and set it to your terminal..."
fi
sleep 1 && clear
# Call the function with the message and a delay of 0.05 seconds
msg dn "Bash configuration has been completed! Close the tarminal and open it again." && sleep 2
exit 0
#__________ ( code finishes here ) __________#