Skip to content

Commit 074d43e

Browse files
ggtrdggtrd
authored andcommitted
Improve tarball update error
1 parent fc5858f commit 074d43e

File tree

2 files changed

+16
-97
lines changed

2 files changed

+16
-97
lines changed

bashpack.sh

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ export -f exists_command
153153
# Error function.
154154
# Usage: error_file_not_downloaded <file_url>
155155
error_file_not_downloaded() {
156-
echo ""
157-
echo "Error: ${1} not found."
158-
echo "Are curl or wget able to reach it from your system?"
159-
echo ""
156+
echo "Error: ${1} not found. Are curl or wget able to reach it from your system?"
157+
}
158+
159+
160+
161+
162+
# Error function.
163+
# Usage: error_tarball_non_working <file_name>
164+
error_tarball_non_working() {
165+
echo "Error: file '${1}' is a non-working .tar.gz tarball and cannot be used. Deleting it."
160166
}
161167

162168

@@ -385,7 +391,7 @@ archive_extract() {
385391
# "tar --strip-components 1" permit to extract sources in /tmp/bashpack and don't create a new directory /tmp/bashpack/bashpack
386392
tar -xf ${1} -C ${2} --strip-components 1
387393
else
388-
echo "Error: file '${1}' is not a real .tar.gz tarball and cannot be used. Deleting it."
394+
error_tarball_non_working ${1}
389395
rm -f ${1}
390396
fi
391397
}
@@ -587,8 +593,8 @@ create_cli() {
587593
# - Github latest tarball release is accessible from https://api.github.com/repos/<user>/<repository>/tarball
588594
update_cli() {
589595
# Download a first time the latest version from the "main" branch to be able to launch the installation script from it to get latest modifications.
590-
# The install function will download the well-named archive with the version name
591-
# (so yes, it means that the CLI is downloaded twice)
596+
# The install function will download the well-named archive with the version name.
597+
# (so yes, it means that the CLI is downloaded multiple times)
592598

593599
local error_already_installed="Latest $NAME version is already installed ($VERSION $(detect_publication))."
594600

@@ -598,40 +604,21 @@ update_cli() {
598604
if [[ $(curl -s "$URL/releases/latest" | grep tag_name | cut -d \" -f 4) = "$VERSION" ]] && [[ $(detect_publication) = $(get_config_value "$dir_config/$file_config" "publication") ]]; then
599605
echo $error_already_installed
600606
else
601-
602-
# # To avoid broken installations, before deleting anything, testing if downloaded archive is a working tarball.
603-
# # (archive is deleted in create_cli, which is called after in the process)
604-
# if file $archive_tmp | grep -q 'gzip compressed data'; then
605-
# # Delete current installed version to clean all old files
606-
# delete_all exclude_main
607-
608-
# # Execute the install_cli function of the script downloaded in /tmp
609-
# exec "$archive_dir_tmp/$NAME_LOWERCASE.sh" -i
610-
# else
611-
# echo "Error: file '${1}' is not a real .tar.gz tarball and cannot be used. Deleting it, then exiting."
612-
# rm -f ${1}
613-
# exit
614-
# fi
615-
616607
# To avoid broken installations, before deleting anything, testing if downloaded archive is a working tarball.
617608
# (archive is deleted in create_cli, which is called after in the process)
618609
if ! $NAME_LOWERCASE verify -d | grep -q 'Error:'; then
619610

611+
# Download latest available version
620612
download_cli "$URL/tarball" $archive_tmp $archive_dir_tmp
621613

622614
# Delete current installed version to clean all old files
623615
delete_all exclude_main
624616

625617
# Execute the install_cli function of the script downloaded in /tmp
626618
exec "$archive_dir_tmp/$NAME_LOWERCASE.sh" -i
619+
else
620+
error_tarball_non_working $archive_tmp
627621
fi
628-
629-
# # Delete current installed version to clean all old files
630-
# delete_all exclude_main
631-
632-
# # Execute the install_cli function of the script downloaded in /tmp
633-
# exec "$archive_dir_tmp/$NAME_LOWERCASE.sh" -i
634-
635622
fi
636623
}
637624

commands/tests.sh

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -174,74 +174,6 @@ check_files() {
174174

175175

176176

177-
# check_download() {
178-
179-
# local not_found=0
180-
181-
# echo ">>> Verifying download"
182-
# echo "Attempting to download and extract archive from $URL"
183-
184-
185-
# # Verification : download and extract latest available tarball
186-
# echo ""
187-
# echo "Verification 1 -> Latest tarball"
188-
# download_cli "$URL/tarball" $archive_tmp $archive_dir_tmp
189-
190-
# if [[ -f $archive_tmp ]]; then
191-
# echo "Success! Verification passed. $archive_tmp found."
192-
# else
193-
# not_found=$((not_found+1))
194-
# echo "Error: verification failed. $archive_tmp not found."
195-
# fi
196-
197-
# if [[ -d $archive_dir_tmp ]]; then
198-
# echo "Success! Verification passed. $archive_dir_tmp found."
199-
# else
200-
# not_found=$((not_found+1))
201-
# echo "Error: verification failed. $archive_dir_tmp not found."
202-
# fi
203-
204-
# # Cleaning files to prepare next verifications.
205-
# rm -rf $archive_tmp
206-
# rm -rf $archive_dir_tmp
207-
208-
209-
210-
# # Verification : download and extract given version tarball
211-
# echo ""
212-
# echo "Verification 2 -> $VERSION tarball"
213-
# download_cli "$URL/tarball/$VERSION" $archive_tmp $archive_dir_tmp
214-
215-
# if [[ -f $archive_tmp ]]; then
216-
# echo "Success! Verification passed. $archive_tmp found."
217-
# else
218-
# not_found=$((not_found+1))
219-
# echo "Error: verification failed. $archive_tmp not found."
220-
# fi
221-
222-
# if [[ -d $archive_dir_tmp ]]; then
223-
# echo "Success! Verification passed. $archive_dir_tmp found."
224-
# else
225-
# not_found=$((not_found+1))
226-
# echo "Error: verification failed. $archive_dir_tmp not found."
227-
# fi
228-
229-
# # Cleaning files to prepare next verifications.
230-
# rm -rf $archive_tmp
231-
# rm -rf $archive_dir_tmp
232-
233-
234-
# if [ $not_found -gt 0 ]; then
235-
# echo ""
236-
# echo "Error: $not_found download verification(s) not working as expected."
237-
# else
238-
# echo ""
239-
# echo "Success! Download functions are working as expected."
240-
# fi
241-
# }
242-
243-
244-
245177
# Permit to verify if downloading tarball works as expected.
246178
# Usage:
247179
# - Latest version: check_download

0 commit comments

Comments
 (0)