From d37f43bf8487910fa1f16a27c3a8ffca2f77da0b Mon Sep 17 00:00:00 2001 From: Daniel De Lucca Date: Sat, 17 Apr 2021 05:57:01 +0000 Subject: [PATCH] feat(modules): adds previous code --- modules/authorization.sh | 6 +++++ modules/feedback.sh | 49 ++++++++++++++++++++++++++++++++++++++++ modules/validation.sh | 18 +++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 modules/authorization.sh create mode 100644 modules/feedback.sh create mode 100644 modules/validation.sh diff --git a/modules/authorization.sh b/modules/authorization.sh new file mode 100644 index 0000000..0bb2fef --- /dev/null +++ b/modules/authorization.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +function update_su_timestamp { + sudo -k + sudo -v +} \ No newline at end of file diff --git a/modules/feedback.sh b/modules/feedback.sh new file mode 100644 index 0000000..13a0c7a --- /dev/null +++ b/modules/feedback.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Imports +# ------------------------------------------------------------------------------------------------- + +source <(curl -s https://raw.githubusercontent.com/tlatsas/bash-spinner/master/spinner.sh) + +# ------------------------------------------------------------------------------------------------- + +function start_spinner_in_category { + category=$1 + message=$2 + + full_message=" \x1B[36m\r➤\e[1m ${category}:\x1B[0m ${message}" + + start_spinner "${full_message}" +} + +function log_title { + message=$1 + + bold=$(tput bold) + reset=$(tput sgr0) + magenta=$(tput setaf 5) + number_of_columns="$(($(tput cols)-27))" + separator_spaces=$(printf "%${number_of_columns}s") + + echo + echo "${bold}${magenta}${message}${reset}" + echo ${separator_spaces// /-} +} + +function log_error { + message=$1 + + bold=$(tput bold) + reset=$(tput sgr0) + red=$(tput setaf 1) + + echo "${bold}${red}Error:${reset}" + echo "${red} ${message}${reset}" +} + +function throw_error { + message=$1 + + log_error "${message}" + exit 1 +} \ No newline at end of file diff --git a/modules/validation.sh b/modules/validation.sh new file mode 100644 index 0000000..2f475a7 --- /dev/null +++ b/modules/validation.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Imports +# ------------------------------------------------------------------------------------------------- + +source <(https://raw.githubusercontent.com/delucca/shell-functions/1.0.0/modules/feedback.sh) + +# Helpers +# ------------------------------------------------------------------------------------------------- + +function validate_bash_dependency { + major_version="$(bash --version | head -1 | cut -d ' ' -f 4 | cut -d '.' -f 1)" + min_major_version="4" + + if [ "${major_version}" -lt "${min_major_version}" ]; then + throw_error "Your bash major version must be ${min_major_version} or greater" + fi +} \ No newline at end of file