-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·238 lines (199 loc) · 6.5 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
#!/bin/sh
FMT_RED=$(printf "\033[31m")
FMT_GREEN=$(printf "\033[32m")
FMT_YELLOW=$(printf "\033[33m")
FMT_BLUE=$(printf "\033[34m")
FMT_CYAN=$(printf "\033[36m")
FMT_BOLD=$(printf "\033[1m")
FMT_RESET=$(printf "\033[0m")
SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
ZUNDER_ZSH_DIR="$HOME/.config/zunder-zsh"
set -e
command_exists() {
command -v "$@" >/dev/null 2>&1
}
fmt_error() {
printf "%sError: %s%s\n" "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
}
fmt_warning() {
printf "%s%s%s\n" "${FMT_BOLD}${FMT_YELLOW}" "$*" "$FMT_RESET"
}
fmt_success() {
printf "%s%s%s\n" "$FMT_GREEN" "$*" "$FMT_RESET"
}
fmt_info() {
printf "%s:: %s%s%s\n" "${FMT_BOLD}${FMT_CYAN}" "${FMT_RESET}${FMT_BOLD}" "$*" "$FMT_RESET"
}
fmt_prompt() {
printf "%s:: %s%s%s" "${FMT_BOLD}${FMT_BLUE}" "${FMT_RESET}${FMT_BOLD}" "$*" "$FMT_RESET"
}
print_line() {
printf "%*s\n" "$(stty size | cut -d ' ' -f2)" '' | tr ' ' '-'
}
install_icons() {
fmt_info "Installing icons..."
# Create directory if it doesn't exist
mkdir -p "$HOME/.local/share/fonts"
# Download font file
curl -fLo "$HOME/.local/share/fonts/Symbols Nerd Font.ttf" \
"https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/NerdFontsSymbolsOnly/SymbolsNerdFont-Regular.ttf" \
|| return 1
}
install_package() {
fmt_prompt "Do you want to install $*? [Y/n] "
read -r response
if [ "$response" != "n" ] && [ "$response" != "N" ]; then
case $os_type in
"arch") sudo pacman -S --noconfirm "$*" ;;
*debian*) sudo apt install -y "$*" ;;
"fedora") sudo dnf install --assumeyes "$*" ;;
"opensuse suse") sudo zypper install -y "$*" ;;
"darwin") brew install "$*" ;;
"android") pkg install -y "$*" ;;
"void") sudo xbps-install -y "$*" ;;
*)
echo
fmt_error "Zunder-zsh doesn't support automatic package installations" \
"in your current operating system."
echo "Please do it manually."
exit 1
;;
esac || {
fmt_error "Installation failed."
exit 1
}
else
return 1
fi
}
check_os_type() {
if [ -f /etc/os-release ]; then
. /etc/os-release
[ -n "$ID_LIKE" ] && os_type="$ID_LIKE" || os_type="$ID"
else
[ "$(uname)" = "Darwin" ] && os_type="darwin"
case "$PREFIX" in
*com.termux*) os_type="android" ;;
esac
fi
if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ]; then
is_wsl=true
fmt_info "WSL detected."
fi
case $os_type in
"arch")
fmt_info "You are using an Arch-like distro."
;;
*debian*)
fmt_info "You are using a Debian-like distro."
;;
"fedora")
fmt_info "You are using a Fedora-like distro."
;;
"opensuse suse")
fmt_info "You are using an OpenSuse-like distro."
;;
"darwin")
fmt_info "You are using MacOS."
;;
"android")
fmt_info "You are using Termux on Android."
;;
"void")
fmt_info "You are using Void Linux."
;;
*)
fmt_warning "The type of your operating system couldn't be detected."
echo "The functionality of the installer will be limited."
fmt_prompt "Continue? [Y/n] "
read -r response
if [ "$response" = "n" ] || [ "$response" = "N" ]; then
exit 1
fi
os_type="unknown"
;;
esac
}
check_dependencies() {
set -- "zsh" "git" "curl"
fmt_info "Checking dependencies..."
for dependency in "$@"; do
if ! command_exists "$dependency"; then
if [ "$os_type" = "unknown" ]; then
fmt_error "$dependency is needed for zunder-zsh to work properly."
echo "Please install it manually."
exit 1
fi
install_package "$dependency" || {
fmt_error "$dependency is needed for zunder-zsh to work properly."
echo "Please install it manually or run again this script."
exit 1
}
fi
shift 1
done
[ "$#" -eq 0 ] && fmt_success "All dependencies satisfied."
}
load_files() {
fmt_info "Zunder-zsh will replace your .zshrc and .zshenv."
fmt_warning "Make a backup copy if necessary."
fmt_prompt "Continue? [y/N]: "
read -r prompt
if [ "$prompt" = "Y" ] || [ "$prompt" = "y" ]; then
cp -v "$SCRIPT_DIR/config/.zshrc" "$HOME/.zshrc"
cp -v "$SCRIPT_DIR/config/.zshenv" "$HOME/.zshenv"
if [ ! -d "$ZUNDER_ZSH_DIR" ]; then
mkdir -p "$ZUNDER_ZSH_DIR"
cp -vr "$SCRIPT_DIR/config/before.zsh" "$ZUNDER_ZSH_DIR"
cp -vr "$SCRIPT_DIR/config/after.zsh" "$ZUNDER_ZSH_DIR"
fi
cp -vr "$SCRIPT_DIR/config/functions" "$ZUNDER_ZSH_DIR"
cp -vr "$SCRIPT_DIR/config/spaceship.zsh" "$ZUNDER_ZSH_DIR"
else
echo
fmt_warning "Canceled."
echo "This won't apply the configuration at all."
exit 1
fi
}
set_default() {
ZSH_PATH="$(which zsh)"
if [ "$os_type" != "android" ]; then
sudo usermod -s "$ZSH_PATH" "$USER"
else
chsh -s zsh
fi
}
main() {
check_os_type
echo
[ "$os_type" != "darwin" ] && check_dependencies
echo
load_files
if ! [ -d "$HOME/.local/share/zap" ]; then
echo
fmt_info "Installing plugins..."
zsh -i -c exit
fi
if [ "$os_type" != "darwin" ] && [ "$os_type" != "android" ] && [ "$os_type" != "unknown" ] && [ -z "$is_wsl" ]; then
fc-list | grep -q "Symbols Nerd Font" || (echo && install_icons)
fi
if [ "$(basename "$SHELL")" != "zsh" ]; then
echo
fmt_prompt "Zsh isn't your current default shell, do you want to set it? [Y/n]: "
read -r prompt
if [ "$prompt" != "n" ] && [ "$prompt" != "N" ]; then
if set_default >/dev/null 2>&1; then
fmt_success "Zsh was applied as default shell."
fmt_warning "You may have to restart your computer to apply the changes."
else
fmt_error "Zsh couldn't be applied as the default shell."
fi
else
fmt_warning "Zsh won't be setted as the default shell."
fi
fi
echo
fmt_success "Installation complete."
}
main "$@"