1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

Adding a function that creates a prefix and logic surrounding it to only create it if it does not already exist

This commit is contained in:
Micheal Quinn 2019-11-26 13:41:38 -06:00
parent 24cb8f0103
commit f6ad8f57cf

View file

@ -339,6 +339,23 @@ extract_file() {
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: create_prefix
# DESCRIPTION: Creates the install prefix (and any parent directories)
# PARAMETERS: $1 = prefix
# RETURNS: Return code of the tool used to make the directory
# 0 = Created the directory
# >0 = Failed to create directory
#-------------------------------------------------------------------------------
create_prefix() {
local prefix
local rcode
prefix="${1}"
mkdir -p "${prefix}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: install_file_freebsd
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
@ -377,7 +394,6 @@ install_file_freebsd() {
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: install_file_linux
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
@ -485,6 +501,7 @@ main() {
local checksum_check_rcode
local extract_file_rcode
local install_file_rcode
local create_prefix_rcode
croc_bin_name="croc"
croc_version="6.4.6"
@ -620,6 +637,20 @@ main() {
exit 1
fi
if [[ ! -d "${prefix}" ]]; then
create_prefix "${prefix}"
create_prefix_rcode="${?}"
if [[ "${create_prefix_rcode}" -gt 0 ]]; then
print_message "== Failed to create the install prefix: ${prefix}" "error"
exit 1
else
print_message "== Created install prefix at ${prefix}" "info"
fi
else
print_message "== Install prefix already exists. No need to create it." "info"
fi
case "${croc_os}" in
"Linux" ) install_file_linux "${tmpdir}/${croc_bin_name}" "${prefix}/";
install_file_rcode="${?}";;