2828URL=" https://api.github.com/repos/bashpack-project/bashpack/tarball" # for Github tarball
2929# URL="https://github.com/bashpack-project/bashpack/archive/refs/heads" # for Github main branch
3030
31- VERSION=" 0.2.20 "
31+ VERSION=" 0.2.21 "
3232
3333NAME=" Bashpack"
3434NAME_LOWERCASE=$( echo " $NAME " | tr A-Z a-z)
115115
116116
117117# Loading animation so we know the process has not crashed
118- # Usage : loading "<command that takes time>"
118+ # Usage: loading "<command that takes time>"
119119loading () {
120120 ${1} & local pid=$!
121121 local loader=" \|/-"
@@ -137,7 +137,7 @@ export -f loading
137137
138138
139139# Function to search for commands on the system.
140- # Usage : exists_command <command>
140+ # Usage: exists_command <command>
141141exists_command () {
142142 local command=${1}
143143
@@ -153,7 +153,7 @@ export -f exists_command
153153
154154
155155# Error function.
156- # Usage : error_file_not_downloaded <file_url>
156+ # Usage: error_file_not_downloaded <file_url>
157157error_file_not_downloaded () {
158158 echo " "
159159 echo " Error: ${1} not found."
@@ -201,8 +201,16 @@ COMMAND_SYSTEMD_STATUS="systemctl status $file_systemd_update.timer"
201201
202202
203203# Delete the installed command from the system
204+ # Usages:
205+ # - delete_cli
206+ # - delete_cli "exclude_main"
204207delete_cli () {
205208
209+ # $exclude_main permit to not delete main command "bp" and "bashpack".
210+ # (i) This is useful in case when the CLI tries to update itself, but the latest release is not accessible.
211+ # /!\ Unless it can happen that the CLI destroys itself, and then the user must reinstall it.
212+ # (i) Any new update will overwrite the "bp" and "bashpack" command, so it doesn't matter to not delete it during update.
213+ # (i) It's preferable to delete all others files since updates can remove files from olders releases
206214 local exclude_main=${1}
207215
208216 if [[ $exclude_main = " exclude_main" ]]; then
@@ -294,15 +302,21 @@ delete_systemd() {
294302
295303
296304# Helper function to assemble all functions that delete something
305+ # Usages:
306+ # - delete_all
307+ # - delete_all "exclude_main" (Please check the explaination of $exclude_main at the delete_cli() function declaration)
297308delete_all () {
298- delete_systemd && delete_cli
309+
310+ local exclude_main=${1}
311+
312+ delete_systemd && delete_cli ${1}
299313}
300314
301315
302316
303317
304318# Helper function to extract a .tar.gz archive
305- # Usage : archive_extract <archive> <directory>
319+ # Usage: archive_extract <archive> <destination directory>
306320archive_extract () {
307321 # "tar --strip-components 1" permit to extract sources in /tmp/bashpack and don't create a new directory /tmp/bashpack/bashpack
308322 tar -xf ${1} -C ${2} --strip-components 1
@@ -312,7 +326,7 @@ archive_extract() {
312326
313327
314328# Download releases archives from the repository
315- # Usages :
329+ # Usages:
316330# - download_cli <latest>
317331# - download_cli <n.n.n>
318332download_cli () {
@@ -446,8 +460,10 @@ create_cli() {
446460
447461
448462 # Clear temporary files & directories
449- rm -f $archive_tmp
450- rm -rf $archive_dir_tmp
463+ # rm -f $archive_tmp
464+ # rm -rf $archive_dir_tmp
465+ rm -rf " $dir_tmp /$NAME_LOWERCASE *" # Cleaning also temp files created during update process since create_cli is not called directly during update.
466+
451467
452468 else
453469 error_file_not_downloaded $archive_url
@@ -480,10 +496,9 @@ update_cli() {
480496 # download_cli "$URL" 2>&1 > /dev/null # Github latest tarball
481497 download_cli " $URL " # Github latest tarball
482498
483- # # Delete current installed version to clean all old files
484- # /!\ Deactivated for now because if we delete the last release from Github, the CLI is just beeing removed from the system...
485- # delete_all
486- delete_systemd && delete_cli exclude_main
499+ # Delete current installed version to clean all old files
500+ delete_all exclude_main
501+ # delete_systemd && delete_cli exclude_main
487502
488503 echo " "
489504
@@ -516,7 +531,7 @@ install_cli() {
516531
517532# The options (except --help) must be called with root
518533case " $1 " in
519- -i|--self-install) install_cli ;;
534+ -i|--self-install) install_cli ;; # Critical option, see the comments at function declaration for more info
520535 -u|--self-update) update_cli ;; # Critical option, see the comments at function declaration for more info
521536 --self-delete) delete_all ;;
522537 man) $COMMAND_MAN ;;
0 commit comments