Commit 7e19870e07204fc7f7ae9980a837892d960d8428
1 parent
aafcfe1c
Exists in
master
Várias melhorias e correções! By Questor
Showing
6 changed files
with
147 additions
and
5 deletions
Show diff stats
LBIndex.tar.gz
No preview for this file type
ez_i.bash
... | ... | @@ -1257,7 +1257,7 @@ f_srv_memory() { |
1257 | 1257 | : 'Informar sobre a memória do servidor. |
1258 | 1258 | |
1259 | 1259 | Returns: |
1260 | - F_SRV_MEMORY_R (int): Quantidade de memória RAM do servidor em KBs. | |
1260 | + F_SRV_MEMORY_R (int): Quantidade de memória RAM do servidor em KB. | |
1261 | 1261 | ' |
1262 | 1262 | |
1263 | 1263 | f_get_stderr_stdout "cat /proc/meminfo" |
... | ... | @@ -1268,6 +1268,148 @@ f_srv_memory() { |
1268 | 1268 | F_SRV_MEMORY_R=$F_STR_TRIM_R |
1269 | 1269 | } |
1270 | 1270 | |
1271 | +F_GET_PERCENT_FROM_R=0 | |
1272 | +f_get_percent_from() { | |
1273 | + : 'Obter percentagem de um valor informado. | |
1274 | + | |
1275 | + Args: | |
1276 | + VAL_GET_PERCENT_P (int): Valor a partir do qual será obtida a | |
1277 | + percentagem. | |
1278 | + PERCENT_VAL_P (int): Valor de percentagem a ser obtido. | |
1279 | + REM_FLOAT_POINT_P (Optional[int]): 0 - Não remove ponto flutuante; 1 - | |
1280 | + remove ponto flutuante (se o valor obtido for maior ou igual a 1). | |
1281 | + Padrão 1. | |
1282 | + | |
1283 | + Returns: | |
1284 | + F_GET_PERCENT_FROM_R (int): Porcentagem obtida. | |
1285 | + ' | |
1286 | + | |
1287 | + VAL_GET_PERCENT_P=$1 | |
1288 | + PERCENT_VAL_P=$2 | |
1289 | + REM_FLOAT_POINT_P=$3 | |
1290 | + if [ -z "$REM_FLOAT_POINT_P" ] ; then | |
1291 | + REM_FLOAT_POINT_P=1 | |
1292 | + fi | |
1293 | + | |
1294 | + # NOTA: A estratégia abaixo foi utilizada pq o bash por padrão não | |
1295 | + # permite cálculo de ponto flutuante! By Questor | |
1296 | + F_GET_PERCENT_FROM_R=$(awk '{printf("%.5f\n",($1*($2/100)))}' <<<" $VAL_GET_PERCENT_P $PERCENT_VAL_P ") | |
1297 | + | |
1298 | + F_GET_PERCENT_FROM_R=${F_GET_PERCENT_FROM_R} | |
1299 | + if [ ${REM_FLOAT_POINT_P} -eq 1 ] ; then | |
1300 | + | |
1301 | + # NOTA: Técnica para comparar valores com ponto flutuante! By Questor | |
1302 | + if [ $(awk '{printf($1 >= $2) ? 1 : 0}' <<<" $VAL_GET_PERCENT_P 1 ") -eq 1 ] ; then | |
1303 | + | |
1304 | + # NOTA: A estratégia abaixo foi utilizada para arredondar o valor | |
1305 | + # (remover o ponto flutuante)! By Questor | |
1306 | + F_GET_PERCENT_FROM_R=${F_GET_PERCENT_FROM_R%\.*} | |
1307 | + fi | |
1308 | + fi | |
1309 | +} | |
1310 | + | |
1311 | +F_BYTES_N_UNITS_R=0 | |
1312 | +f_bytes_n_units() { | |
1313 | + : 'Converter bytes entre suas diversas unidades. | |
1314 | + | |
1315 | + Args: | |
1316 | + F_VAL_TO_CONV (int): Valor em bytes a se convertido. | |
1317 | + F_FROM_UNIT (str): Unidade em que o valor está (B, KB, MB, GB, TB e PB). | |
1318 | + F_TO_UNIT (str): Unidade para a qual se quer converter o valor (B, KB, | |
1319 | + MB, GB, TB e PB). | |
1320 | + | |
1321 | + Returns: | |
1322 | + F_BYTES_N_UNITS_R (int/float): Valor convertido para a unidade desejada. | |
1323 | + ' | |
1324 | + | |
1325 | + # NOTE: | |
1326 | + # Unit Equivalent | |
1327 | + # 1 kilobyte (KB) 1,024 bytes | |
1328 | + # 1 megabyte (MB) 1,048,576 bytes | |
1329 | + # 1 gigabyte (GB) 1,073,741,824 bytes | |
1330 | + # 1 terabyte (TB) 1,099,511,627,776 bytes | |
1331 | + # 1 petabyte (PB) 1,125,899,906,842,624 bytes | |
1332 | + # By Questor | |
1333 | + | |
1334 | + F_VAL_TO_CONV=$1 | |
1335 | + F_FROM_UNIT=$2 | |
1336 | + F_TO_UNIT=$3 | |
1337 | + | |
1338 | + CONV_LOOPS=0 | |
1339 | + UNIT_FACTOR_0=0 | |
1340 | + while [ ${CONV_LOOPS} -le 1 ] ; do | |
1341 | + UNIT_FACTOR=0 | |
1342 | + if [ ${CONV_LOOPS} -eq 0 ] ; then | |
1343 | + UNIT_NOW=$F_FROM_UNIT | |
1344 | + else | |
1345 | + UNIT_NOW=$F_TO_UNIT | |
1346 | + fi | |
1347 | + case "$UNIT_NOW" in | |
1348 | + B) | |
1349 | + UNIT_FACTOR=0 | |
1350 | + ;; | |
1351 | + KB) | |
1352 | + UNIT_FACTOR=1 | |
1353 | + ;; | |
1354 | + MB) | |
1355 | + UNIT_FACTOR=2 | |
1356 | + ;; | |
1357 | + GB) | |
1358 | + UNIT_FACTOR=3 | |
1359 | + ;; | |
1360 | + TB) | |
1361 | + UNIT_FACTOR=4 | |
1362 | + ;; | |
1363 | + PB) | |
1364 | + UNIT_FACTOR=5 | |
1365 | + ;; | |
1366 | + esac | |
1367 | + if [ ${CONV_LOOPS} -eq 0 ] ; then | |
1368 | + UNIT_FACTOR_0=$UNIT_FACTOR | |
1369 | + else | |
1370 | + UNIT_FACTOR=$(awk '{printf($1-$2)}' <<<" $UNIT_FACTOR_0 $UNIT_FACTOR ") | |
1371 | + F_VAL_TO_CONV=$(awk '{printf("%.5f\n",($1*(1024^$2)))}' <<<" $F_VAL_TO_CONV $UNIT_FACTOR ") | |
1372 | + fi | |
1373 | + ((CONV_LOOPS++)) | |
1374 | + done | |
1375 | + | |
1376 | + # NOTE: Remover zeros denecessários (Ex.: 0.05000 -> 0.05)! | |
1377 | + F_VAL_TO_CONV=$(echo $F_VAL_TO_CONV | sed 's/0\{1,\}$//') | |
1378 | + | |
1379 | + # NOTE: Remover ponto flutuante quando não necessário (Ex.: 5.00000 -> 5)! | |
1380 | + if [ $(echo $F_VAL_TO_CONV | awk '$0-int($0){print 0;next}{print 1}') -eq 1 ] ; then | |
1381 | + F_VAL_TO_CONV=${F_VAL_TO_CONV%\.*} | |
1382 | + fi | |
1383 | + | |
1384 | + F_BYTES_N_UNITS_R=$F_VAL_TO_CONV | |
1385 | +} | |
1386 | + | |
1387 | +F_PROCS_QTT_R=0 | |
1388 | +f_procs_qtt() { | |
1389 | + : 'Determine the amount of processes on a server. | |
1390 | + | |
1391 | + Args: | |
1392 | + F_MULT_FACTOR (Optional[int]): Multiplying factor over the number of | |
1393 | + processes on the server. Default 1. | |
1394 | + | |
1395 | + Returns: | |
1396 | + F_PROCS_QTT_R (int): Number of server processes multiplied by a factor | |
1397 | + if informed. | |
1398 | + ' | |
1399 | + | |
1400 | + F_MULT_FACTOR=$1 | |
1401 | + if [ -z "$F_MULT_FACTOR" ] ; then | |
1402 | + F_MULT_FACTOR=1 | |
1403 | + fi | |
1404 | + f_get_stderr_stdout "nproc" | |
1405 | + if [[ $F_GET_STDERR_R == "" ]]; then | |
1406 | + F_PROCS_QTT_R=$(( F_GET_STDOUT_R * F_MULT_FACTOR )) | |
1407 | + else | |
1408 | + 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\"." | |
1409 | + f_error_exit | |
1410 | + fi | |
1411 | +} | |
1412 | + | |
1271 | 1413 | # < -------------------------------------------------------------------------- |
1272 | 1414 | |
1273 | 1415 | # > -------------------------------------------------------------------------- | ... | ... |
install.bash
... | ... | @@ -25,7 +25,7 @@ LBI - LBIndex Installer |
25 | 25 | EOF |
26 | 26 | |
27 | 27 | read -d '' VERSION_F <<"EOF" |
28 | -0.1.1.0 | |
28 | +0.1.2.0 | |
29 | 29 | EOF |
30 | 30 | |
31 | 31 | # NOTE: Para versionamento usar "MAJOR.MINOR.REVISION.BUILDNUMBER"! |
... | ... | @@ -751,13 +751,13 @@ f_inst_lib() { |
751 | 751 | f_yes_no "Install the LIB - liblightbase?" |
752 | 752 | if [ ${EZ_I_SKIP_ON_V} -eq 1 ] || [ ${YES_NO_R} -eq 1 ] ; then |
753 | 753 | EZ_I_SKIP_ON_V=$FAST_INST |
754 | - f_inst_lib_py_packs 1 | |
755 | 754 | 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\"!" |
756 | 755 | F_BAK_MD_R=1 |
757 | 756 | if [ ${F_CHK_BY_PATH_HLP_R} -eq 1 ] ; then |
758 | 757 | f_ez_mv_bak "$BASE_INST_DIR_V/$VE_2_X/src/liblightbase" "Backup old version and update? (\"y\" recommended)" |
759 | 758 | fi |
760 | 759 | if [ ${F_BAK_MD_R} -eq 1 ] ; then |
760 | + f_inst_lib_py_packs 1 | |
761 | 761 | cd "$SCRIPTDIR_V" |
762 | 762 | tar -zxvf liblightbase.tar.gz |
763 | 763 | mv "$SCRIPTDIR_V/liblightbase" "$BASE_INST_DIR_V/$VE_2_X/src/" | ... | ... |
liblightbase.tar.gz
No preview for this file type
py-packs-LBIndex.bash
... | ... | @@ -18,7 +18,7 @@ if [ -z "$BASE_INST_DIR_V" ] ; then |
18 | 18 | BASE_INST_DIR_V="/usr/local/lb" |
19 | 19 | |
20 | 20 | QUESTION_F="Enter the installation directory. |
21 | - Use empty for \"$BASE_INST_DIR_V\"!" | |
21 | +Use empty for \"$BASE_INST_DIR_V\"!" | |
22 | 22 | |
23 | 23 | f_get_usr_input "$QUESTION_F" 1 |
24 | 24 | QUESTION_F="" | ... | ... |
py-packs-liblightbase.bash
... | ... | @@ -18,7 +18,7 @@ if [ -z "$BASE_INST_DIR_V" ] ; then |
18 | 18 | BASE_INST_DIR_V="/usr/local/lb" |
19 | 19 | |
20 | 20 | QUESTION_F="Enter the installation directory. |
21 | - Use empty for \"$BASE_INST_DIR_V\"!" | |
21 | +Use empty for \"$BASE_INST_DIR_V\"!" | |
22 | 22 | |
23 | 23 | f_get_usr_input "$QUESTION_F" 1 |
24 | 24 | QUESTION_F="" | ... | ... |