3030
3131
3232
33- export VERSION=" 3.0.0 "
33+ export VERSION=" 3.0.1 "
3434
3535export NAME=" Bashpack"
3636export NAME_LOWERCASE=" $( echo " $NAME " | tr A-Z a-z) "
@@ -179,53 +179,25 @@ if [ -z "$1" ]; then
179179else
180180 case " $1 " in
181181 -v|--version) echo $VERSION && exit ;;
182- # command)
183- # case "$2" in
184- # --help) echo "$USAGE" \
185- # && echo "" \
186- # && echo "Manage $NAME sub commands." \
187- # && echo "" \
188- # && echo "Options:" \
189- # && echo " -l, --list list available commands." \
190- # && echo " -g, --get <name> install a command." \
191- # && echo " -d, --delete remove a command." \
192- # && echo "" \
193- # && echo "$NAME $VERSION" \
194- # && exit ;;
195- # esac
196- # ;;
197- verify)
198- case " $2 " in
199- --help) echo " $USAGE " \
200- && echo " " \
201- && echo " Verify current $NAME installation health." \
202- && echo " " \
203- && echo " Options:" \
204- && echo " -f, --files check that all required files are available." \
205- && echo " -d, --dependencies <file> check that required dependencies are available." \
206- && echo " -r, --repository check that remote repository is reachable." \
207- && echo " " \
208- && echo " $NAME $VERSION " \
209- && exit ;;
210- esac
211- ;;
212182 -h|--help|help) echo " $USAGE " \
213183 && echo " " \
214184 && echo " Options:" \
215- && echo " -i, --self-install install (or reinstall) $NAME on your system as the command '$NAME_ALIAS '." \
216- && echo " -u, --self-update update $NAME to the latest available version (--force option available)." \
217- && echo " --self-delete delete $NAME from your system." \
218- && echo " --logs display logs." \
219- && echo " -h, --help display this information." \
220- && echo " -v, --version display version." \
221- && echo " -l, --list list available subcommands (local and remote). " \
222- && echo " -g, --get <name> install a subcommand." \
223- && echo " -n, --new <name> get a template to create a subcommand." \
224- && echo " -d, --delete <name> uninstall a subcommand." \
185+ && echo " -i, --self-install install (or reinstall) $NAME on your system as the command '$NAME_ALIAS '." \
186+ && echo " -u, --self-update update $NAME to the latest available version (--force option available)." \
187+ && echo " --self-delete delete $NAME from your system." \
188+ && echo " -l, --list <local> list available subcommands (local and remote). " \
189+ && echo " -g, --get <name> install a subcommand." \
190+ && echo " -n, --new <name> get a template to create a subcommand." \
191+ && echo " -d, --delete <name> uninstall a subcommand." \
192+ && echo " --verify-files check that all required files are available." \
193+ && echo " --verify-dependencies <file> check that required dependencies are available." \
194+ && echo " --verify-repository check that remote repository is reachable." \
195+ && echo " --logs display logs." \
196+ && echo " -h, --help display this information." \
197+ && echo " -v, --version display version." \
225198 && echo " " \
226199 && echo " Commands (<command> --help to display usages):" \
227- && echo " verify" \
228- && echo " $( ls $dir_commands 2> /dev/null | sed " s/^/ /g" ) " \
200+ && echo " $( ls $dir_commands 2> /dev/null | sed ' s|\..*||' | sed ' s|^| |' ) " \
229201 && echo " \n$NAME $VERSION " \
230202 && exit ;;
231203 esac
815787# Usage: create_completion <file_command>
816788create_completion () {
817789
818- local file_command=" $1 "
819- local command=" $( echo $( basename $file_command ) ) "
790+ local command=" $1 "
791+ # local file_command="$(echo $(basename $command))"
792+ # local file_command="$(echo $(basename $command.sh))"
793+ local file_command=" $command .sh"
820794
795+ local dir_commands=" $dir_src_cli /commands"
821796
797+
798+ # echo file_command $file_command
799+ # echo command $command
800+
822801 # List all options of any file that is a CLI
823802 # Usage: get_options <file path>
824803 get_options () {
825- cat $1 | sed ' s/.*[ \t|]\(.*\)).*/\1 /' | grep ' ^\-\- ' | sort -ud | sed -Ez ' s/([^\n])\n/\1 /g '
804+ cat $1 | grep ' \--.*) ' | sed ' s/\t*// ' | sed ' s/).*// ' | sed ' s/.*|/ /' | grep ' ^- ' | sort -ud
826805 }
827806
828807
808+
829809 if [ " $( exists_command " pkg-config" ) " = " exists" ]; then
830810
831811 # Install completion only if the directory has been found.
832812 if [ -d " $dir_completion " ]; then
833813
834- if [ " $file_command " = " $CURRENT_CLI " ]; then
814+ # if [ "$file_command" = "$CURRENT_CLI" ]; then
815+ # if [ "$file_command" = "$NAME_LOWERCASE.sh" ]; then
816+ if [ " $( echo $file_command | grep $NAME_LOWERCASE ) " ]; then
835817
836818 if [ -f " $file_completion " ]; then
837819 rm -f $file_completion
@@ -870,16 +852,18 @@ create_completion() {
870852 # Duplicate the line and make it unique with the "new" word to find and replace it with automatics values
871853 sed -i ' s|\(_commandtofill.*\)|\1\n\1new|' $file_completion
872854 sed -i " s|_commandtofill\(.*new\).*|\t\t\t$command \1|" $file_completion
873- sed -i " s|_optionstofill\(.*\)new|$( get_options $dir_commands /$file_command ) \1|" $file_completion
855+ sed -i " s|_optionstofill\(.*\)new|$( echo $( get_options $dir_commands /$file_command ) ) \1|" $file_completion
856+ # sed -i "s|_optionstofill\(.*\)new|$(echo $(get_options $dir_src_cli/commands/$file_command))\1|" $file_completion
874857
875858 # Add the subcommand itself to the completion
876859 sed -i " s|\(1) COMPREPLY.*\)\" |\1 $command \" |" $file_completion
877860 fi
878861
862+
879863 if [ -f " $file_completion " ] && [ -f " $file_completion_alias_1 " ] && [ -f " $file_completion_alias_2 " ]; then
880- log_info " completion ready."
864+ log_info " completion of ' $command ' ready."
881865 else
882- log_error " completion not ready."
866+ log_error " completion of ' $command ' not ready."
883867 fi
884868
885869 else
@@ -2118,19 +2102,20 @@ install_cli() {
21182102
21192103 # Depending on what version an update is performed, it can happen that cp can't overwrite a previous symlink
21202104 # Remove them to allow installation of the CLI
2121- if [ -f " $file_main_alias_1 " ] || [ -f " $file_main_alias_2 " ]; then
2122- rm -f $file_main_alias_1
2123- if [ ! -f " $file_main_alias_1 " ]; then
2124- log_info " file '$file_main_alias_1 ' removed."
2125- fi
2105+ if [ " $( echo $CURRENT_CLI | grep $NAME_LOWERCASE .sh) " ]; then
2106+ if [ -f " $file_main_alias_1 " ] || [ -f " $file_main_alias_2 " ]; then
2107+ rm -f $file_main_alias_1
2108+ if [ ! -f " $file_main_alias_1 " ]; then
2109+ log_info " file '$file_main_alias_1 ' removed."
2110+ fi
21262111
2127- rm -f $file_main_alias_2
2128- if [ ! -f " $file_main_alias_2 " ]; then
2129- log_info " file '$file_main_alias_2 ' removed."
2112+ rm -f $file_main_alias_2
2113+ if [ ! -f " $file_main_alias_2 " ]; then
2114+ log_info " file '$file_main_alias_2 ' removed."
2115+ fi
21302116 fi
21312117 fi
21322118
2133-
21342119 # Sources files installation
21352120 if [ ! -d " $dir_src_cli " ]; then
21362121 log_info " $dir_src_cli not found, creating it."
@@ -2160,7 +2145,13 @@ install_cli() {
21602145
21612146 # Or do the basic offline installation
21622147 else
2163- cp -f $CURRENT_CLI $file_main
2148+ # Avoid non copy file in case of installing from current installed CLI (because an error will be raised saying source and destination are same files)
2149+ if [ " $( cat $CURRENT_CLI ) " != " $( cat $file_main ) " ]; then
2150+ cp -f $CURRENT_CLI $file_main
2151+
2152+ # Autocompletion installation
2153+ create_completion $CURRENT_CLI
2154+ fi
21642155 fi
21652156
21662157 if [ -f " $file_main " ]; then
@@ -2184,24 +2175,18 @@ install_cli() {
21842175 echo " $( cat $CURRENT_CLI | grep -A 21 " MIT License" | head -n 21) " > " $dir_src_cli /LICENSE.md"
21852176
21862177
2187- # Autocompletion installation
2188- create_completion $CURRENT_CLI
2189-
2190-
21912178 # Delete all automations because some of them might have changed
21922179 # if [ "$(ls $dir_systemd/$NAME_LOWERCASE*)" ]; then
21932180 if [ " $( ls $dir_systemd /$NAME_LOWERCASE * ) " ]; then
21942181 rm -f $dir_systemd /$NAME_LOWERCASE *
21952182 fi
21962183
21972184 # Reinstall all automations and completion of the subcommands
2185+ local dir_commands=" $dir_src_cli /commands" # Force using the $dir_command of the installed CLI to avoid the local installed subcommands
21982186 if [ -d " $dir_commands " ]; then
21992187 if [ " $( ls $dir_commands ) " ]; then
22002188 for command in $dir_commands /* ; do
22012189
2202- # echo $command
2203- # echo $dir_commands/$command
2204-
22052190 local command_name=" $( echo $command | sed ' s|^.*/\(.*\)\..*|\1|' ) "
22062191
22072192 # Ensure the command needs to be initialized
@@ -2280,21 +2265,11 @@ case "$1" in
22802265 --logs) get_logs " $file_log_main " ;;
22812266 -l|--list) loading_process " subcommand_list $2 " ;;
22822267 -g|--get) loading_process " subcommand_get $2 " ;;
2283- # -g|--get) loading_process "subcommand_update $2" ;;
22842268 -d|--delete) subcommand_delete $2 $3 ;;
22852269 -n|--new) subcommand_new $2 $3 ;;
2286- verify)
2287- if [ -z " $2 " ]; then
2288- loading_process " verify_dependencies $3 " ; loading_process " verify_files" ; loading_process " verify_repository_reachability $( match_url_repository $( get_config_value $file_config cli_url) github_raw) "
2289- else
2290- case " $2 " in
2291- -f|--files) loading_process " verify_files $3 " ;;
2292- -d|--dependencies) loading_process " verify_dependencies $3 " ;;
2293- # -r|--repository) loading_process "verify_repository_reachability "$URL_RAW/main/$NAME_LOWERCASE.sh""; loading_process "verify_repository_reachability "$URL_API/tarball/$VERSION"" ;;
2294- -r|--repository) loading_process " verify_repository_reachability $( match_url_repository $( get_config_value $file_config cli_url) github_raw) " ;;
2295- * ) log_error " unknown option [$1 ] '$2 '." && echo " $USAGE " && exit ;;
2296- esac
2297- fi ;;
2270+ --verify-files) loading_process " verify_files $3 " ;;
2271+ --verify-dependencies) loading_process " verify_dependencies $3 " ;;
2272+ --verify-repository) loading_process " verify_repository_reachability $( match_url_repository $( get_config_value $file_config cli_url) github_raw) " ;;
22982273 # 'self' is a word used in many operations for the CLI, it's preferable to not allow it in subcommand name
22992274 self) log_error " reserved operation." && exit ;;
23002275 # Since "export -f" is not available in Shell, the helper command below permits to use commands from this file in sub scripts
0 commit comments