-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·179 lines (149 loc) · 5.63 KB
/
install
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
#!/usr/bin/env bash
# This script has been tested on the following systems:
# - GNU bash v5.1.16 on Arch Linux
# - GNU bash v5.1.16 on Linux Mint 21
# - GNU bash v5.2.15(1)-release on Kali Linux Rolling
# - GNU bash v5.2.2 on Termux Terminal Emulator 0.118.0
# ? Set variables.
name="Neovim Config Installer"
# Installer version; different from config version and Neovim version.
version=(0 13 0)
title=$(printf "%s v%s.%s.%s" "${name}" "${version[@]}")
target_branch="main" # The branch to which the configs will be pulled from.
installation_files="${PWD}/src"
nvim_config_path="${HOME}/.config/nvim"
filelist="files.txt"
min_nvim_version=(0 9 2) # Minimum Neovim version required.
echo
echo "$title"
echo
# ? Check requirements.
echo "Checking requirements..."
if ! [[ -x "$(command -v git)" ]]; then # Check if Git is installed.
echo "Git : not found"
echo
echo "\`git\` is not installed. Please install git and try again."
echo
echo "- \`sudo apt update && sudo apt install git\`"
echo "- https://git-scm.com/downloads"
exit 1
else
echo "Git : $(command -v git)"
fi
if ! [[ -x "$(command -v gcc)" ]]; then
if ! [[ -x "$(command -v clang)" ]]; then
echo "C compiler: not found"
echo
echo "\`gcc\` or \`clang\` is not installed."
echo "Please install either of the two and try again."
echo
echo "- \`sudo apt update && sudo apt install gcc\`"
exit 2
else
echo "C compiler: $(command -v clang)"
fi
else
echo "C compiler: $(command -v gcc)"
fi
if ! [[ -x "$(command -v make)" ]]; then
echo "make : not found"
echo
echo "\`make\` is not installed."
echo "Please install it and try again."
echo
echo "- \`sudo apt update && sudo apt install make\`"
exit 11
else
echo "make : $(command -v make)"
fi
if ! [[ -x "$(command -v npm)" ]]; then
echo "npm : not found"
echo
echo "\`npm\` is not installed. Please install it and try again."
echo
echo "- \`sudo apt update && sudo apt install nodejs npm\`"
echo "- https://nodejs.org/en/download/"
exit 4
else
echo "npm : $(command -v npm)"
fi
echo
if ! [[ -x "$(command -v nvim)" ]]; then # Check if Neovim is installed.
echo "\`nvim\` is not installed. Please install nvim and try again."
echo
echo "- \`sudo apt update && sudo apt install neovim\`"
echo "- https://github.com/neovim/neovim/releases/latest"
exit 5
else
echo "Neovim is installed. Checking its version..."
# Get the version of Neovim using `nvim -v` in format `vX.X.X`.
nvim_version=$(nvim -v | grep -oP 'v\d+\.\d+\.\d+')
min_nvim_version_str=$(printf "v%s.%s.%s" "${min_nvim_version[@]}")
echo "Detected Neovim version: ${nvim_version}"
# Returns min_nvim_version_str if the user's Neovim version is supported.
nvim_version_supported=$(echo -e "${min_nvim_version_str}\n${nvim_version}" | sort -V | head -n1)
if [[ ${nvim_version_supported} != "${min_nvim_version_str}" ]]; then
echo "Neovim ${nvim_version} is not supported."
echo "Please upgrade to at least ${min_nvim_version_str} or higher and try again."
exit 6
else
echo "User's Neovim version is supported. (Requires: >= ${min_nvim_version_str})"
fi
fi
# ? Ask for user confirmation.
echo
echo "This will install ${name} on \`${nvim_config_path}\`."
echo "This will overwrite existing files in the said directory."
echo
while true; do
printf "Are you sure? (Y/n) > "
read -r installation_confirmation
if [[ "${installation_confirmation}" == "" || "${installation_confirmation}" =~ ^[y|Y].* ]]; then
printf "Installing %s customization files...\n" "${title}"
break
elif [[ "${installation_confirmation}" =~ ^[n|N].* ]]; then
echo "Cancelling installation."
exit 7
else
echo "Unknown answer."
echo
fi
done
echo
# Remove the configuration files.
if [[ -e "${nvim_config_path}" ]]; then
printf "Removing existing files in \`%s\`...\r" "${nvim_config_path}"
rm -r -- "${nvim_config_path}" # Delete the existing Neovim configuration directory.
printf "Removing existing files in \`%s\`... Done!\n" "${nvim_config_path}"
else
echo "No existing files found in \`${nvim_config_path}\`."
fi
# Check if the installation files exist.
if [[ -d "$installation_files" ]]; then
printf "Copying customization files to \`%s\`...\r" "${nvim_config_path}"
# Copy the customization files to the Neovim configuration directory.
if cp -r "$installation_files" "$nvim_config_path"; then
printf "Copying customization files to \`%s\`... Done!\n" "${nvim_config_path}"
echo "Please run \`nvim\` to finish the installation."
exit 0
else
printf "Copying customization files to \`%s\`... Failed!\n" "${nvim_config_path}"
exit 10
fi
else
filelist_url="https://raw.githubusercontent.com/SetupGuides/Neovim/${target_branch}/${filelist}"
echo "Downloading file list..."
files_to_download=$(curl -sSfL "${filelist_url}")
printf "Downloading customization files to \`%s\`...\r" "${nvim_config_path}"
for file in ${files_to_download}; do
pull_url="${file//<branch>/${target_branch}}"
output_filepath=${file##*/src/}
if ! curl -sSfL "${pull_url}" --create-dirs --output "${nvim_config_path}/${output_filepath}"; then
printf "Downloading customization files to \`%s\`... Failed!\n" "${nvim_config_path}"
exit 3
fi
done
printf "Downloading customization files to \`%s\`... Done!\n" "${nvim_config_path}"
echo "Please run \`nvim\` to finish the installation."
exit 0
fi