freedombone/src/freedombone-utils-android

168 lines
6.8 KiB
Plaintext
Raw Permalink Normal View History

2018-05-25 16:17:34 +02:00
#!/bin/bash
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Freedom in the Cloud
#
# Integration with the FreedomBox android app
#
# License
# =======
#
# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
#
# 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 <http://www.gnu.org/licenses/>.
function android_update_apps {
if [ "$1" ]; then
detect_installable_apps
fi
2018-05-26 16:33:38 +02:00
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
2018-05-26 19:59:04 +02:00
plinth_api="/var/www/${local_hostname}/htdocs/plinth/api.json"
2018-05-26 16:33:38 +02:00
# Create a self-signed cert if needed
# The FreedomBox app assumes a self-signed cert
if [ ! -f "/etc/ssl/certs/${local_hostname}.crt" ]; then
install_web_local_user_interface
2018-05-26 16:36:12 +02:00
systemctl restart nginx
fi
2018-05-26 20:24:34 +02:00
if [ ! -d "/var/www/${local_hostname}/htdocs/plinth" ]; then
mkdir -p "/var/www/${local_hostname}/htdocs/plinth"
2018-05-25 16:17:34 +02:00
fi
2018-05-25 23:17:53 +02:00
if [ ! -d "/var/www/${local_hostname}/htdocs/icons" ]; then
mkdir -p "/var/www/${local_hostname}/htdocs/icons"
fi
2018-05-25 16:17:34 +02:00
echo '{' > "$plinth_api"
echo ' "shortcuts": [' >> "$plinth_api"
android_ctr=0
app_index=0
2018-05-26 14:41:15 +02:00
# shellcheck disable=SC2068,SC2034
2018-05-25 16:17:34 +02:00
for a in ${APPS_INSTALLED[@]}
do
2018-05-26 14:41:15 +02:00
app_name=${APPS_INSTALLED_NAMES[$app_index]}
if [ "$app_name" ]; then
2018-05-25 16:17:34 +02:00
app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"
if [ -f "$app_filename" ]; then
2018-05-25 23:17:53 +02:00
# get the icon for the app
icon_filename="/usr/share/${PROJECT_NAME}/android-app/${app_name}.png"
if [ -f "$icon_filename" ]; then
cp "$icon_filename" "/var/www/${local_hostname}/htdocs/icons/${app_name}.png"
else
icon_filename=
fi
2018-05-25 16:17:34 +02:00
app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}')
2018-05-25 19:45:09 +02:00
SHORT_DESCRIPTION=
DESCRIPTION=
MOBILE_APP_URL=
if ! grep -q "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
2018-05-26 14:57:23 +02:00
app_index=$((app_index+1))
continue
2018-05-25 16:17:34 +02:00
fi
2018-05-25 19:15:24 +02:00
if grep -q "#${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
2018-05-26 14:57:23 +02:00
app_index=$((app_index+1))
2018-05-25 19:15:24 +02:00
continue
fi
2018-05-25 19:55:59 +02:00
SHORT_DESCRIPTION="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
if grep -q "${app_name_upper}_DESCRIPTION=" "$app_filename"; then
2018-05-25 19:53:28 +02:00
DESCRIPTION="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
2018-05-25 16:17:34 +02:00
fi
if grep -q "${app_name_upper}_MOBILE_APP_URL=" "$app_filename"; then
2018-05-25 19:53:28 +02:00
MOBILE_APP_URL="$(grep "${app_name_upper}_MOBILE_APP_URL=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
2018-05-25 16:17:34 +02:00
fi
if [ $android_ctr -gt 0 ]; then
echo ',' >> "$plinth_api"
fi
2018-05-25 16:17:34 +02:00
{ echo ' {';
echo " \"name\": \"${app_name}\",";
2018-05-25 19:45:09 +02:00
echo " \"short_description\": \"$SHORT_DESCRIPTION\",";
2018-05-26 19:53:36 +02:00
echo " \"description\": [";
echo " \"$DESCRIPTION\"";
echo ' ],';
2018-05-25 23:17:53 +02:00
echo " \"icon_url\": \"/icons/${app_name}.png\",";
echo " \"clients\": ["; } >> "$plinth_api"
2018-05-25 16:17:34 +02:00
read_config_param "${app_name_upper}_DOMAIN_NAME"
2018-05-25 20:26:23 +02:00
test_domain_name="${app_name_upper}_DOMAIN_NAME"
domain_name=${!test_domain_name}
2018-05-25 21:06:38 +02:00
if [ "$domain_name" ]; then
if [[ "$domain_name" != *'.onion' ]]; then
domain_name="https://${!test_domain_name}"
else
domain_name="http://${!test_domain_name}"
fi
fi
2018-05-25 20:46:43 +02:00
if [[ "$domain_name" && "$app_name" != 'matrix' ]]; then
{ echo ' {';
echo " \"name\": \"${app_name}\",";
echo " \"platforms\": [";
echo ' {';
echo ' "type": "web",';
2018-05-25 19:45:09 +02:00
echo " \"url\": \"$domain_name\"";
2018-05-25 20:44:26 +02:00
echo -n ' }'; } >> "$plinth_api"
fi
2018-05-25 19:45:09 +02:00
if [ "$MOBILE_APP_URL" ]; then
2018-05-25 20:46:43 +02:00
if [[ "$domain_name" && "$app_name" != 'matrix' ]]; then
echo ',' >> "$plinth_api"
2018-05-25 20:44:26 +02:00
else
{ echo ' {';
echo " \"name\": \"${app_name}\",";
echo " \"platforms\": ["; } >> "$plinth_api"
fi
store_name='f-droid'
if [[ "$MOBILE_APP_URL" == *'google'* ]]; then
store_name='google-play'
fi
2018-05-25 20:44:26 +02:00
{ echo ' {';
2018-05-25 16:17:34 +02:00
echo ' "type": "store",';
echo ' "os": "android",';
echo " \"store_name\": \"$store_name\",";
2018-05-25 19:45:09 +02:00
echo " \"url\": \"$MOBILE_APP_URL\"";
2018-05-25 20:44:26 +02:00
echo ' }'; } >> "$plinth_api"
2018-05-25 16:17:34 +02:00
else
echo '' >> "$plinth_api"
fi
2018-05-25 20:44:26 +02:00
{ echo ' ]';
echo ' }';
echo ' ]';
2018-05-25 16:17:34 +02:00
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"
2018-05-25 23:17:53 +02:00
chown -R www-data:www-data "/var/www/${local_hostname}/htdocs/icons"
2018-05-25 16:17:34 +02:00
}
# NOTE: deliberately no exit 0