Explicitly return 0 in main.
The cleanup function can be called within the functions being removed.
This is handy in that the cleanup no longer has to be called after the main function.
The error code can then be properly returned without being lost due to the cleanup function.
Once this is done, return can be used instead of exit (which is generally safer).
if [[ $do_help == "yes" ]] ; then
generate_help
generate_cleanup
- exit 0
+ return 0
fi
generate_load_settings
elif [[ ! -d $path_bash ]] ; then
echo -e "${c_error}ERROR: the bash path of $c_notice$path_bash$c_error is not a valid directory.$c_reset"
generate_cleanup
- exit 0
+ return 0
fi
if [[ $work_directory != "" && ! -d $work_directory ]] ; then
echo -e "${c_error}ERROR: the work directory $c_notice$work_directory$c_error is not a valid directory.$c_reset"
- exit 1
+ generate_cleanup
+ return 1
fi
if [[ $defines_override != "" && $(echo "$defines_override" | grep -s -o "[^_[:alnum:][:space:]]") != "" ]] ; then
echo -e "${c_error}ERROR: the defines override $c_notice$defines_override$c_error includes invalid characters, only alphanumeric, whitespace, and underscore are allowed.$c_reset"
- exit 1
+ generate_cleanup
+ return 1
fi
if [[ ! -d $path_c && ( ${variables[$(generate_id build_sources_library)]} != "" || ${variables[$(generate_id build_sources_program)]} != "" || ${variables[$(generate_id build_sources_headers)]} != "" ) ]] ; then
echo -e "${c_error}ERROR: the c path of '$c_notice$path_c$c_error' is invalid.$c_reset"
generate_cleanup
- exit 1
+ return 1
fi
if [[ $operation_failure == "fail-multiple" ]] ; then
echo -e "${c_error}ERROR: only one operation may be specified at a time.$c_reset"
- exit 1
+ generate_cleanup
+ return 1
elif [[ $operation == "build" ]] ; then
if [[ -f ${path_build}.built$project_built ]] ; then
echo -e "${c_warning}WARNING: this project has already been built.$c_reset"
generate_operation_clean
elif [[ $operation == "" ]] ; then
echo -e "${c_error}ERROR: no operation was given.$c_reset"
- exit 1
+ generate_cleanup
+ return 1
else
echo -e "${c_error}ERROR: the operation $c_notice$operation$c_error was not recognized.$c_reset"
- exit 1
+ generate_cleanup
+ return 1
fi
+
+ generate_cleanup
+ return 0
}
generate_handle_colors(){
}
generate_main $*
-generate_cleanup
if [[ $do_help == "yes" ]] ; then
install_help
install_cleanup
- exit 0
+ return 0
fi
if [[ $operation_failure == "fail-unsupported" ]] ; then
echo -e "${c_error}ERROR: the operation $c_notice$operation$c_error was not recognized.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ $prefix == "" && ! -d $path_build ]] ; then
echo -e "${c_error}ERROR: the build path $c_notice$path_build$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ $destination_prefix != "" && ! -d $destination_prefix ]] ; then
echo -e "${c_error}ERROR: the destination prefix $c_notice$destination_prefix$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ $destination_prefix != "" ]] ; then
if [[ $work_directory != "" && ! -d $work_directory ]] ; then
echo -e "${c_error}ERROR: the work directory $c_notice$work_directory$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_programs ]] ; then
echo -e "${c_error}ERROR: the destination bindir $c_notice$destination_programs$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_programs_static ]] ; then
echo -e "${c_error}ERROR: the destination (static) bindir $c_notice$destination_programs_static$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_programs_shared ]] ; then
echo -e "${c_error}ERROR: the destination (shared) bindir $c_notice$destination_programs_shared$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_includes ]] ; then
echo -e "${c_error}ERROR: the destination incluedir $c_notice$destination_includes$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_libraries_static ]] ; then
echo -e "${c_error}ERROR: the destination (static) libdir $c_notice$destination_libraries_static$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
if [[ ! -d $destination_libraries_shared ]] ; then
echo -e "${c_error}ERROR: the destination (shared) libdir $c_notice$destination_libraries_shared$c_error is not a valid directory.$c_reset"
- exit 1
+ install_cleanup
+ return 1
fi
install_load_settings
install_perform_install
+
+ install_cleanup
+ return 0
}
install_handle_colors(){
}
install_main $*
-install_cleanup
if [[ $do_help == "yes" ]] ; then
package_help
package_cleanup
- exit 0
+ return 0
fi
if [[ $operation_failure == "fail-multiple" ]] ; then
echo -e "${c_error}ERROR: only one operation may be specified at a time.$c_reset"
- exit 1
+ package_cleanup
+ return 1
elif [[ $operation == "build" ]] ; then
if [[ ! -d $path_build ]] ; then
echo -e "${c_error}ERROR: build directory '$path_build' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ ! -d $path_destination ]] ; then
mkdir -vp $path_destination
if [[ $? -ne 0 ]] ; then
echo -e "${c_error}ERROR: package directory '$path_destination' is invalid or could not be created.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
fi
if [[ ! -d $path_sources ]] ; then
echo -e "${c_error}ERROR: sources directory '$path_sources' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ ! -d ${path_sources}level_0/ ]] ; then
echo -e "${c_error}ERROR: build sources directory '${path_sources}level_0/' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ ! -d ${path_sources}level_1/ ]] ; then
echo -e "${c_error}ERROR: build sources directory '${path_sources}level_1/' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ ! -d ${path_sources}level_2/ ]] ; then
echo -e "${c_error}ERROR: build sources directory '${path_sources}level_2/' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ ! -d ${path_sources}level_3/ ]] ; then
echo -e "${c_error}ERROR: build sources directory '${path_sources}level_3/' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
if [[ $mode_individual == "" && $mode_level == "" && $mode_monolithic == "" && $mode_program == "" ]] ; then
elif [[ $operation == "dependencies" ]] ; then
if [[ ! -d $path_sources ]] ; then
echo -e "${c_error}ERROR: sources directory '$path_sources' is invalid or missing.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
package_operation_dependencies
elif [[ $operation == "clean" ]] ; then
if [[ ! -d $path_destination ]] ; then
echo -e "${c_warning}WARNING: package directory '$path_destination' does not exist, there is nothing to clean.$c_reset"
- exit 0
+ package_cleanup
+ return 0
fi
package_operation_clean
elif [[ $operation == "" ]] ; then
echo -e "${c_error}ERROR: no operation was given.$c_reset"
- exit 1
+ package_cleanup
+ return 1
else
echo -e "${c_error}ERROR: the operation $c_notice$operation$c_error was not recognized.$c_reset"
- exit 1
+ package_cleanup
+ return 1
fi
+
+ package_cleanup
+ return 0
}
package_handle_colors(){
if [[ ! -d ${path_build}monolithic ]] ; then
echo -e "${c_error}ERROR: build settings directory $c_notice${path_build}monolithic$c_error is invalid or missing.$c_reset"
package_cleanup
- exit 1
+ return 1
fi
package_create_base_files
if [[ $? -ne 0 ]] ; then
echo -e "${c_error}ERROR: failed to create directory $c_notice${package}data$c_error.$c_reset"
package_cleanup
- exit 1
+ return 1
fi
fi
if [[ $? -ne 0 ]] ; then
echo -e "${c_error}ERROR: failed to move the directory $c_notice$path_build$level$c_error as $c_notice$path_build${level}build$c_error.$c_reset"
package_cleanup
- exit 1
+ return 1
fi
if [[ ! -d ${package}sources/ ]] ; then
if [[ $? -ne 0 ]] ; then
echo -e "${c_error}ERROR: failed to create directory $c_notice${package}sources$c_error.$c_reset"
package_cleanup
- exit 1
+ return 1
fi
fi
}
package_main $*
-package_cleanup