From 7e19870e07204fc7f7ae9980a837892d960d8428 Mon Sep 17 00:00:00 2001 From: edulucio Date: Fri, 16 Jun 2017 15:37:51 -0300 Subject: [PATCH] Várias melhorias e correções! By Questor --- LBIndex.tar.gz | Bin 3593091 -> 0 bytes ez_i.bash | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- install.bash | 4 ++-- liblightbase.tar.gz | Bin 767103 -> 0 bytes py-packs-LBIndex.bash | 2 +- py-packs-liblightbase.bash | 2 +- 6 files changed, 147 insertions(+), 5 deletions(-) diff --git a/LBIndex.tar.gz b/LBIndex.tar.gz index dc61db2..80e652d 100644 Binary files a/LBIndex.tar.gz and b/LBIndex.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 aa8188a..454b838 100755 --- a/install.bash +++ b/install.bash @@ -25,7 +25,7 @@ LBI - LBIndex Installer EOF read -d '' VERSION_F <<"EOF" -0.1.1.0 +0.1.2.0 EOF # NOTE: Para versionamento usar "MAJOR.MINOR.REVISION.BUILDNUMBER"! @@ -751,13 +751,13 @@ f_inst_lib() { f_yes_no "Install the LIB - liblightbase?" if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then EZ_I_SKIP_ON_V=$FAST_INST - f_inst_lib_py_packs 1 f_chk_by_path_hlp "$BASE_INST_DIR_V/$VE_2_X/src/liblightbase" "d" "\"liblightbase\" already installed in \"$BASE_INST_DIR_V/$VE_2_X/src\"!" F_BAK_MD_R=1 if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then f_ez_mv_bak "$BASE_INST_DIR_V/$VE_2_X/src/liblightbase" "Backup old version and update? (\"y\" recommended)" fi if [ ${F_BAK_MD_R} -eq 1 ] ; then + f_inst_lib_py_packs 1 cd "$SCRIPTDIR_V" tar -zxvf liblightbase.tar.gz mv "$SCRIPTDIR_V/liblightbase" "$BASE_INST_DIR_V/$VE_2_X/src/" diff --git a/liblightbase.tar.gz b/liblightbase.tar.gz index ae6b2df..7062ddb 100644 Binary files a/liblightbase.tar.gz and b/liblightbase.tar.gz differ diff --git a/py-packs-LBIndex.bash b/py-packs-LBIndex.bash index 6464b93..346982d 100755 --- a/py-packs-LBIndex.bash +++ b/py-packs-LBIndex.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="" diff --git a/py-packs-liblightbase.bash b/py-packs-liblightbase.bash index dd01beb..710b810 100755 --- a/py-packs-liblightbase.bash +++ b/py-packs-liblightbase.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