|
@@ -0,0 +1,127 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+# _____ _ _
|
|
3
|
+# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
|
|
4
|
+# | __| _| -_| -_| . | . | | . | . | | -_|
|
|
5
|
+# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
|
|
6
|
+#
|
|
7
|
+# Freedom in the Cloud
|
|
8
|
+#
|
|
9
|
+# Integration with the FreedomBox android app
|
|
10
|
+#
|
|
11
|
+# License
|
|
12
|
+# =======
|
|
13
|
+#
|
|
14
|
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
|
|
15
|
+#
|
|
16
|
+# This program is free software: you can redistribute it and/or modify
|
|
17
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
18
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
19
|
+# (at your option) any later version.
|
|
20
|
+#
|
|
21
|
+# This program is distributed in the hope that it will be useful,
|
|
22
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24
|
+# GNU Affero General Public License for more details.
|
|
25
|
+#
|
|
26
|
+# You should have received a copy of the GNU Affero General Public License
|
|
27
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
28
|
+
|
|
29
|
+function android_update_apps {
|
|
30
|
+ if [ "$1" ]; then
|
|
31
|
+ detect_installable_apps
|
|
32
|
+ fi
|
|
33
|
+
|
|
34
|
+ local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
|
|
35
|
+ plinth_api="/var/www/${local_hostname}/htdocs/plinth/api/1"
|
|
36
|
+
|
|
37
|
+ if [ ! -d "/var/www/${local_hostname}/htdocs/plinth/api" ]; then
|
|
38
|
+ mkdir -p "/var/www/${local_hostname}/htdocs/plinth/api"
|
|
39
|
+ fi
|
|
40
|
+
|
|
41
|
+ echo '{' > "$plinth_api"
|
|
42
|
+ echo ' "shortcuts": [' >> "$plinth_api"
|
|
43
|
+
|
|
44
|
+ android_ctr=0
|
|
45
|
+ app_index=0
|
|
46
|
+ # shellcheck disable=SC2068
|
|
47
|
+ for a in ${APPS_INSTALLED[@]}
|
|
48
|
+ do
|
|
49
|
+ if [[ "$a" == "1" ]]; then
|
|
50
|
+ app_name=${APPS_INSTALLED_NAMES[$app_index]}
|
|
51
|
+ app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"
|
|
52
|
+ if [ -f "$app_filename" ]; then
|
|
53
|
+ if [ $android_ctr -gt 0 ]; then
|
|
54
|
+ echo ',' >> "$plinth_api"
|
|
55
|
+ fi
|
|
56
|
+ app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}')
|
|
57
|
+ "${app_name_upper}_SHORT_DESCRIPTION"=
|
|
58
|
+ "${app_name_upper}_DESCRIPTION"=
|
|
59
|
+ "${app_name_upper}_ICON_URL"=
|
|
60
|
+ "${app_name_upper}_MOBILE_APP_URL"=
|
|
61
|
+ if ! grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
|
|
62
|
+ # shellcheck disable=SC2140
|
|
63
|
+ "${app_name_upper}_SHORT_DESCRIPTION"="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')"
|
|
64
|
+ fi
|
|
65
|
+ if ! grep "${app_name_upper}_DESCRIPTION=" "$app_filename"; then
|
|
66
|
+ # shellcheck disable=SC2140
|
|
67
|
+ "${app_name_upper}_DESCRIPTION"="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')"
|
|
68
|
+ fi
|
|
69
|
+ if ! grep "${app_name_upper}_ICON_URL=" "$app_filename"; then
|
|
70
|
+ # shellcheck disable=SC2140
|
|
71
|
+ "${app_name_upper}_ICON_URL"="$(grep "${app_name_upper}_ICON_URL=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')"
|
|
72
|
+ fi
|
|
73
|
+ if ! grep "${app_name_upper}_MOBILE_APP_URL=" "$app_filename"; then
|
|
74
|
+ # shellcheck disable=SC2140
|
|
75
|
+ "${app_name_upper}_MOBILE_APP_URL"="$(grep "${app_name_upper}_MOBILE_APP_URL=" "$app_filename" | head -n 1 | awk -F '=' '{print $2}')"
|
|
76
|
+ fi
|
|
77
|
+
|
|
78
|
+ { echo ' {';
|
|
79
|
+ echo " \"name\": \"${app_name}\",";
|
|
80
|
+ echo " \"short_description\": \"${app_name_upper}_SHORT_DESCRIPTION\",";
|
|
81
|
+ echo " \"description\": \"${app_name_upper}_DESCRIPTION\",";
|
|
82
|
+ echo " \"icon_url\": \"${app_name_upper}_ICON_URL\",";
|
|
83
|
+ echo " \"clients\": [";
|
|
84
|
+ echo ' {';
|
|
85
|
+ echo " \"name\": \"${app_name}\",";
|
|
86
|
+ echo " \"platforms\": [";
|
|
87
|
+ echo ' {';
|
|
88
|
+ echo ' "type": "web",';
|
|
89
|
+ echo " \"url\": \"${app_name_upper}_DOMAIN_NAME\"";
|
|
90
|
+ echo ' }';
|
|
91
|
+ echo ' ]';
|
|
92
|
+ echo -n ' }'; } >> "$plinth_api"
|
|
93
|
+
|
|
94
|
+ if [[ $(("${app_name_upper}_MOBILE_APP_URL")) ]]; then
|
|
95
|
+ { echo ',';
|
|
96
|
+ echo ' {';
|
|
97
|
+ echo " \"name\": \"${app_name}\",";
|
|
98
|
+ echo " \"platforms\": [";
|
|
99
|
+ echo ' {';
|
|
100
|
+ echo ' "type": "store",';
|
|
101
|
+ echo ' "os": "android",';
|
|
102
|
+ echo ' "store_name": "f-droid",';
|
|
103
|
+ echo " \"url\": \"${app_name_upper}_MOBILE_APP_URL\"";
|
|
104
|
+ echo ' }';
|
|
105
|
+ echo ' ]';
|
|
106
|
+ echo -n ' }'; } >> "$plinth_api"
|
|
107
|
+ else
|
|
108
|
+ echo '' >> "$plinth_api"
|
|
109
|
+ fi
|
|
110
|
+
|
|
111
|
+ { echo ' ]';
|
|
112
|
+ echo -n ' }'; } >> "$plinth_api"
|
|
113
|
+
|
|
114
|
+ android_ctr=$((android_ctr+1))
|
|
115
|
+ fi
|
|
116
|
+ fi
|
|
117
|
+ app_index=$((app_index+1))
|
|
118
|
+ done
|
|
119
|
+
|
|
120
|
+ { echo '';
|
|
121
|
+ echo ' ]';
|
|
122
|
+ echo '}'; } >> "$plinth_api"
|
|
123
|
+
|
|
124
|
+ chown -R www-data:www-data "/var/www/${local_hostname}/htdocs/plinth"
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+# NOTE: deliberately no exit 0
|