|
| 1 | +#!/bin/bash |
| 2 | +# Version: @(#).functions0.sh 1.0.0 |
| 3 | +# License |
| 4 | +# Copyright (c) 2023 Oracle and/or its affiliates. |
| 5 | +# Licensed under the Universal Permissive License (UPL), Version 1.0. |
| 6 | +# See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/folder-structure/LICENSE) for more details. |
| 7 | +# |
| 8 | +#@ functions needed to run healthcheck.storage.sh |
| 9 | +#@ |
| 10 | +# |
| 11 | +# Update history: |
| 12 | +# |
| 13 | +# V 1.0.0 28.06.2023 initial version |
| 14 | +# |
| 15 | + |
| 16 | + |
| 17 | +if [ 1 -eq 1 ] ; then # define colors |
| 18 | +Color_Off='\e[0m' # Text Reset |
| 19 | + |
| 20 | +# Regular Colors |
| 21 | +Black='\e[0;30m' # Black |
| 22 | +Red='\e[0;31m' # Red |
| 23 | +Green='\e[0;32m' # Green |
| 24 | +Yellow='\e[0;33m' # Yellow |
| 25 | +Blue='\e[0;34m' # Blue |
| 26 | +Purple='\e[0;35m' # Purple |
| 27 | +Cyan='\e[0;36m' # Cyan |
| 28 | +White='\e[0;37m' # White |
| 29 | + |
| 30 | +# Bold |
| 31 | +BBlack='\e[1;30m' # Black |
| 32 | +BRed='\e[1;31m' # Red |
| 33 | +BGreen='\e[1;32m' # Green |
| 34 | +BYellow='\e[1;33m' # Yellow |
| 35 | +BBlue='\e[1;34m' # Blue |
| 36 | +BPurple='\e[1;35m' # Purple |
| 37 | +BCyan='\e[1;36m' # Cyan |
| 38 | +BWhite='\e[1;37m' # White |
| 39 | + |
| 40 | +# Underline |
| 41 | +UBlack='\e[4;30m' # Black |
| 42 | +URed='\e[4;31m' # Red |
| 43 | +UGreen='\e[4;32m' # Green |
| 44 | +UYellow='\e[4;33m' # Yellow |
| 45 | +UBlue='\e[4;34m' # Blue |
| 46 | +UPurple='\e[4;35m' # Purple |
| 47 | +UCyan='\e[4;36m' # Cyan |
| 48 | +UWhite='\e[4;37m' # White |
| 49 | + |
| 50 | +# Background |
| 51 | +On_Black='\e[40m' # Black |
| 52 | +On_Red='\e[41m' # Red |
| 53 | +On_Green='\e[42m' # Green |
| 54 | +On_Yellow='\e[43m' # Yellow |
| 55 | +On_Blue='\e[44m' # Blue |
| 56 | +On_Purple='\e[45m' # Purple |
| 57 | +On_Cyan='\e[46m' # Cyan |
| 58 | +On_White='\e[47m' # White |
| 59 | + |
| 60 | +# High Intensity |
| 61 | +IBlack='\e[0;90m' # Black |
| 62 | +IRed='\e[0;91m' # Red |
| 63 | +IGreen='\e[0;92m' # Green |
| 64 | +IYellow='\e[0;93m' # Yellow |
| 65 | +IBlue='\e[0;94m' # Blue |
| 66 | +IPurple='\e[0;95m' # Purple |
| 67 | +ICyan='\e[0;96m' # Cyan |
| 68 | +IWhite='\e[0;97m' # White |
| 69 | + |
| 70 | +# Bold High Intensity |
| 71 | +BIBlack='\e[1;90m' # Black |
| 72 | +BIRed='\e[1;91m' # Red |
| 73 | +BIGreen='\e[1;92m' # Green |
| 74 | +BIYellow='\e[1;93m' # Yellow |
| 75 | +BIBlue='\e[1;94m' # Blue |
| 76 | +BIPurple='\e[1;95m' # Purple |
| 77 | +BICyan='\e[1;96m' # Cyan |
| 78 | +BIWhite='\e[1;97m' # White |
| 79 | + |
| 80 | +# High Intensity backgrounds |
| 81 | +On_IBlack='\e[0;100m' # Black |
| 82 | +On_IRed='\e[0;101m' # Red |
| 83 | +On_IGreen='\e[0;102m' # Green |
| 84 | +On_IYellow='\e[0;103m' # Yellow |
| 85 | +On_IBlue='\e[0;104m' # Blue |
| 86 | +On_IPurple='\e[0;105m' # Purple |
| 87 | +On_ICyan='\e[0;106m' # Cyan |
| 88 | +On_IWhite='\e[0;107m' # White |
| 89 | +fi |
| 90 | + |
| 91 | +if [ 1 -eq 1 ] ; then # set environement |
| 92 | +. parameter1.sh |
| 93 | +fi |
| 94 | + |
| 95 | +if [ 1 -eq 1 ] ; then # level 0 functions (this functions do not need/call other then level 0 functions) |
| 96 | + |
| 97 | +function color_print() { |
| 98 | +if [ ${DEBUG_LEVEL} -eq 0 ] ; then echo -e "$1: $2 ${Color_Off}" ; fi |
| 99 | +if [ ${DEBUG_LEVEL} -eq 1 ] ; then echo -e "$1(${DEBUG_LEVEL}) $(date "+%d.%m.%Y %H:%M:%S") : $2 ${Color_Off}" ; fi |
| 100 | +if [ ${DEBUG_LEVEL} -eq 2 ] ; then echo -e "$1(${DEBUG_LEVEL}) $(date "+%d.%m.%Y %H:%M:%S") : $2 ${Color_Off}" ; fi |
| 101 | +if [ ${DEBUG_LEVEL} -gt 2 ] ; then echo -e "$1(${DEBUG_LEVEL}) $(date "+%d.%m.%Y %H:%M:%S") : $2 ${Color_Off}" ; fi |
| 102 | +} |
| 103 | + |
| 104 | +TIMESTAMP=$(date "+%Y%m%d%H%M%S") # timestamp |
| 105 | +UNIQUE_ID="k4JgHrt${TIMESTAMP}" # generate a unique ID to tag resources created by this script |
| 106 | +if [ -e /dev/urandom ];then |
| 107 | + UNIQUE_ID=$(cat /dev/urandom|LC_CTYPE=C tr -dc "[:alnum:]"|fold -w 32|head -n 1) |
| 108 | +fi |
| 109 | +TMP_FILE_LIST=() # array keeps a list of temporary files to cleanup |
| 110 | +THIS_SCRIPT="$(basename ${BASH_SOURCE})" # sciptname |
| 111 | + |
| 112 | +# Do cleanup |
| 113 | +function Cleanup() { |
| 114 | +color_print "${MYcolor}" "$PF1 function: $FUNCNAME" |
| 115 | + for i in "${!TMP_FILE_LIST[@]}"; do |
| 116 | + if [ -f "${TMP_FILE_LIST[$i]}" ]; then |
| 117 | + #echo -e "deleting ${TMP_FILE_LIST[$i]}" |
| 118 | + rm -f "${TMP_FILE_LIST[$i]}" |
| 119 | + fi |
| 120 | + done |
| 121 | +} |
| 122 | + |
| 123 | +# Do cleanup, display error message and exit |
| 124 | +function Interrupt() { |
| 125 | + Cleanup |
| 126 | + exitcode=99 |
| 127 | + echo -e "\nScript '${THIS_SCRIPT}' aborted by user. $Color_Off" |
| 128 | + exit $exitcode |
| 129 | +} |
| 130 | + |
| 131 | +# trap ctrl-c and call interrupt() |
| 132 | +trap Interrupt INT |
| 133 | +# trap exit and call cleanup() |
| 134 | +trap Cleanup EXIT |
| 135 | + |
| 136 | +function tempfile() |
| 137 | +{ |
| 138 | + local __resultvar=$1 |
| 139 | + local __tmp_file=$(mktemp -t ${THIS_SCRIPT}_tmp_file.XXXXXXXXXXX) || { |
| 140 | + echo -e "$Cyan ......#*** Creation of ${__tmp_file} failed $Color_Off"; |
| 141 | + exit 1; |
| 142 | + } |
| 143 | + TMP_FILE_LIST+=("${__tmp_file}") |
| 144 | + if [[ "$__resultvar" ]]; then |
| 145 | + eval $__resultvar="'$__tmp_file'" |
| 146 | + else |
| 147 | + echo -e "$Cyan ......#$__tmp_file" |
| 148 | + fi |
| 149 | +} |
| 150 | + |
| 151 | +fi |
| 152 | + |
| 153 | +# --------------------------------------------------------------------------------------------------------------------------------------------- |
| 154 | +# end of file |
| 155 | +# --------------------------------------------------------------------------------------------------------------------------------------------- |
0 commit comments