From 519d3ee19703138e5aff2a92e90e768b5ca4100c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 8 May 2018 18:58:16 +0100 Subject: [PATCH 01/14] Starting gnusocial daemons --- src/freedombone-app-gnusocial | 5 ++++- src/freedombone-app-postactiv | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial index 7859ea5b..04ba854a 100755 --- a/src/freedombone-app-gnusocial +++ b/src/freedombone-app-gnusocial @@ -935,9 +935,12 @@ function install_gnusocial { sed -i 's|"theme":.*|"theme": "base16-apathy.css",|g' "/var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs/static/config.json" fi - # unleash the daemons! + # this has to be run as root initially, otherwise database tables + # don't get created cd "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs" || exit 236482684 php scripts/checkschema.php + sh scripts/startdaemons.sh + /etc/cron.hourly/gnusocial-daemons systemctl restart nginx diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index dc98d3ce..2cb22d97 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -952,7 +952,12 @@ function install_postactiv { expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS" - # unleash the daemons! + # this has to be run as root initially, otherwise database tables + # don't get created + cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 3658254254 + sh scripts/startdaemons.sh + php scripts/checkschema.php + /etc/cron.hourly/postactiv-daemons systemctl restart nginx From 22132e1241b6f5ff5ea366298cb64c0f42914a01 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 8 May 2018 20:25:59 +0100 Subject: [PATCH 02/14] Try postactiv with different server name --- src/freedombone-app-postactiv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index 2cb22d97..51fde3b8 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -845,9 +845,9 @@ function install_postactiv_main { fi POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME} - if [[ $ONION_ONLY != 'no' ]]; then - POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME} - fi + #if [[ $ONION_ONLY != 'no' ]]; then + # POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME} + #fi # Create the configuration postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php From 7345b7b6299fd6da834f24e6ccb270b3f0f23056 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 8 May 2018 21:13:17 +0100 Subject: [PATCH 03/14] Revert --- src/freedombone-app-postactiv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index 51fde3b8..2cb22d97 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -845,9 +845,9 @@ function install_postactiv_main { fi POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME} - #if [[ $ONION_ONLY != 'no' ]]; then - # POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME} - #fi + if [[ $ONION_ONLY != 'no' ]]; then + POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME} + fi # Create the configuration postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php From 43213139223e4e86c8bf82ae5e654a99da06db75 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 8 May 2018 22:34:59 +0100 Subject: [PATCH 04/14] Some extra kills when removing gnusocial/postactiv --- src/freedombone-app-gnusocial | 1 + src/freedombone-app-postactiv | 1 + 2 files changed, 2 insertions(+) diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial index 04ba854a..05cf03ee 100755 --- a/src/freedombone-app-gnusocial +++ b/src/freedombone-app-gnusocial @@ -581,6 +581,7 @@ function remove_gnusocial { fi kill_pid=$(pgrep "/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" | head -n 1) kill -9 "$kill_pid" + pkill "$GNUSOCIAL_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" if [ -d "/var/www/$GNUSOCIAL_DOMAIN_NAME" ]; then rm -rf "/var/www/$GNUSOCIAL_DOMAIN_NAME" diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index 2cb22d97..fd9e97c5 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -595,6 +595,7 @@ function remove_postactiv { fi kill_pid=$(pgrep "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" | head -n 1) kill -9 "$kill_pid" + pkill "$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" if [ -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME" From 1eaefd9c3612d8905dc3d69d44c1060d746c67dc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 13:08:53 +0100 Subject: [PATCH 05/14] Disable gnusocial and postactiv on onion only installs There are database problems possibly related to being primarily on an onion address --- src/freedombone-app-gnusocial | 4 ++-- src/freedombone-app-postactiv | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial index 05cf03ee..93c57f10 100755 --- a/src/freedombone-app-gnusocial +++ b/src/freedombone-app-gnusocial @@ -912,8 +912,8 @@ function install_gnusocial_main { } function install_gnusocial { - if [ ! "$ONION_ONLY" ]; then - ONION_ONLY='no' + if [[ "$ONION_ONLY" != 'no' ]]; then + return fi install_gnusocial_main diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index fd9e97c5..ae7e7b25 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -927,8 +927,8 @@ function install_postactiv_main { } function install_postactiv { - if [ ! "$ONION_ONLY" ]; then - ONION_ONLY='no' + if [[ "$ONION_ONLY" != 'no' ]]; then + return fi install_postactiv_main From 1af2de409094290a1db88eeaf34feb8dc6790a0a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 14:28:34 +0100 Subject: [PATCH 06/14] Some apps not installable on onion only version --- src/freedombone-addremove | 28 ++++++++++++++++++++++------ src/freedombone-app-gnusocial | 1 + src/freedombone-app-hubzilla | 1 + src/freedombone-app-jitsi | 1 + src/freedombone-app-matrix | 1 + src/freedombone-app-postactiv | 1 + src/freedombone-app-riot | 1 + 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index d42c3796..277da7fe 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -80,6 +80,20 @@ function mark_unselected_apps_as_removed { done } +function app_not_on_onion_only { + app_name="$1" + + read_config_param ONION_ONLY + + if [[ "$ONION_ONLY" != 'no' ]]; then + if ! grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then + echo "0" + return + fi + fi + echo "1" +} + function app_expected_to_be_installed { # is the given application expected to be installed by default? select_all_apps="$1" @@ -108,16 +122,18 @@ function show_apps { # shellcheck disable=SC2068 for a in ${APPS_AVAILABLE[@]} do - if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then - applist="$applist $n $a off" - else - if [[ $(app_expected_to_be_installed "$select_all_apps" "$a") == "0" ]]; then + if [[ $(app_not_on_onion_only "$a") != "0" ]]; then + if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then applist="$applist $n $a off" else - applist="$applist $n $a on" + if [[ $(app_expected_to_be_installed "$select_all_apps" "$a") == "0" ]]; then + applist="$applist $n $a off" + else + applist="$applist $n $a on" + fi fi + n=$((n+1)) fi - n=$((n+1)) app_index=$((app_index+1)) done diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial index 93c57f10..640e5343 100755 --- a/src/freedombone-app-gnusocial +++ b/src/freedombone-app-gnusocial @@ -30,6 +30,7 @@ VARIANTS='full full-vim social' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +NOT_ON_ONION=1 GNUSOCIAL_DOMAIN_NAME= GNUSOCIAL_CODE= diff --git a/src/freedombone-app-hubzilla b/src/freedombone-app-hubzilla index dade690e..27d86461 100755 --- a/src/freedombone-app-hubzilla +++ b/src/freedombone-app-hubzilla @@ -30,6 +30,7 @@ VARIANTS='full full-vim social' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +NOT_ON_ONION=1 HUBZILLA_DOMAIN_NAME= HUBZILLA_CODE= diff --git a/src/freedombone-app-jitsi b/src/freedombone-app-jitsi index 80290874..5250ec5c 100755 --- a/src/freedombone-app-jitsi +++ b/src/freedombone-app-jitsi @@ -32,6 +32,7 @@ VARIANTS="" IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=0 +NOT_ON_ONION=1 VIDEOBRIDGE_PORT=5347 JITSI_ONION_PORT=8102 diff --git a/src/freedombone-app-matrix b/src/freedombone-app-matrix index 55e8c641..524914d4 100755 --- a/src/freedombone-app-matrix +++ b/src/freedombone-app-matrix @@ -36,6 +36,7 @@ VARIANTS='full full-vim chat' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +NOT_ON_ONION=1 MATRIX_DOMAIN_NAME= MATRIX_CODE= diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv index ae7e7b25..1af2c2af 100755 --- a/src/freedombone-app-postactiv +++ b/src/freedombone-app-postactiv @@ -30,6 +30,7 @@ VARIANTS='full full-vim media' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +NOT_ON_ONION=1 POSTACTIV_DOMAIN_NAME= POSTACTIV_CODE= diff --git a/src/freedombone-app-riot b/src/freedombone-app-riot index a1111a4c..4337430d 100755 --- a/src/freedombone-app-riot +++ b/src/freedombone-app-riot @@ -30,6 +30,7 @@ VARIANTS='full full-vim chat' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 +NOT_ON_ONION=1 RIOT_VERSION='0.13.3' RIOT_FILENAME="riot-v${RIOT_VERSION}" From c98b2f2e007cb97301628a5984afd8f4bc92f1c1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 14:30:15 +0100 Subject: [PATCH 07/14] Invert logic --- src/freedombone-addremove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index 277da7fe..5f5cdcec 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -86,7 +86,7 @@ function app_not_on_onion_only { read_config_param ONION_ONLY if [[ "$ONION_ONLY" != 'no' ]]; then - if ! grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then + if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then echo "0" return fi From a1a7e92d90640a31304515d0fe33f0bbe46a54e8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 15:33:48 +0100 Subject: [PATCH 08/14] Avoid bad app sequence --- src/freedombone-addremove | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index 5f5cdcec..df4b621d 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -163,14 +163,16 @@ function remove_apps_selected { # shellcheck disable=SC2068 for a in ${APPS_INSTALLED[@]} do - if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then - if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then - if [ ${n} -gt 0 ]; then - removals="$removals ${APPS_AVAILABLE[$app_index]}" - else - removals="${APPS_AVAILABLE[$app_index]}" + if [[ $(app_not_on_onion_only "$a") != "0" ]]; then + if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then + if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then + if [ ${n} -gt 0 ]; then + removals="$removals ${APPS_AVAILABLE[$app_index]}" + else + removals="${APPS_AVAILABLE[$app_index]}" + fi + n=$((n+1)) fi - n=$((n+1)) fi fi app_index=$((app_index+1)) @@ -208,14 +210,16 @@ function install_apps_selected { # shellcheck disable=SC2068 for a in ${APPS_INSTALLED[@]} do - if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then - if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then - if [ ${n} -gt 0 ]; then - installs="$installs ${APPS_AVAILABLE[$app_index]}" - else - installs="${APPS_AVAILABLE[$app_index]}" + if [[ $(app_not_on_onion_only "$a") != "0" ]]; then + if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then + if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then + if [ ${n} -gt 0 ]; then + installs="$installs ${APPS_AVAILABLE[$app_index]}" + else + installs="${APPS_AVAILABLE[$app_index]}" + fi + n=$((n+1)) fi - n=$((n+1)) fi fi app_index=$((app_index+1)) From 352b259bbb8960120987580bcfb178629cd8f6a2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 15:43:45 +0100 Subject: [PATCH 09/14] Extra onion app checks --- src/freedombone-utils-selector | 94 +++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index 63b854e0..077168de 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -285,11 +285,12 @@ function detect_apps { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - - # shellcheck disable=SC2068 - if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then - APPS_AVAILABLE+=("${app_name}") - APPS_CHOSEN+=("0") + 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 done @@ -298,6 +299,20 @@ function detect_apps { get_apps_installed_names } +function app_not_on_onion_only { + app_name="$1" + + read_config_param ONION_ONLY + + if [[ "$ONION_ONLY" != 'no' ]]; then + if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then + echo "0" + return + fi + fi + echo "1" +} + # detects what apps are available and can be installed # If the variants list within an app script is an empty string then # it is considered to be too experimental to be installable @@ -318,16 +333,18 @@ function detect_installable_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - # 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 [[ $(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 @@ -350,13 +367,15 @@ function detect_installed_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - 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 [[ $(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 @@ -385,27 +404,28 @@ function choose_apps_for_variant { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - - # 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 [[ $(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 done From 992bde2f97d61d6fbd81f603fca18d7ce3f46147 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 16:08:41 +0100 Subject: [PATCH 10/14] Index scope --- src/freedombone-addremove | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index df4b621d..fe170b18 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -133,8 +133,8 @@ function show_apps { fi fi n=$((n+1)) + app_index=$((app_index+1)) fi - app_index=$((app_index+1)) done # shellcheck disable=SC2086 @@ -174,8 +174,8 @@ function remove_apps_selected { n=$((n+1)) fi fi + app_index=$((app_index+1)) fi - app_index=$((app_index+1)) done # if no apps to be removed then don't do anything @@ -221,8 +221,8 @@ function install_apps_selected { n=$((n+1)) fi fi + app_index=$((app_index+1)) fi - app_index=$((app_index+1)) done # if no apps to be installed then don't do anything From ddb9b7a35339555a7b71f6ca09a813c07b67050c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 16:14:31 +0100 Subject: [PATCH 11/14] Remove redundant function --- src/freedombone-addremove | 14 -------------- src/freedombone-utils-selector | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index fe170b18..a363af8d 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -80,20 +80,6 @@ function mark_unselected_apps_as_removed { done } -function app_not_on_onion_only { - app_name="$1" - - read_config_param ONION_ONLY - - if [[ "$ONION_ONLY" != 'no' ]]; then - if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then - echo "0" - return - fi - fi - echo "1" -} - function app_expected_to_be_installed { # is the given application expected to be installed by default? select_all_apps="$1" diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index 077168de..597b83a7 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -272,6 +272,20 @@ function get_apps_installed_names { done } +function app_not_on_onion_only { + app_name="$1" + + read_config_param ONION_ONLY + + if [[ "$ONION_ONLY" != 'no' ]]; then + if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then + echo "0" + return + fi + fi + echo "1" +} + # detects what apps are available function detect_apps { FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*" @@ -299,20 +313,6 @@ function detect_apps { get_apps_installed_names } -function app_not_on_onion_only { - app_name="$1" - - read_config_param ONION_ONLY - - if [[ "$ONION_ONLY" != 'no' ]]; then - if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then - echo "0" - return - fi - fi - echo "1" -} - # detects what apps are available and can be installed # If the variants list within an app script is an empty string then # it is considered to be too experimental to be installable From fcb209d3a933c12bf1b8afefb23e747a8bddd790 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 16:17:10 +0100 Subject: [PATCH 12/14] Tidying --- src/freedombone-addremove | 53 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index a363af8d..af5c9a60 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -108,19 +108,17 @@ function show_apps { # shellcheck disable=SC2068 for a in ${APPS_AVAILABLE[@]} do - if [[ $(app_not_on_onion_only "$a") != "0" ]]; then - if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then + if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then + applist="$applist $n $a off" + else + if [[ $(app_expected_to_be_installed "$select_all_apps" "$a") == "0" ]]; then applist="$applist $n $a off" else - if [[ $(app_expected_to_be_installed "$select_all_apps" "$a") == "0" ]]; then - applist="$applist $n $a off" - else - applist="$applist $n $a on" - fi + applist="$applist $n $a on" fi - n=$((n+1)) - app_index=$((app_index+1)) fi + n=$((n+1)) + app_index=$((app_index+1)) done # shellcheck disable=SC2086 @@ -149,19 +147,17 @@ function remove_apps_selected { # shellcheck disable=SC2068 for a in ${APPS_INSTALLED[@]} do - if [[ $(app_not_on_onion_only "$a") != "0" ]]; then - if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then - if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then - if [ ${n} -gt 0 ]; then - removals="$removals ${APPS_AVAILABLE[$app_index]}" - else - removals="${APPS_AVAILABLE[$app_index]}" - fi - n=$((n+1)) + if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then + if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then + if [ ${n} -gt 0 ]; then + removals="$removals ${APPS_AVAILABLE[$app_index]}" + else + removals="${APPS_AVAILABLE[$app_index]}" fi + n=$((n+1)) fi - app_index=$((app_index+1)) fi + app_index=$((app_index+1)) done # if no apps to be removed then don't do anything @@ -196,19 +192,18 @@ function install_apps_selected { # shellcheck disable=SC2068 for a in ${APPS_INSTALLED[@]} do - if [[ $(app_not_on_onion_only "$a") != "0" ]]; then - if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then - if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then - if [ ${n} -gt 0 ]; then - installs="$installs ${APPS_AVAILABLE[$app_index]}" - else - installs="${APPS_AVAILABLE[$app_index]}" - fi - n=$((n+1)) + if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then + if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then + if [ ${n} -gt 0 ]; then + installs="$installs ${APPS_AVAILABLE[$app_index]}" + else + installs="${APPS_AVAILABLE[$app_index]}" fi + n=$((n+1)) fi - app_index=$((app_index+1)) fi + app_index=$((app_index+1)) + done # if no apps to be installed then don't do anything From fa49e53734b50f7ab90b373b15bba76312ec314d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 17:38:17 +0100 Subject: [PATCH 13/14] 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 From 4321770ee53c8d95270d081cd6ad753de4c2f03e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 May 2018 17:41:37 +0100 Subject: [PATCH 14/14] Invert logic --- src/freedombone-app-matrix | 1 + src/freedombone-utils-selector | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/freedombone-app-matrix b/src/freedombone-app-matrix index 524914d4..3992238d 100755 --- a/src/freedombone-app-matrix +++ b/src/freedombone-app-matrix @@ -37,6 +37,7 @@ VARIANTS='full full-vim chat' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 NOT_ON_ONION=1 +MINIMUM_RAM_MB=1500 MATRIX_DOMAIN_NAME= MATRIX_CODE= diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index ec17f563..25ed118e 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -318,7 +318,7 @@ function detect_apps { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + 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 @@ -354,7 +354,7 @@ function detect_installable_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + 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 @@ -390,7 +390,7 @@ function detect_installed_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + 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 @@ -429,7 +429,7 @@ function choose_apps_for_variant { for filename in $FILES do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if [[ $(enough_ram_for_app "$app_name") != "0" ]]; then + 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