Skip to content

Commit 479d15d

Browse files
committed
fix: broken installation script
1 parent ef04957 commit 479d15d

File tree

3 files changed

+85
-134
lines changed

3 files changed

+85
-134
lines changed

scripts/neovim_download.sh

Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env bash
22

33
# If anything fails, exit
4-
set -eo pipefail
4+
set -eouE pipefail
55

6-
# Check if either curl or wget is available on the system
7-
if command -v curl &>/dev/null; then
8-
downloader="curl"
9-
elif command -v wget &>/dev/null; then
10-
downloader="wget"
11-
else
12-
echo "Error: This script requires either curl or wget to be installed."
13-
exit 1
14-
fi
6+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
7+
8+
# shellcheck source=SCRIPTDIR/utils/core.sh
9+
source "${SCRIPTS_DIR}/utils/core.sh"
10+
# shellcheck source=SCRIPTDIR/utils/api.sh
11+
source "${SCRIPTS_DIR}/utils/api.sh"
12+
# shellcheck source=SCRIPTDIR/utils/neovim.sh
13+
source "${SCRIPTS_DIR}/utils/neovim.sh"
1514

1615
function display_help() {
1716
cat <<EOM
@@ -26,91 +25,42 @@ Options:
2625
EOM
2726
}
2827

29-
# Download using wget/curl whatever is available
30-
function download() {
31-
local url="$1"
32-
local output_file="$2"
33-
34-
if [ "$downloader" = "curl" ]; then
35-
curl -fsSL -o "$output_file" "$url"
36-
elif [ "$downloader" = "wget" ]; then
37-
wget --quiet --output-document="$output_file" "$url"
38-
fi
39-
}
40-
4128
function download_neovim() {
42-
local os="$1"
43-
local version="$2"
44-
local download_dir="$3"
45-
local arch_type="$4"
46-
local download_url=""
47-
local download_path=""
48-
49-
if [ "$os" == "Linux" ]; then
50-
download_url="https://github.com/neovim/neovim/releases/download/${version}/nvim.appimage"
51-
download_path="$download_dir/nvim-$version-linux.appimage"
52-
53-
set +e # Prevent termination based on compare_version's return
54-
compare_versions "$version" v0.10.3
55-
local result=$?
56-
set -e # Re-enable termination based on return values
57-
58-
if [[ $version == "nightly" ]] || [[ $version == "stable" ]] || [[ $result -eq 1 ]]; then
59-
download_url="https://github.com/neovim/neovim/releases/download/${version}/nvim-linux-${arch_type}.appimage"
60-
download_path="$download_dir/nvim-$version-linux-$arch_type.appimage"
61-
fi
62-
elif [ "$os" == "Darwin" ]; then
63-
download_url="https://github.com/neovim/neovim/releases/download/${version}/nvim-macos.tar.gz"
64-
download_path="$download_dir/nvim-$version-macos.tar.gz"
65-
66-
set +e # Prevent termination based on compare_version's return
67-
compare_versions "$version" v0.9.5
68-
local result=$?
69-
set -e # Re-enable termination based on return values
70-
71-
if [[ $version == "nightly" ]] || [[ $version == "stable" ]] || [[ $result -eq 1 ]]; then
72-
download_url="https://github.com/neovim/neovim/releases/download/${version}/nvim-macos-${arch_type}.tar.gz"
73-
download_path="$download_dir/nvim-$version-macos-$arch_type.tar.gz"
74-
fi
75-
else
76-
echo "Error: Currently download support is present only for Linux and macOS"
77-
exit 1
78-
fi
29+
local os="$1" version="$2" download_dir="$3" arch_type="$4"
7930

80-
local checksum_path="$download_path".sha256sum
81-
local expected_checksum=""
82-
# This ensures that they do not match
83-
local actual_checksum="$expected_checksum-actual"
31+
local download_url, download_path, checksum_path, expected_checksum, actual_checksum
32+
download_url=$(safe_subshell build_github_uri "$version" "$os" "$arch_type")
33+
download_path="$download_dir/$(basename "$download_url")"
34+
35+
checksum_path="$download_path".sha256sum
36+
actual_checksum="$expected_checksum-actual" # This ensures that they do not match
37+
expected_checksum=$(safe_subshell get_sha256 "$version" "$os" "$arch_type")
8438

8539
if [ -e "$download_path" ] && [ -e "$checksum_path" ]; then
86-
expected_checksum=$(cut -d ' ' -f 1 <"$checksum_path")
40+
expected_checksum=$(<"$checksum_path")
8741
actual_checksum=$(sha256sum "$download_path" | cut -d ' ' -f 1)
8842
fi
8943

9044
if [ "$actual_checksum" == "$expected_checksum" ]; then
91-
echo "Existing installation with matching checksum found. Skipping downloading..."
45+
info "Existing installation with matching checksum found. Skipping downloading..."
9246
return 0
9347
fi
9448

95-
echo "Downloading Neovim..."
96-
download "$download_url" "$download_path"
97-
if [[ $version != "nightly" ]]; then
98-
# Nightly versions do not come with checksums
99-
download "$download_url".sha256sum "$checksum_path"
100-
fi
101-
echo "Download completed."
49+
download_file "$download_url" "$download_path"
50+
info "Downloaded Neovim release ${version} for ${os} (${arch_type}) to ${download_path}"
10251
}
10352

