Commit ce1bcb26dc229eec1d19140822894dd723d168be
1 parent
17c88e01
Exists in
master
Várias melhorias e correções! By Questor
Showing
4 changed files
with
145 additions
and
3 deletions
Show diff stats
LBConverter.tar.gz
No preview for this file type
ez_i.bash
@@ -1257,7 +1257,7 @@ f_srv_memory() { | @@ -1257,7 +1257,7 @@ f_srv_memory() { | ||
1257 | : 'Informar sobre a memória do servidor. | 1257 | : 'Informar sobre a memória do servidor. |
1258 | 1258 | ||
1259 | Returns: | 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 | f_get_stderr_stdout "cat /proc/meminfo" | 1263 | f_get_stderr_stdout "cat /proc/meminfo" |
@@ -1268,6 +1268,148 @@ f_srv_memory() { | @@ -1268,6 +1268,148 @@ f_srv_memory() { | ||
1268 | F_SRV_MEMORY_R=$F_STR_TRIM_R | 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
@@ -29,7 +29,7 @@ EOF | @@ -29,7 +29,7 @@ EOF | ||
29 | # http://programmers.stackexchange.com/questions/24987/what-exactly-is-the-build-number-in-major-minor-buildnumber-revision | 29 | # http://programmers.stackexchange.com/questions/24987/what-exactly-is-the-build-number-in-major-minor-buildnumber-revision |
30 | 30 | ||
31 | read -d '' VERSION_F <<"EOF" | 31 | read -d '' VERSION_F <<"EOF" |
32 | -0.1.1.0 | 32 | +0.1.2.0 |
33 | EOF | 33 | EOF |
34 | 34 | ||
35 | read -d '' ABOUT_F <<"EOF" | 35 | read -d '' ABOUT_F <<"EOF" |
py-packs-LBConverter.bash
@@ -18,7 +18,7 @@ if [ -z "$BASE_INST_DIR_V" ] ; then | @@ -18,7 +18,7 @@ if [ -z "$BASE_INST_DIR_V" ] ; then | ||
18 | BASE_INST_DIR_V="/usr/local/lb" | 18 | BASE_INST_DIR_V="/usr/local/lb" |
19 | 19 | ||
20 | QUESTION_F="Enter the installation directory. | 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 | f_get_usr_input "$QUESTION_F" 1 | 23 | f_get_usr_input "$QUESTION_F" 1 |
24 | QUESTION_F="" | 24 | QUESTION_F="" |