From ce1bcb26dc229eec1d19140822894dd723d168be Mon Sep 17 00:00:00 2001 From: edulucio Date: Fri, 16 Jun 2017 15:41:17 -0300 Subject: [PATCH] Várias melhorias e correções! By Questor --- LBConverter.tar.gz | Bin 42220011 -> 0 bytes ez_i.bash | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- install.bash | 2 +- py-packs-LBConverter.bash | 2 +- 4 files changed, 145 insertions(+), 3 deletions(-) diff --git a/LBConverter.tar.gz b/LBConverter.tar.gz index e632bfe..7226f2f 100644 Binary files a/LBConverter.tar.gz and b/LBConverter.tar.gz differ diff --git a/ez_i.bash b/ez_i.bash index 3b50cfb..681d774 100755 --- a/ez_i.bash +++ b/ez_i.bash @@ -1257,7 +1257,7 @@ f_srv_memory() { : 'Informar sobre a memória do servidor. Returns: - F_SRV_MEMORY_R (int): Quantidade de memória RAM do servidor em KBs. + F_SRV_MEMORY_R (int): Quantidade de memória RAM do servidor em KB. ' f_get_stderr_stdout "cat /proc/meminfo" @@ -1268,6 +1268,148 @@ f_srv_memory() { F_SRV_MEMORY_R=$F_STR_TRIM_R } +F_GET_PERCENT_FROM_R=0 +f_get_percent_from() { + : 'Obter percentagem de um valor informado. + + Args: + VAL_GET_PERCENT_P (int): Valor a partir do qual será obtida a + percentagem. + PERCENT_VAL_P (int): Valor de percentagem a ser obtido. + REM_FLOAT_POINT_P (Optional[int]): 0 - Não remove ponto flutuante; 1 - + remove ponto flutuante (se o valor obtido for maior ou igual a 1). + Padrão 1. + + Returns: + F_GET_PERCENT_FROM_R (int): Porcentagem obtida. + ' + + VAL_GET_PERCENT_P=$1 + PERCENT_VAL_P=$2 + REM_FLOAT_POINT_P=$3 + if [ -z "$REM_FLOAT_POINT_P" ] ; then + REM_FLOAT_POINT_P=1 + fi + + # NOTA: A estratégia abaixo foi utilizada pq o bash por padrão não + # permite cálculo de ponto flutuante! By Questor + F_GET_PERCENT_FROM_R=$(awk '{printf("%.5f\n",($1*($2/100)))}' <<<" $VAL_GET_PERCENT_P $PERCENT_VAL_P ") + + F_GET_PERCENT_FROM_R=${F_GET_PERCENT_FROM_R} + if [ ${REM_FLOAT_POINT_P} -eq 1 ] ; then + + # NOTA: Técnica para comparar valores com ponto flutuante! By Questor + if [ $(awk '{printf($1 >= $2) ? 1 : 0}' <<<" $VAL_GET_PERCENT_P 1 ") -eq 1 ] ; then + + # NOTA: A estratégia abaixo foi utilizada para arredondar o valor + # (remover o ponto flutuante)! By Questor + F_GET_PERCENT_FROM_R=${F_GET_PERCENT_FROM_R%\.*} + fi + fi +} + +F_BYTES_N_UNITS_R=0 +f_bytes_n_units() { + : 'Converter bytes entre suas diversas unidades. + + Args: + F_VAL_TO_CONV (int): Valor em bytes a se convertido. + F_FROM_UNIT (str): Unidade em que o valor está (B, KB, MB, GB, TB e PB). + F_TO_UNIT (str): Unidade para a qual se quer converter o valor (B, KB, + MB, GB, TB e PB). + + Returns: + F_BYTES_N_UNITS_R (int/float): Valor convertido para a unidade desejada. + ' + + # NOTE: + # Unit Equivalent + # 1 kilobyte (KB) 1,024 bytes + # 1 megabyte (MB) 1,048,576 bytes + # 1 gigabyte (GB) 1,073,741,824 bytes + # 1 terabyte (TB) 1,099,511,627,776 bytes + # 1 petabyte (PB) 1,125,899,906,842,624 bytes + # By Questor + + F_VAL_TO_CONV=$1 + F_FROM_UNIT=$2 + F_TO_UNIT=$3 + + CONV_LOOPS=0 + UNIT_FACTOR_0=0 + while [ ${CONV_LOOPS} -le 1 ] ; do + UNIT_FACTOR=0 + if [ ${CONV_LOOPS} -eq 0 ] ; then + UNIT_NOW=$F_FROM_UNIT + else + UNIT_NOW=$F_TO_UNIT + fi + case "$UNIT_NOW" in + B) + UNIT_FACTOR=0 + ;; + KB) + UNIT_FACTOR=1 + ;; + MB) + UNIT_FACTOR=2 + ;; + GB) + UNIT_FACTOR=3 + ;; + TB) + UNIT_FACTOR=4 + ;; + PB) + UNIT_FACTOR=5 + ;; + esac + if [ ${CONV_LOOPS} -eq 0 ] ; then + UNIT_FACTOR_0=$UNIT_FACTOR + else + UNIT_FACTOR=$(awk '{printf($1-$2)}' <<<" $UNIT_FACTOR_0 $UNIT_FACTOR ") + F_VAL_TO_CONV=$(awk '{printf("%.5f\n",($1*(1024^$2)))}' <<<" $F_VAL_TO_CONV $UNIT_FACTOR ") + fi + ((CONV_LOOPS++)) + done + + # NOTE: Remover zeros denecessários (Ex.: 0.05000 -> 0.05)! + F_VAL_TO_CONV=$(echo $F_VAL_TO_CONV | sed 's/0\{1,\}$//') + + # NOTE: Remover ponto flutuante quando não necessário (Ex.: 5.00000 -> 5)! + if [ $(echo $F_VAL_TO_CONV | awk '$0-int($0){print 0;next}{print 1}') -eq 1 ] ; then + F_VAL_TO_CONV=${F_VAL_TO_CONV%\.*} + fi + + F_BYTES_N_UNITS_R=$F_VAL_TO_CONV +} + +F_PROCS_QTT_R=0 +f_procs_qtt() { + : 'Determine the amount of processes on a server. + + Args: + F_MULT_FACTOR (Optional[int]): Multiplying factor over the number of + processes on the server. Default 1. + + Returns: + F_PROCS_QTT_R (int): Number of server processes multiplied by a factor + if informed. + ' + + F_MULT_FACTOR=$1 + if [ -z "$F_MULT_FACTOR" ] ; then + F_MULT_FACTOR=1 + fi + f_get_stderr_stdout "nproc" + if [[ $F_GET_STDERR_R == "" ]]; then + F_PROCS_QTT_R=$(( F_GET_STDOUT_R * F_MULT_FACTOR )) + else + f_enter_to_cont "An error occurred when trying to determine an appropriate amount of processes to use on this server! ERROR: \"$F_GET_STDERR_R$F_GET_STDOUT_R\"." + f_error_exit + fi +} + # < -------------------------------------------------------------------------- # > -------------------------------------------------------------------------- diff --git a/install.bash b/install.bash index aa05c19..9a07785 100755 --- a/install.bash +++ b/install.bash @@ -29,7 +29,7 @@ EOF # http://programmers.stackexchange.com/questions/24987/what-exactly-is-the-build-number-in-major-minor-buildnumber-revision read -d '' VERSION_F <<"EOF" -0.1.1.0 +0.1.2.0 EOF read -d '' ABOUT_F <<"EOF" diff --git a/py-packs-LBConverter.bash b/py-packs-LBConverter.bash index 20d5c18..60ca9c3 100755 --- a/py-packs-LBConverter.bash +++ b/py-packs-LBConverter.bash @@ -18,7 +18,7 @@ if [ -z "$BASE_INST_DIR_V" ] ; then BASE_INST_DIR_V="/usr/local/lb" QUESTION_F="Enter the installation directory. - Use empty for \"$BASE_INST_DIR_V\"!" +Use empty for \"$BASE_INST_DIR_V\"!" f_get_usr_input "$QUESTION_F" 1 QUESTION_F="" -- libgit2 0.21.2