10453
# Download Neovim source
10554
function download_neovim_source() {
10655
local version="$1"
10756
local download_dir="$2"
10857
local download_url="https://github.com/neovim/neovim/archive/refs/tags/${version}.tar.gz"
58+
local download_path="${download_dir}/nvim-${version}-source.tar.gz"
10959

110-
echo "Downloading Neovim source..."
111-
download "$download_url" "$download_dir/nvim-${version}-source.tar.gz"
60+
debug "Downloading Neovim source..."
61+
download_file "$download_url" "$download_path"
11262

113-
echo "Source download completed."
63+
info "Downloaded Neovim source version ${version} to ${download_path}"
11464
}
11565

11666
# Parse command-line options
@@ -149,38 +99,34 @@ done
14999

150100
# Check if the required options are provided
151101
if [[ -z $nvim_version || -z $download_dir || -z $download_type || -z $arch_type ]]; then
152-
echo "Missing options. Use -h to see the usage."
102+
error "Missing options. Use -h to see the usage."
153103
exit 1
154104
fi
155105

156106
if [[ $download_dir == *"remote-nvim.nvim/version_cache"* ]]; then
157-
echo "$download_dir is the default path. So, recursively creating the necessary directories"
107+
info "$download_dir is the default path. So, recursively creating the necessary directories"
158108
mkdir -p "$download_dir"
159109
fi
160110

161111
if [[ ! -d $download_dir ]]; then
162-
echo "$download_dir does not exist. Will try creating it now.."
112+
info "$download_dir does not exist. Will try creating it now.."
163113
if ! mkdir "$download_dir"; then
164-
echo "$download_dir creation failed as parent directories do not exist"
114+
error "$download_dir creation failed as parent directories do not exist"
165115
exit 1
166116
else
167-
echo "Created $download_dir successfully"
117+
info "Created $download_dir successfully"
168118
fi
169119
fi
170120

