Repository navigation
Expand file tree
/
Copy pathsunshine.sh
More file actions
executable file
·204 lines (173 loc) · 5.19 KB
/
Copy pathsunshine.sh
File metadata and controls
executable file
·204 lines (173 loc) · 5.19 KB
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
#!/bin/bash
set -e
set -o pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
RESET='\033[0m'
package_manager=("apt" "apt-get" "yum" "dnf" "zypper" "pacman")
## --- HELPER FUNCTIONS ---
job_done() {
printf "${GREEN} %s${RESET}\n" "$1"
}
info() {
printf "${CYAN} %s${RESET}\n" "$1"
}
step_counter() {
printf "${PURPLE} %s${RESET}\n" "$1"
}
info_handler() {
printf "${YELLOW} %s${RESET}\n" "$1"
}
error_handler(){
printf "${RED}Error: %s${RESET}\n" "$1" >&2
exit "${2:-1}"
}
# TOOLS TO INSTALL
## Neovim
install_nvim(){
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz >> install.log 2>&1 || error_handler "Curl error to fetch neovim tarball" 2
sudo rm -rf /opt/nvim-linux-x86_64 >> nvim_install.log 2>&1 || error_handler "Could not delete directory" 2
sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz >> nvim_install.log 2>&1 || error_handler "Tar extraction failed" 2
echo 'export PATH="$PATH:/opt/nvim-linux-x86_64/bin"' >> $HOME/.bashrc
job_done "Cleaning up"
rm -rf nvim-* || "Failed to clean up neovim install" 2
}
## nvim Kickstart
install_kick(){
git clone https://github.com/nvim-lua/kickstart.nvim.git "${XDG_CONFIG_HOME:-$HOME/.config}"/nvim >> kick.log 2>&1 || error_handler "Failed to clone neovim" 2
job_done "Kickstart cloned and working"
}
# Set ZSH as the default shell
install_omz(){
## Install oh-my-zsh
RUNZSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" <<< "y" >> omz.log 2>&1 || error_handler "Failed to install oh-my-zsh" 2
}
add_nvim_zshrc(){
# Export neovim to PATH after oh-my-zsh is installed and zshrc file is set
echo 'export PATH="$PATH:/opt/nvim-linux-x86_64/bin"' >> $HOME/.zshrc || error_handler "failed to export to path" 2
}
change_shell(){
if [ "$(basename -- "$SHELL")" != "zsh" ]; then
info_handler "Changing default shell to zsh..."
sudo chsh -s "$(command -v zsh)" "$USER" || error_handler "Failed to change default shell" 2
else
info_handler "zsh is already the default shell"
fi
}
cleanup(){
# Collecting logs into one directory
job_done "Tidying up the room..."
mkdir -p sunshine-logs && mv ./*.log sunshine-logs
}
# --- CONFIRM OS AND PACKAGE MANAGER BEFORE START INSTALLING ---
os_pm(){
for manager in "${package_manager[@]}"; do
if command -v "$manager" > /dev/null 2>&1; then
case $manager in
"apt-get"|"apt")
pm="apt-get";
break
;;
"dnf"|"yum")
pm="dnf";
break
;;
"pacman")
pm="pacman";
break
;;
"zypper")
pm="zypper";
break
;;
*)
echo "We do not support this distribution yet."
exit 1
;;
esac
fi
done
info_handler "Package Manager Found: $pm"
}
# --- INSTALLATION FUNCTIONS ---
installer(){
case $pm in
"apt-get")
comm_update="update"
comm_install=(install -y)
essentials=(zsh unzip wget git build-essential libreadline-dev ripgrep fd-find xclip tree-sitter-cli)
;;
"dnf")
comm_update="upgrade"
comm_install=(install -y)
essentials=(zsh unzip wget git gcc gcc-c++ make glibc-devel readline-devel ripgrep fd-find xclip tree-sitter-cli)
;;
"pacman")
comm_update="-Syu"
comm_install=(-S --noconfirm)
essentials=(zsh unzip wget git gcc make glibc readline ripgrep fd xclip tree-sitter-cli)
;;
"zypper")
comm_update="refresh"
comm_install=(install -y)
essentials=(zsh unzip wget git gcc gcc-c++ make glibc-devel readline-devel ripgrep fd xclip tree-sitter)
;;
*)
info_handler "Keep your secrets then"
exit 1;
;;
esac
step_counter "Step 1 of 5"
info_handler "Updating the system..."
cd $HOME
sudo "$pm" "$comm_update" >> updater.log 2>&1 || error_handler "Failed to update the system..." 2
job_done "System up to date"
step_counter "Step 2 of 5"
info_handler "Installing essentials"
for i in "${essentials[@]}"; do
sudo "$pm" "${comm_install[@]}" "$i" >> updater.log 2>&1 || error_handler "Failed to install essential package" 2
done
job_done "Essentials packages installed"
step_counter "Step 3 of 5"
if [ ! -d "/opt/nvim-linux-x86_64" ]; then
info_handler "Installing Neovim..."
install_nvim
else
info_handler "You already have neovim installed. Skipping this step."
fi
step_counter "Step 4 of 5"
if [ ! -d "${XDG_CONFIG_HOME:-$HOME/.config}/nvim" ]; then
info_handler "Kickstarting...(see what I did)..."
install_kick
else
info_handler "You already have the kickstart template installed. Skipping this step"
fi
step_counter "Step 5 of 5"
if [ ! -d "${ZDOTDIR:-$HOME/.oh-my-zsh}" ]; then
info_handler "Installing oh-my-zsh..."
install_omz
add_nvim_zshrc
else
info_handler "You already have oh-my-zsh installed. Skipping this step."
add_nvim_zshrc
fi
}
# Summary function
summary(){
info "Your system has been updated and new tools have been installed and configured."
info "You have the latest version of Neovim with the Kickstart plugin installed."
info "You have the latest version of Oh-My-Zsh installed, and zsh is the default shell"
info "Restart the shell session, run nvim, it will install the necessary plugins."
}
# Actually implement the Script
main(){
os_pm
installer
change_shell
cleanup
summary
}
main