mirror of
https://github.com/schollz/croc.git
synced 2024-11-24 08:02:33 +03:00
Adding description information. Added print message function for fancy colors in the output.
This commit is contained in:
parent
e7d6d096a8
commit
2c2920eb9c
@ -3,22 +3,64 @@
|
||||
#
|
||||
# FILE: default.txt.sh
|
||||
#
|
||||
# USAGE: ./default.txt.sh
|
||||
# USAGE: curl https://getcroc.schollz.com | bash
|
||||
# OR
|
||||
# wget -qO- https://getcroc.schollz.com | bash
|
||||
#
|
||||
# DESCRIPTION:
|
||||
#
|
||||
# OPTIONS: ---
|
||||
# REQUIREMENTS: ---
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# DESCRIPTION: croc Installer Script.
|
||||
#
|
||||
# This script installs croc into a specified prefix.
|
||||
# Default prefix = /usr/local/bin
|
||||
#
|
||||
# OPTIONS: -p, --prefix "${PREFIX}"
|
||||
# Prefix to install croc into. Defaults to /usr/local/bin
|
||||
# REQUIREMENTS: bash, uname, tar/unzip, curl/wget, sudo (if not run
|
||||
# as root), install, mktemp, sha256sum/shasum/sha256
|
||||
#
|
||||
# BUGS: ...hopefully not. Please report.
|
||||
#
|
||||
# NOTES: Homepage: https://schollz.com/software/croc
|
||||
# Issues: https://github.com/schollz/croc/issues
|
||||
#
|
||||
# AUTHOR: Micheal Quinn, micheal.quinn85@gmail.com
|
||||
# COMPANY:
|
||||
# ORGANIZATION:
|
||||
# CREATED: 08/10/2019 16:41
|
||||
# REVISION: 0.0.0
|
||||
# REVISION: 0.5.0
|
||||
#===============================================================================
|
||||
set -o nounset # Treat unset variables as an error
|
||||
|
||||
|
||||
#--- FUNCTION ----------------------------------------------------------------
|
||||
# NAME: print_message
|
||||
# DESCRIPTION: Prints a message all fancy like
|
||||
# PARAMETERS: $1 = Message to print
|
||||
# $2 = Severity. info, ok, error, warn
|
||||
# RETURNS: Formatted Message to stdout
|
||||
#-------------------------------------------------------------------------------
|
||||
print_message() {
|
||||
local message
|
||||
local severity
|
||||
local red
|
||||
local green
|
||||
local yellow
|
||||
local nc
|
||||
|
||||
message="${1}"
|
||||
severity="${2}"
|
||||
red='\e[0;31m'
|
||||
green='\e[0;32m'
|
||||
yellow='\e[1;33m'
|
||||
nc='\e[0m'
|
||||
|
||||
case "${severity}" in
|
||||
"info" ) echo -e "${nc}${message}${nc}";;
|
||||
"ok" ) echo -e "${green}${message}${nc}";;
|
||||
"error" ) echo -e "${red}${message}${nc}";;
|
||||
"warn" ) echo -e "${yellow}${message}${nc}";;
|
||||
esac
|
||||
|
||||
|
||||
}
|
||||
|
||||
#--- FUNCTION ----------------------------------------------------------------
|
||||
# NAME: make_tempdir
|
||||
# DESCRIPTION: Makes a temp dir using mktemp if available
|
||||
@ -57,7 +99,6 @@ determine_os() {
|
||||
local uname_out
|
||||
|
||||
uname_cmd="$(command -v uname)"
|
||||
|
||||
if [[ "${uname_cmd}" == "" ]]; then
|
||||
return 2
|
||||
else
|
||||
@ -127,7 +168,6 @@ download_file() {
|
||||
wget --quiet "${url}" -O "${dir}/${filename}"
|
||||
rcode="${?}"
|
||||
else
|
||||
echo "== Could not find curl or wget"
|
||||
rcode="2"
|
||||
fi
|
||||
|
||||
@ -340,32 +380,32 @@ main() {
|
||||
tmpdir="$(make_tempdir "${croc_bin_name}")"
|
||||
tmpdir_rcode="${?}"
|
||||
if [[ "${tmpdir_rcode}" == "0" ]]; then
|
||||
echo "== Created temp dir at ${tmpdir}"
|
||||
print_message "== Created temp dir at ${tmpdir}" "info"
|
||||
else
|
||||
echo "== Failed to create temp dir at ${tmpdir}"
|
||||
print_message "== Failed to create temp dir at ${tmpdir}" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
croc_arch="$(determine_arch)"
|
||||
croc_arch_rcode="${?}"
|
||||
if [[ "${croc_arch_rcode}" == "0" ]]; then
|
||||
echo "== Architecture detected as ${croc_arch}"
|
||||
print_message "== Architecture detected as ${croc_arch}" "info"
|
||||
elif [[ "${croc_arch_rcode}" == "1" ]]; then
|
||||
echo "== Architecture not detected"
|
||||
print_message "== Architecture not detected" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== 'uname' not found in path. Is it installed?"
|
||||
print_message "== 'uname' not found in path. Is it installed?" "error"
|
||||
fi
|
||||
|
||||
croc_os="$(determine_os)"
|
||||
croc_os_rcode="${?}"
|
||||
if [[ "${croc_os_rcode}" == "0" ]]; then
|
||||
echo "== OS detected as ${croc_os}"
|
||||
print_message "== OS detected as ${croc_os}" "info"
|
||||
elif [[ "${croc_os_rcode}" == "1" ]]; then
|
||||
echo "== OS not detected"
|
||||
print_message "== OS not detected" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== 'uname' not found in path. Is it installed?"
|
||||
print_message "== 'uname' not found in path. Is it installed?" "error"
|
||||
fi
|
||||
|
||||
case "${croc_arch}" in
|
||||
@ -384,65 +424,65 @@ main() {
|
||||
download_file "${croc_url}" "${tmpdir}" "${croc_file}"
|
||||
download_file_rcode="${?}"
|
||||
if [[ "${download_file_rcode}" == "0" ]]; then
|
||||
echo "== Downloaded croc archive into ${tmpdir}"
|
||||
print_message "== Downloaded croc archive into ${tmpdir}" "info"
|
||||
elif [[ "${download_file_rcode}" == "1" ]]; then
|
||||
echo "== Failed to download croc archive"
|
||||
print_message "== Failed to download croc archive" "error"
|
||||
exit 1
|
||||
elif [[ "${download_file_rcode}" == "2" ]]; then
|
||||
echo "== Failed to locate curl or wget"
|
||||
print_message "== Failed to locate curl or wget" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== Return code of download tool returned an unexpected value of ${download_file_rcode}"
|
||||
print_message "== Return code of download tool returned an unexpected value of ${download_file_rcode}" "error"
|
||||
exit 1
|
||||
fi
|
||||
download_file "${croc_checksum_url}" "${tmpdir}" "${croc_checksum_file}"
|
||||
download_checksum_file_rcode="${?}"
|
||||
if [[ "${download_checksum_file_rcode}" == "0" ]]; then
|
||||
echo "== Downloaded croc checksums file into ${tmpdir}"
|
||||
print_message "== Downloaded croc checksums file into ${tmpdir}" "info"
|
||||
elif [[ "${download_checksum_file_rcode}" == "1" ]]; then
|
||||
echo "== Failed to download croc checksums"
|
||||
print_message "== Failed to download croc checksums" "error"
|
||||
exit 1
|
||||
elif [[ "${download_checksum_file_rcode}" == "2" ]]; then
|
||||
echo "== Failed to locate curl or wget"
|
||||
print_message "== Failed to locate curl or wget" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== Return code of download tool returned an unexpected value of ${download_checksum_file_rcode}"
|
||||
print_message "== Return code of download tool returned an unexpected value of ${download_checksum_file_rcode}" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
checksum_check "${tmpdir}/${croc_checksum_file}" "${tmpdir}/${croc_file}" "${tmpdir}"
|
||||
checksum_check_rcode="${?}"
|
||||
if [[ "${checksum_check_rcode}" == "0" ]]; then
|
||||
echo "== Checksum of ${tmpdir}/${croc_file} verified"
|
||||
print_message "== Checksum of ${tmpdir}/${croc_file} verified" "ok"
|
||||
elif [[ "${checksum_check_rcode}" == "1" ]]; then
|
||||
echo "== Failed to verify checksum of ${tmpdir}/${croc_file}"
|
||||
print_message "== Failed to verify checksum of ${tmpdir}/${croc_file}" "error"
|
||||
exit 1
|
||||
elif [[ "${checksum_check_rcode}" == "20" ]]; then
|
||||
echo "== Failed to find tool to verify sha256 sums"
|
||||
print_message "== Failed to find tool to verify sha256 sums" "error"
|
||||
exit 1
|
||||
elif [[ "${checksum_check_rcode}" == "30" ]]; then
|
||||
echo "== Failed to change into working directory ${tmpdir}"
|
||||
print_message "== Failed to change into working directory ${tmpdir}" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== Unknown return code returned while checking checksum of ${tmpdir}/${croc_file}. Returned ${checksum_check_rcode}"
|
||||
print_message "== Unknown return code returned while checking checksum of ${tmpdir}/${croc_file}. Returned ${checksum_check_rcode}" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
extract_file "${tmpdir}/${croc_file}" "${tmpdir}/" "${croc_dl_ext}"
|
||||
extract_file_rcode="${?}"
|
||||
if [[ "${extract_file_rcode}" == "0" ]]; then
|
||||
echo "== Extracted ${croc_file} to ${tmpdir}/"
|
||||
print_message "== Extracted ${croc_file} to ${tmpdir}/" "info"
|
||||
elif [[ "${extract_file_rcode}" == "1" ]]; then
|
||||
echo "== Failed to extract ${croc_file}"
|
||||
print_message "== Failed to extract ${croc_file}" "error"
|
||||
exit 1
|
||||
elif [[ "${extract_file_rcode}" == "2" ]]; then
|
||||
echo "== Failed to determine which extraction tool to use"
|
||||
print_message "== Failed to determine which extraction tool to use" "error"
|
||||
exit 1
|
||||
elif [[ "${extract_file_rcode}" == "3" ]]; then
|
||||
echo "== Failed to find extraction tool in path"
|
||||
print_message "== Failed to find extraction tool in path" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== Unknown error returned from extraction attempt"
|
||||
print_message "== Unknown error returned from extraction attempt" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -453,20 +493,21 @@ main() {
|
||||
install_file_rcode="${?}";;
|
||||
esac
|
||||
if [[ "${install_file_rcode}" == "0" ]]; then
|
||||
echo "== Installed ${croc_bin_name} to ${prefix}/"
|
||||
print_message "== Installed ${croc_bin_name} to ${prefix}/" "ok"
|
||||
elif [[ "${install_file_rcode}" == "1" ]]; then
|
||||
echo "== Failed to install ${croc_bin_name}"
|
||||
print_message "== Failed to install ${croc_bin_name}" "error"
|
||||
exit 1
|
||||
elif [[ "${install_file_rcode}" == "2" ]]; then
|
||||
echo "== Failed to locate 'install' command"
|
||||
print_message "== Failed to locate 'install' command" "error"
|
||||
exit 1
|
||||
else
|
||||
echo "== Return code of 'install' returned an unexpected value of ${install_file_rcode}"
|
||||
print_message "== Return code of 'install' returned an unexpected value of ${install_file_rcode}" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "== Cleaning up ${tmpdir}"
|
||||
print_message "== Cleaning up ${tmpdir}" "info"
|
||||
cleanup "${tmpdir}"
|
||||
print_message "== Installation complete" "ok"
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user