171121
if [[ $nvim_version != "stable" && $nvim_version != "nightly" && ! $nvim_version =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
172-
echo "Invalid Neovim version: $nvim_version"
122+
error "Invalid Neovim version: $nvim_version"
173123
exit 1
174124
fi
175125

176-
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
177-
# shellcheck source=./scripts/neovim_utils.sh
178-
source "$SCRIPT_DIR/neovim_utils.sh"
179-
180126
if [[ $download_type == "source" ]]; then
181127
download_neovim_source "$nvim_version" "$download_dir"
182128
elif [[ $download_type == "system" ]]; then
183-
echo "Cannot download a system-type Neovim release. Choose from either 'source' or 'binary'."
129+
error "Cannot download a system-type Neovim release. Choose from either 'source' or 'binary'."
184130
exit 1
185131
else
186132
download_neovim "$os_name" "$nvim_version" "$download_dir" "$arch_type"

scripts/neovim_install.sh

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#!/usr/bin/env bash
22

33
# If anything fails, exit
4-
set -eo pipefail
4+
set -eouE pipefail
5+
6+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
7+
8+
# shellcheck source=SCRIPTDIR/utils/core.sh
9+
source "${SCRIPTS_DIR}/utils/core.sh"
10+
# shellcheck source=SCRIPTDIR/utils/api.sh
11+
source "${SCRIPTS_DIR}/utils/api.sh"
12+
# shellcheck source=SCRIPTDIR/utils/neovim.sh
13+
source "${SCRIPTS_DIR}/utils/neovim.sh"
14+
15+
download_neovim_script="$SCRIPTS_DIR/neovim_download.sh"
516

617
# Create a temporary directory to handle any remote nvim data location things
718
temp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'neovim_download')
@@ -33,7 +44,7 @@ EOM
3344
# Function to check if Neovim is available in the system's $PATH
3445
function check_neovim_in_path() {
3546
if command -v nvim &>/dev/null; then
36-
echo "Neovim already on PATH. Skipping installation..."
47+
info "Neovim already on PATH. Skipping installation..."
3748
exit 0
3849
fi
3950
}
@@ -45,7 +56,7 @@ function link_to_system_neovim() {
4556
mkdir -p "$nvim_version_dir"/bin
4657
ln -sf "$(which nvim)" "$nvim_binary"
4758
else
48-
echo "Error: Did not find Neovim on the path"
59+
error "Error: Did not find Neovim on the path"
4960
exit 1
5061
fi
5162
}
@@ -55,7 +66,7 @@ function build_from_source() {
5566
local nvim_release_name="nvim-$1-source.tar.gz"
5667

5768
if [ ! -e "$nvim_version_dir/$nvim_release_name" ]; then
58-
echo "Expected release to be present at $nvim_version_dir/$nvim_release_name. Aborting..."
69+
error "Expected release to be present at $nvim_version_dir/$nvim_release_name. Aborting..."
5970
exit 1
6071
fi
6172

@@ -82,31 +93,25 @@ function build_from_source() {
8293

8394
# Install on Linux using AppImage
8495
function setup_neovim_linux_appimage() {
85-
local version="$1"
86-
local nvim_release_name="nvim-$1-linux.appimage"
96+
local version="$1" arch_type="$2"
8797
local nvim_appimage_temp_path="$temp_dir/$nvim_release_name"
8898

89-
set +e # Prevent termination based on compare_version's return
90-
compare_versions "$version" v0.10.3
91-
local result=$?
92-
set -e # Re-enable termination based on return values
93-
94-
if [[ $version == "nightly" ]] || [[ $version == "stable" ]] || [[ $result -eq 1 ]]; then
95-
nvim_release_name="nvim-$1-linux-$2.appimage"
96-
fi
99+
local nvim_release_name
100+
download_url=$(safe_subshell build_github_uri "$version" "Linux" "$arch_type")
101+
nvim_release_name=$(basename "$download_url")
97102

98103
if [ ! -e "$nvim_version_dir/$nvim_release_name" ]; then
99-
echo "Expected release to be present at $nvim_version_dir/$nvim_release_name. Aborting..."
104+
error "Expected release to be present at $nvim_version_dir/$nvim_release_name. Aborting..."
100105
exit 1
101106
fi
102107

103108
cp "$nvim_version_dir/$nvim_release_name" "$nvim_appimage_temp_path"
104109

105-
echo "Extracting Neovim binary..."
110+
info "Extracting Neovim binary..."
106111
chmod u+x "$nvim_appimage_temp_path"
107112
"$nvim_appimage_temp_path" --appimage-extract >/dev/null
108113

109-
echo "Finishing up installing Neovim..."
114+
info "Finishing up installing Neovim..."
110115
mkdir -p "$nvim_version_dir"/bin
111116
mv -f "$temp_dir/squashfs-root"/* "$nvim_version_dir"
112117
ln -sf "$nvim_version_dir"/usr/bin/nvim "$nvim_binary"
@@ -149,61 +154,62 @@ function setup_neovim_macos() {
149154
function install_neovim() {
150155
# Check if the specified download directory exists
151156
if [[ ! -d $remote_nvim_dir ]]; then
152-
echo "Remote neovim directory does not exist. Creating it now..."
157+
info "Remote neovim directory does not exist. Creating it now..."
153158
mkdir -p "$remote_nvim_dir"
154159
fi
160+
155161
nvim_download_dir="$remote_nvim_dir/nvim-downloads"
156162

157163
# Check if the specified release is already downloaded
158164
nvim_version_dir="$nvim_download_dir/$nvim_version"
159165
nvim_binary="$nvim_version_dir/bin/nvim"
160166

161167
if [[ ! $force_installation && -d $nvim_version_dir && $($nvim_binary -v 2>/dev/null | head -c1 | wc -c) -ne 0 ]]; then
162-
echo "Neovim ${nvim_version} is already installed. Skipping installation."
168+
info "Neovim ${nvim_version} is already installed. Skipping installation."
163169
else
164170
mkdir -p "$nvim_version_dir"
165171

166172
if [[ -f $nvim_binary && $($nvim_binary -v 2>/dev/null | head -c1 | wc -c) -eq 0 ]]; then
167-
echo "Neovim installation is corrupted. Would re-install..."
173+
warn "Neovim installation is corrupted. Would re-install..."
168174
fi
169175

170176
local os
171177
os=$(uname)
172178

173179
if [[ $install_method == "binary" ]]; then
174180
if [ "$offline_mode" == true ]; then
175-
echo "Operating in offline mode. Will not download Neovim release"
181+
info "Operating in offline mode. Will not download Neovim release"
176182
else
177183
"$download_neovim_script" -o "$os" -v "$nvim_version" -d "$nvim_version_dir" -t "binary" -a "$arch_type"
178184
fi
179185

180186
# Install Neovim based on the detected OS
181187
if [[ $os == "Linux" ]]; then
182-
setup_neovim_linux_appimage "$nvim_version" "$arch_type"
188+
safe_subshell setup_neovim_linux_appimage "$nvim_version" "$arch_type"
183189
elif [[ $os == "Darwin" ]]; then
184-
setup_neovim_macos "$nvim_version" "$arch_type"
190+
safe_subshell setup_neovim_macos "$nvim_version" "$arch_type"
185191
else
186192
echo "Unsupported operating system: $(uname)"
187193
exit 1
188194
fi
189195
elif [[ $install_method == "source" ]]; then
190196
if [ "$offline_mode" == true ]; then
191-
echo "Operating in offline mode. Will not download Neovim source"
197+
info "Operating in offline mode. Will not download Neovim source"
192198
else
193199
"$download_neovim_script" -o "$os" -v "$nvim_version" -d "$nvim_version_dir" -t "source" -a "$arch_type"
194200
fi
195-
build_from_source "$nvim_version"
201+
safe_subshell build_from_source "$nvim_version"
196202
# Handle tar file downloaded or copied over
197203
elif [[ $install_method == "system" ]]; then
198204
# Handle symlinking to the system binary version
199-
link_to_system_neovim
205+
safe_subshell link_to_system_neovim
200206
else
201-
echo "Unsupported Neovim installation method. Available installation methods are: binary, source or system"
207+
error "Unsupported Neovim installation method. Available installation methods are: binary, source or system"
202208
exit 1
203209
fi
204210
fi
205211

206-
echo "Neovim $nvim_version can be accessed at $nvim_binary"
212+
info "Neovim $nvim_version can be accessed at $nvim_binary"
207213
}
208214

209215
# Parse command-line options
@@ -254,10 +260,5 @@ if [[ $install_method == "system" && $nvim_version != "system" ]]; then
254260
exit 1
255261
fi
256262

257-
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
258-
download_neovim_script="$SCRIPT_DIR/neovim_download.sh"
259-
# shellcheck source=./scripts/neovim_utils.sh
260-
source "${SCRIPT_DIR}/neovim_utils.sh"
261-
262263
cd "$temp_dir" || exit 1
263-
install_neovim
264+
safe_subshell install_neovim

0 commit comments

Comments
 (0)