Sfoglia il codice sorgente

Don't list apps when there's not enough ram to install them

Bob Mottram 6 anni fa
parent
commit
fa49e53734
2 ha cambiato i file con 67 aggiunte e 39 eliminazioni
  1. 1
    0
      src/freedombone-app-etherpad
  2. 66
    39
      src/freedombone-utils-selector

+ 1
- 0
src/freedombone-app-etherpad Vedi File

@@ -30,6 +30,7 @@ VARIANTS="full full-vim writer"
30 30
 
31 31
 IN_DEFAULT_INSTALL=0
32 32
 SHOW_ON_ABOUT=1
33
+MINIMUM_RAM_MB=2000
33 34
 
34 35
 ETHERPAD_DOMAIN_NAME=
35 36
 ETHERPAD_CODE=

+ 66
- 39
src/freedombone-utils-selector Vedi File

@@ -286,6 +286,25 @@ function app_not_on_onion_only {
286 286
     echo "1"
287 287
 }
288 288
 
289
+function enough_ram_for_app {
290
+    app_name="$1"
291
+
292
+    if ! grep -q "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
293
+        echo "0"
294
+        return
295
+    fi
296
+
297
+    minimum_ram_MB=$(grep "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}" | head -n 1 | awk -F '=' '{print $2}')
298
+    minimum_ram_bytes=$((minimum_ram_MB * 1024))
299
+
300
+    ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
301
+    if [ "$ram_available" -lt "$minimum_ram_bytes" ]; then
302
+        echo "1"
303
+        return
304
+    fi
305
+    echo "0"
306
+}
307
+
289 308
 # detects what apps are available
290 309
 function detect_apps {
291 310
     FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
@@ -299,11 +318,13 @@ function detect_apps {
299 318
     for filename in $FILES
300 319
     do
301 320
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
302
-        if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
303
-            # shellcheck disable=SC2068
304
-            if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
305
-                APPS_AVAILABLE+=("${app_name}")
306
-                APPS_CHOSEN+=("0")
321
+        if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then
322
+            if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
323
+                # shellcheck disable=SC2068
324
+                if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
325
+                    APPS_AVAILABLE+=("${app_name}")
326
+                    APPS_CHOSEN+=("0")
327
+                fi
307 328
             fi
308 329
         fi
309 330
     done
@@ -333,17 +354,19 @@ function detect_installable_apps {
333 354
     do
334 355
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
335 356
 
336
-        if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
337
-            # shellcheck disable=SC2068
338
-            if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
339
-                variants_list=$(app_variants "$filename")
340
-                # check for empty string
341
-                if [ ${#variants_list} -gt 0 ]; then
342
-                    APPS_AVAILABLE+=("${app_name}")
343
-                    APPS_CHOSEN+=("0")
344
-                    APPS_INSTALLED+=("$(app_is_installed "$app_name")")
345
-                    if [[ $(app_is_installed "$app_name") == "1" ]]; then
346
-                        APPS_INSTALLED_NAMES+=("$app_name")
357
+        if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then
358
+            if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
359
+                # shellcheck disable=SC2068
360
+                if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
361
+                    variants_list=$(app_variants "$filename")
362
+                    # check for empty string
363
+                    if [ ${#variants_list} -gt 0 ]; then
364
+                        APPS_AVAILABLE+=("${app_name}")
365
+                        APPS_CHOSEN+=("0")
366
+                        APPS_INSTALLED+=("$(app_is_installed "$app_name")")
367
+                        if [[ $(app_is_installed "$app_name") == "1" ]]; then
368
+                            APPS_INSTALLED_NAMES+=("$app_name")
369
+                        fi
347 370
                     fi
348 371
                 fi
349 372
             fi
@@ -367,14 +390,16 @@ function detect_installed_apps {
367 390
     do
368 391
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
369 392
 
370
-        if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
371
-            if [[ $(app_is_installed "$app_name") == "1" ]]; then
372
-                # shellcheck disable=SC2068
373
-                if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
374
-                    variants_list=$(app_variants "$filename")
375
-                    if [ ${#variants_list} -gt 0 ]; then
376
-                        APPS_AVAILABLE+=("${app_name}")
377
-                        APPS_INSTALLED_NAMES+=("$app_name")
393
+        if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then
394
+            if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
395
+                if [[ $(app_is_installed "$app_name") == "1" ]]; then
396
+                    # shellcheck disable=SC2068
397
+                    if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
398
+                        variants_list=$(app_variants "$filename")
399
+                        if [ ${#variants_list} -gt 0 ]; then
400
+                            APPS_AVAILABLE+=("${app_name}")
401
+                            APPS_INSTALLED_NAMES+=("$app_name")
402
+                        fi
378 403
                     fi
379 404
                 fi
380 405
             fi
@@ -404,27 +429,29 @@ function choose_apps_for_variant {
404 429
     for filename in $FILES
405 430
     do
406 431
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
407
-        if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
408
-            # shellcheck disable=SC2068
409
-            if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
410
-                if grep -q "VARIANTS=" "${filename}"; then
411
-                    variants_list=$(app_variants "$filename")
412
-                    if [[ "${variants_list}" == 'all'* || \
413
-                              "${variants_list}" == "$variant_name" || \
414
-                              "${variants_list}" == "$variant_name "* || \
415
-                              "${variants_list}" == *" $variant_name "* || \
416
-                              "${variants_list}" == *" $variant_name" ]]; then
417
-                        if [[ $(app_is_removed "${a}") == "0" ]]; then
418
-                            #echo $"${app_name} chosen"
419
-                            APPS_CHOSEN+=("1")
432
+        if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then
433
+            if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
434
+                # shellcheck disable=SC2068
435
+                if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
436
+                    if grep -q "VARIANTS=" "${filename}"; then
437
+                        variants_list=$(app_variants "$filename")
438
+                        if [[ "${variants_list}" == 'all'* || \
439
+                                  "${variants_list}" == "$variant_name" || \
440
+                                  "${variants_list}" == "$variant_name "* || \
441
+                                  "${variants_list}" == *" $variant_name "* || \
442
+                                  "${variants_list}" == *" $variant_name" ]]; then
443
+                            if [[ $(app_is_removed "${a}") == "0" ]]; then
444
+                                #echo $"${app_name} chosen"
445
+                                APPS_CHOSEN+=("1")
446
+                            else
447
+                                APPS_CHOSEN+=("0")
448
+                            fi
420 449
                         else
421 450
                             APPS_CHOSEN+=("0")
422 451
                         fi
423 452
                     else
424 453
                         APPS_CHOSEN+=("0")
425 454
                     fi
426
-                else
427
-                    APPS_CHOSEN+=("0")
428 455
                 fi
429 456
             fi
430 457
         fi