diff --git a/src/freedombone-addremove b/src/freedombone-addremove index af5c9a60..f93b3eb7 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -267,5 +267,6 @@ if [[ "$1" == "add-all" ]]; then else install_apps_selected fi +android_update_apps exit 0 diff --git a/src/freedombone-template b/src/freedombone-template index ce334fd4..42ff37ff 100755 --- a/src/freedombone-template +++ b/src/freedombone-template @@ -280,6 +280,12 @@ if [ $app_daemon ]; then fi fi echo '' +echo $'# These parameters are used by the FreedomBox mobile app' +echo "${app_name_upper}_SHORT_DESCRIPTION=" +echo "${app_name_upper}_DESCRIPTION=" +echo "${app_name_upper}_ICON_URL=" +echo "${app_name_upper}_MOBILE_APP_URL=" +echo '' echo "${app_name}_variables=(ONION_ONLY" echo " ${app_name_upper}_DOMAIN_NAME" echo " ${app_name_upper}_CODE" diff --git a/src/freedombone-upgrade b/src/freedombone-upgrade index e5891212..b36d3233 100755 --- a/src/freedombone-upgrade +++ b/src/freedombone-upgrade @@ -111,6 +111,7 @@ if [ -d "$PROJECT_DIR" ]; then rm /etc/exim4/exim4.conf.template.bak* email_update_onion_domain prevent_mail_process_overrun + android_update_apps #defrag_filesystem # reinstall tor from backports diff --git a/src/freedombone-utils-android b/src/freedombone-utils-android new file mode 100755 index 00000000..78b9ff57 --- /dev/null +++ b/src/freedombone-utils-android @@ -0,0 +1,127 @@ +#!/bin/bash +# _____ _ _ +# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___ +# | __| _| -_| -_| . | . | | . | . | | -_| +# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___| +# +# Freedom in the Cloud +# +# Integration with the FreedomBox android app +# +# License +# ======= +# +# Copyright (C) 2018 Bob Mottram +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +function android_update_apps { + if [ "$1" ]; then + detect_installable_apps + fi + + local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local + plinth_api="/var/www/${local_hostname}/htdocs/plinth/api/1" + + if [ ! -d "/var/www/${local_hostname}/htdocs/plinth/api" ]; then + mkdir -p "/var/www/${local_hostname}/htdocs/plinth/api" + fi + + echo '{' > "$plinth_api" + echo ' "shortcuts": [' >> "$plinth_api" + + android_ctr=0 + app_index=0 + # shellcheck disable=SC2068 + for a in ${APPS_INSTALLED[@]} + do + if [[ "$a" == "1" ]]; then + app_name=${APPS_INSTALLED_NAMES[$app_index]} + app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}" + if [ -f "$app_filename" ]; then + if [ $android_ctr -gt 0 ]; then + echo ',' >> "$plinth_api" + fi + app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}') + "${app_name_upper}_SHORT_DESCRIPTION"= + "${app_name_upper}_DESCRIPTION"= + "${app_name_upper}_ICON_URL"= + "${app_name_upper}_MOBILE_APP_URL"= + if ! grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then + # shellcheck disable=SC2140 + "${app_name_upper}_SHORT_DESCRIPTION"="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')" + fi + if ! grep "${app_name_upper}_DESCRIPTION=" "$app_filename"; then + # shellcheck disable=SC2140 + "${app_name_upper}_DESCRIPTION"="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')" + fi + if ! grep "${app_name_upper}_ICON_URL=" "$app_filename"; then + # shellcheck disable=SC2140 + "${app_name_upper}_ICON_URL"="$(grep "${app_name_upper}_ICON_URL=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')" + fi + if ! grep "${app_name_upper}_MOBILE_APP_URL=" "$app_filename"; then + # shellcheck disable=SC2140 + "${app_name_upper}_MOBILE_APP_URL"="$(grep "${app_name_upper}_MOBILE_APP_URL=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')" + fi + + { echo ' {'; + echo " \"name\": \"${app_name}\","; + echo " \"short_description\": \"${app_name_upper}_SHORT_DESCRIPTION\","; + echo " \"description\": \"${app_name_upper}_DESCRIPTION\","; + echo " \"icon_url\": \"${app_name_upper}_ICON_URL\","; + echo " \"clients\": ["; + echo ' {'; + echo " \"name\": \"${app_name}\","; + echo " \"platforms\": ["; + echo ' {'; + echo ' "type": "web",'; + echo " \"url\": \"${app_name_upper}_DOMAIN_NAME\""; + echo ' }'; + echo ' ]'; + echo -n ' }'; } >> "$plinth_api" + + if [[ $(("${app_name_upper}_MOBILE_APP_URL")) ]]; then + { echo ','; + echo ' {'; + echo " \"name\": \"${app_name}\","; + echo " \"platforms\": ["; + echo ' {'; + echo ' "type": "store",'; + echo ' "os": "android",'; + echo ' "store_name": "f-droid",'; + echo " \"url\": \"${app_name_upper}_MOBILE_APP_URL\""; + echo ' }'; + echo ' ]'; + echo -n ' }'; } >> "$plinth_api" + else + echo '' >> "$plinth_api" + fi + + { echo ' ]'; + echo -n ' }'; } >> "$plinth_api" + + android_ctr=$((android_ctr+1)) + fi + fi + app_index=$((app_index+1)) + done + + { echo ''; + echo ' ]'; + echo '}'; } >> "$plinth_api" + + chown -R www-data:www-data "/var/www/${local_hostname}/htdocs/plinth" +} + +# NOTE: deliberately no exit 0 diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index 99aaab1b..a03d3766 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -584,7 +584,7 @@ function add_users_after_install { if [[ $(is_valid_user "$USERNAME") == "1" ]]; then if [[ "$USERNAME" != "$ADMIN_USERNAME" ]]; then if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then - valstr=$"Login for user ${USERNAME}=" + #valstr=$"Login for user ${USERNAME}=" app_password="$(create_password ${MINIMUM_PASSWORD_LENGTH})" "add_user_${app_name}" "${USERNAME}" "${app_password}" echo "${app_name}_${USERNAME}" >> "$APP_USERS_FILE"