From fa49e53734b50f7ab90b373b15bba76312ec314d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 17:38:17 +0100 Subject: [PATCH] Don't list apps when there's not enough ram to install them --- src/freedombone-app-etherpad | 1 + src/freedombone-utils-selector | 105 +++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/freedombone-app-etherpad b/src/freedombone-app-etherpad index 807c8f79..2ae82191 100755 --- a/src/freedombone-app-etherpad +++ b/src/freedombone-app-etherpad @@ -30,6 +30,7 @@ VARIANTS="full full-vim writer" IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +MINIMUM_RAM_MB=2000 ETHERPAD_DOMAIN_NAME= ETHERPAD_CODE= diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index 597b83a7..ec17f563 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -286,6 +286,25 @@ function app_not_on_onion_only { echo "1" } +function enough_ram_for_app { + app_name="$1" + + if ! grep -q "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then + echo "0" + return + fi + + minimum_ram_MB=$(grep "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}" | head -n 1 | awk -F '=' '{print $2}') + minimum_ram_bytes=$((minimum_ram_MB * 1024)) + + ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}') + if [ "$ram_available" -lt "$minimum_ram_bytes" ]; then + echo "1" + return + fi + echo "0" +} + # detects what apps are available function detect_apps { FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*" @@ -299,11 +318,13 @@ function detect_apps { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then - # shellcheck disable=SC2068 - if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then - APPS_AVAILABLE+=("${app_name}") - APPS_CHOSEN+=("0") + if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then + APPS_AVAILABLE+=("${app_name}") + APPS_CHOSEN+=("0") + fi fi fi done @@ -333,17 +354,19 @@ function detect_installable_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then - # shellcheck disable=SC2068 - if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then - variants_list=$(app_variants "$filename") - # check for empty string - if [ ${#variants_list} -gt 0 ]; then - APPS_AVAILABLE+=("${app_name}") - APPS_CHOSEN+=("0") - APPS_INSTALLED+=("$(app_is_installed "$app_name")") - if [[ $(app_is_installed "$app_name") == "1" ]]; then - APPS_INSTALLED_NAMES+=("$app_name") + if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then + variants_list=$(app_variants "$filename") + # check for empty string + if [ ${#variants_list} -gt 0 ]; then + APPS_AVAILABLE+=("${app_name}") + APPS_CHOSEN+=("0") + APPS_INSTALLED+=("$(app_is_installed "$app_name")") + if [[ $(app_is_installed "$app_name") == "1" ]]; then + APPS_INSTALLED_NAMES+=("$app_name") + fi fi fi fi @@ -367,14 +390,16 @@ function detect_installed_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then - if [[ $(app_is_installed "$app_name") == "1" ]]; then - # shellcheck disable=SC2068 - if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then - variants_list=$(app_variants "$filename") - if [ ${#variants_list} -gt 0 ]; then - APPS_AVAILABLE+=("${app_name}") - APPS_INSTALLED_NAMES+=("$app_name") + if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then + if [[ $(app_is_installed "$app_name") == "1" ]]; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then + variants_list=$(app_variants "$filename") + if [ ${#variants_list} -gt 0 ]; then + APPS_AVAILABLE+=("${app_name}") + APPS_INSTALLED_NAMES+=("$app_name") + fi fi fi fi @@ -404,27 +429,29 @@ function choose_apps_for_variant { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then - # shellcheck disable=SC2068 - if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then - if grep -q "VARIANTS=" "${filename}"; then - variants_list=$(app_variants "$filename") - if [[ "${variants_list}" == 'all'* || \ - "${variants_list}" == "$variant_name" || \ - "${variants_list}" == "$variant_name "* || \ - "${variants_list}" == *" $variant_name "* || \ - "${variants_list}" == *" $variant_name" ]]; then - if [[ $(app_is_removed "${a}") == "0" ]]; then - #echo $"${app_name} chosen" - APPS_CHOSEN+=("1") + if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then + # shellcheck disable=SC2068 + if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then + if grep -q "VARIANTS=" "${filename}"; then + variants_list=$(app_variants "$filename") + if [[ "${variants_list}" == 'all'* || \ + "${variants_list}" == "$variant_name" || \ + "${variants_list}" == "$variant_name "* || \ + "${variants_list}" == *" $variant_name "* || \ + "${variants_list}" == *" $variant_name" ]]; then + if [[ $(app_is_removed "${a}") == "0" ]]; then + #echo $"${app_name} chosen" + APPS_CHOSEN+=("1") + else + APPS_CHOSEN+=("0") + fi else APPS_CHOSEN+=("0") fi else APPS_CHOSEN+=("0") fi - else - APPS_CHOSEN+=("0") fi fi fi